ADXabhi commited on
Commit
76e3db8
Β·
verified Β·
1 Parent(s): 4e11af8

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -13,12 +13,19 @@ import cloudinary, cloudinary.uploader
13
 
14
  # ── CONFIG ──────────────────────────────────────────────
15
  def _fetch_cloud_name():
16
- try:
17
- import urllib.request as _ur, json as _j
18
- with _ur.urlopen("https://media.toolxp.org/config", timeout=5) as r:
19
- return _j.loads(r.read())["cloud_name"]
20
- except Exception:
21
- return os.environ.get("CLOUDINARY_CLOUD_NAME", "doxoms9hd")
 
 
 
 
 
 
 
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