Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -13,12 +13,19 @@ import cloudinary, cloudinary.uploader
|
|
| 13 |
|
| 14 |
# ββ CONFIG ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 15 |
def _fetch_cloud_name():
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
CLOUD_NAME = _fetch_cloud_name()
|
| 23 |
UPLOAD_PRESET = os.environ.get("CLOUDINARY_UPLOAD_PRESET", "testing")
|
| 24 |
|
|
|
|
| 13 |
|
| 14 |
# ββ CONFIG ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 15 |
def _fetch_cloud_name():
|
| 16 |
+
import urllib.request as _ur, json as _j, ssl as _ssl
|
| 17 |
+
ctx = _ssl.create_default_context()
|
| 18 |
+
req = _ur.Request("https://media.toolxp.org/config", headers={"User-Agent": "Mozilla/5.0"})
|
| 19 |
+
for _i in range(3):
|
| 20 |
+
try:
|
| 21 |
+
with _ur.urlopen(req, timeout=10, context=ctx) as r:
|
| 22 |
+
name = _j.loads(r.read().decode())["cloud_name"]
|
| 23 |
+
if name:
|
| 24 |
+
print(f"[config] cloud_name={name}")
|
| 25 |
+
return name
|
| 26 |
+
except Exception as _e:
|
| 27 |
+
print(f"[config] attempt {_i+1} failed: {_e}")
|
| 28 |
+
raise RuntimeError("[config] FATAL: could not fetch cloud_name after 3 attempts")
|
| 29 |
CLOUD_NAME = _fetch_cloud_name()
|
| 30 |
UPLOAD_PRESET = os.environ.get("CLOUDINARY_UPLOAD_PRESET", "testing")
|
| 31 |
|