aboutsummarybugs & patchesrefslogtreecommitdiffstats
path: root/src/discord_image_bridge
diff options
context:
space:
mode:
authorVosjedev <vosje@vosjedev.net>2026-01-25 16:24:36 +0100
committerVosjedev <vosje@vosjedev.net>2026-01-25 16:24:36 +0100
commit794af1254456e5285d5a18be1c11911ad1393328 (patch)
treed2a1147649798d20616100e8b7cf0cc9785a562b /src/discord_image_bridge
parent7f56cabb3e0b21bafd3f4eb813b2264f7f6e2a2b (diff)
downloaddiscord_image_bridge-794af1254456e5285d5a18be1c11911ad1393328.tar.gz
discord_image_bridge-794af1254456e5285d5a18be1c11911ad1393328.tar.bz2
discord_image_bridge-794af1254456e5285d5a18be1c11911ad1393328.tar.xz
fix some obvious errors in downloading
Signed-off-by: Vosjedev <vosje@vosjedev.net>
Diffstat (limited to 'src/discord_image_bridge')
-rw-r--r--src/discord_image_bridge/utils.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/discord_image_bridge/utils.py b/src/discord_image_bridge/utils.py
index e92ed5b..f937997 100644
--- a/src/discord_image_bridge/utils.py
+++ b/src/discord_image_bridge/utils.py
@@ -11,9 +11,15 @@ from . import fsmanager
def download_and_cache(url, filename):
cherrypy.log("Downloading attachment %s"%filename)
- resp=requests.get(url)
- if resp.status_code==200:
- hash=do_hash(resp.content).hexdigest()
+ try:
+ resp=requests.get(url)
+ except requests.exceptions.RequestException as e:
+ cherrypy.log("Error downloading: %s"%repr(e))
+ return None, None
+ if not resp.status_code==200:
+ cherrypy.log("Attachment %s failed to download"%filename)
+ return None, None
+ hash=do_hash(resp.content).hexdigest()
try:
fname=fsmanager.hash2fname(hash)
dirname=os.path.dirname(fname)
@@ -31,6 +37,7 @@ def download_and_cache(url, filename):
except OSError as e:
cherrypy.log("Error writing "+filename+" to disk: "+repr(e))
return None, None
+ return None, None
def download_uncached(hash):
with fsmanager.MetaFile(hash) as metafd:
@@ -41,11 +48,12 @@ def download_uncached(hash):
for source in data["sources"]:
match source["type"]:
case "discord":
- return download_uncached_discord(
+ hash, fname=download_uncached_discord(
channel=source["channel"],
msgid=source["message"],
attachmentid=source["attachment"]
)
+ if hash: return hash, fname
case _:
# NOTE: maybe log here?
return None, None