Oysiyl commited on
Commit
d8a05c7
·
1 Parent(s): a32c29b

chore: add qrcut dual-write diagnostics

Browse files
Files changed (1) hide show
  1. hf_dashboard.py +18 -3
hf_dashboard.py CHANGED
@@ -215,11 +215,12 @@ def _png_bytes(image: Image.Image, *, max_size: int | None = None) -> bytes:
215
 
216
 
217
  def _upload_public_png(*, image: Image.Image, object_path: str, max_size: int | None = None) -> str:
 
218
  _ensure_bucket()
219
  _request_bytes(
220
  "POST",
221
  f"/storage/v1/object/{GENERATIONS_BUCKET}/{urllib_parse.quote(object_path, safe='/')}",
222
- data=_png_bytes(image, max_size=max_size),
223
  content_type="image/png",
224
  headers={"x-upsert": "true"},
225
  )
@@ -230,10 +231,14 @@ def _upload_public_png(*, image: Image.Image, object_path: str, max_size: int |
230
  # Failures here are logged but do NOT break the Supabase write -- Supabase
231
  # remains the source of truth until the user explicitly deletes the bucket.
232
  if QRCUT_STORAGE_URL and QRCUT_WRITE_API_KEY:
 
 
 
 
233
  try:
234
  kvm_req = urllib_request.Request(
235
  f"{QRCUT_STORAGE_URL}/storage-write/{urllib_parse.quote(object_path, safe='/')}",
236
- data=_png_bytes(image, max_size=max_size),
237
  headers={
238
  "X-QRCUT-WRITE-KEY": QRCUT_WRITE_API_KEY,
239
  "Content-Type": "image/png",
@@ -244,10 +249,20 @@ def _upload_public_png(*, image: Image.Image, object_path: str, max_size: int |
244
  with urllib_request.urlopen(kvm_req, timeout=30) as kvm_resp:
245
  if kvm_resp.status == 201:
246
  public_url = f"{QRCUT_STORAGE_PUBLIC_URL}/storage/{object_path}"
 
247
  else:
248
- print(f"[qrcut] dual-write HTTP {kvm_resp.status}: {object_path}", flush=True)
 
 
 
 
249
  except (urllib_error.URLError, TimeoutError, OSError) as exc:
250
  print(f"[qrcut] dual-write failed: {exc} -- {object_path}", flush=True)
 
 
 
 
 
251
 
252
  return public_url
253
 
 
215
 
216
 
217
  def _upload_public_png(*, image: Image.Image, object_path: str, max_size: int | None = None) -> str:
218
+ png_bytes = _png_bytes(image, max_size=max_size)
219
  _ensure_bucket()
220
  _request_bytes(
221
  "POST",
222
  f"/storage/v1/object/{GENERATIONS_BUCKET}/{urllib_parse.quote(object_path, safe='/')}",
223
+ data=png_bytes,
224
  content_type="image/png",
225
  headers={"x-upsert": "true"},
226
  )
 
231
  # Failures here are logged but do NOT break the Supabase write -- Supabase
232
  # remains the source of truth until the user explicitly deletes the bucket.
233
  if QRCUT_STORAGE_URL and QRCUT_WRITE_API_KEY:
234
+ print(
235
+ f"[qrcut] dual-write enabled path={object_path} bytes={len(png_bytes)} target={QRCUT_STORAGE_URL}/storage-write/...",
236
+ flush=True,
237
+ )
238
  try:
239
  kvm_req = urllib_request.Request(
240
  f"{QRCUT_STORAGE_URL}/storage-write/{urllib_parse.quote(object_path, safe='/')}",
241
+ data=png_bytes,
242
  headers={
243
  "X-QRCUT-WRITE-KEY": QRCUT_WRITE_API_KEY,
244
  "Content-Type": "image/png",
 
249
  with urllib_request.urlopen(kvm_req, timeout=30) as kvm_resp:
250
  if kvm_resp.status == 201:
251
  public_url = f"{QRCUT_STORAGE_PUBLIC_URL}/storage/{object_path}"
252
+ print(f"[qrcut] dual-write success HTTP 201: {object_path}", flush=True)
253
  else:
254
+ response_body = kvm_resp.read(400).decode("utf-8", errors="replace").strip()
255
+ print(
256
+ f"[qrcut] dual-write HTTP {kvm_resp.status}: {object_path} body={response_body}",
257
+ flush=True,
258
+ )
259
  except (urllib_error.URLError, TimeoutError, OSError) as exc:
260
  print(f"[qrcut] dual-write failed: {exc} -- {object_path}", flush=True)
261
+ else:
262
+ print(
263
+ f"[qrcut] dual-write skipped missing env: storage_url={'yes' if QRCUT_STORAGE_URL else 'no'} write_key={'yes' if QRCUT_WRITE_API_KEY else 'no'} path={object_path}",
264
+ flush=True,
265
+ )
266
 
267
  return public_url
268