q6 commited on
Commit
f64ecfa
·
1 Parent(s): e3c4a04

Fix webhook?

Browse files
Files changed (1) hide show
  1. backend/app.py +9 -5
backend/app.py CHANGED
@@ -111,7 +111,6 @@ async def init_db():
111
  {
112
  "sql": "CREATE TABLE IF NOT EXISTS pi_scans (post_id TEXT PRIMARY KEY, url TEXT, exif_type INTEGER)"
113
  },
114
- {"sql": "DELETE FROM pi_searches"},
115
  ]
116
  )
117
 
@@ -121,10 +120,15 @@ async def discord_notify(msg):
121
  print("WARN: DISCORD_WEBHOOK_URL not set, skipping notify")
122
  return
123
  try:
124
- async with httpx.AsyncClient(timeout=10) as client:
125
- r = await client.post(DISCORD_WEBHOOK_URL, json={"content": msg})
126
- if r.status_code >= 400:
127
- print(f"Discord webhook failed ({r.status_code}): {r.text}")
 
 
 
 
 
128
  except Exception as e:
129
  print(f"Discord webhook error: {repr(e)}")
130
 
 
111
  {
112
  "sql": "CREATE TABLE IF NOT EXISTS pi_scans (post_id TEXT PRIMARY KEY, url TEXT, exif_type INTEGER)"
113
  },
 
114
  ]
115
  )
116
 
 
120
  print("WARN: DISCORD_WEBHOOK_URL not set, skipping notify")
121
  return
122
  try:
123
+ async with aiohttp.ClientSession() as session:
124
+ async with session.post(
125
+ DISCORD_WEBHOOK_URL.rstrip("/"),
126
+ json={"content": msg},
127
+ timeout=aiohttp.ClientTimeout(total=15),
128
+ ) as r:
129
+ if r.status >= 400:
130
+ body = await r.text()
131
+ print(f"Discord webhook failed ({r.status}): {body}")
132
  except Exception as e:
133
  print(f"Discord webhook error: {repr(e)}")
134