From b07000f789d51fb98b630e64efff04d33d71b583 Mon Sep 17 00:00:00 2001 From: Luke Robles <98352913+lrobles-iterable@users.noreply.github.com> Date: Thu, 23 Jun 2022 14:02:20 -0700 Subject: [PATCH] Fixing the image conversion to use temp files and time.time for filename on upload --- app/bot.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) mode change 100755 => 100644 app/bot.py diff --git a/app/bot.py b/app/bot.py old mode 100755 new mode 100644 index 48190a40..a62b2242 --- a/app/bot.py +++ b/app/bot.py @@ -53,15 +53,18 @@ async def fix_cdn_url(ctx): @bot.listen("on_message") async def convert_heic_to_jpg(ctx): from cmagick import cmagick + import time + import tempfile if ctx.attachments: for attachment in ctx.attachments: if attachment.filename.lower().endswith(("heic", "tiff")): source_file = "/tmp/source" - jpg_file = "/tmp/converted.jpg" - await attachment.save(fp=source_file) + source_file, file_path = tempfile.mkstemp() + jpg_file = "/tmp/%s.jpg" % time.time() + await attachment.save(fp=file_path) - img = cmagick.convert(source_file, jpg_file) + img = cmagick.convert(file_path, jpg_file) try: await ctx.delete()