From 6656edeefcc7b3a9f1fe3e4cd7ba04d7eb40451a Mon Sep 17 00:00:00 2001 From: TLSM <104547575+TLSM@users.noreply.github.com> Date: Sun, 8 May 2022 01:01:49 -0400 Subject: [PATCH] Refactor admig logic, fix banners path. (#250) Made the logic of the recent admig upload thread fixes (arguably) more Pythonic, or at least less verbose. Also, the banners path was replaced with a duplicate of the sidebars path during the copypasta. This has been remedied. --- files/routes/comments.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/files/routes/comments.py b/files/routes/comments.py index caf880b223..17f2a27c42 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -228,18 +228,16 @@ def api_comment(v): if image == "": return {"error":"Image upload failed"} if v.admin_level > 2 and level == 1: if parent_post.id == 37696: - li = os.listdir('files/assets/images/rDrama/sidebar') - li = [int(x.split('.webp')[0]) for x in li] - li = sorted(li) - num = li[-1] + 1 + li = sorted(os.listdir('files/assets/images/rDrama/sidebar'), + key=lambda e: int(e.split('.webp')[0]))[-1] + num = int(li.split('.webp')[0]) + 1 filename = f'files/assets/images/rDrama/sidebar/{num}.webp' copyfile(oldname, filename) process_image(v.patron, filename, 400) elif parent_post.id == 37697: - li = os.listdir('files/assets/images/rDrama/sidebar') - li = [int(x.split('.webp')[0]) for x in li] - li = sorted(li) - num = li[-1] + 1 + li = sorted(os.listdir('files/assets/images/rDrama/banners'), + key=lambda e: int(e.split('.webp')[0]))[-1] + num = int(li.split('.webp')[0]) + 1 filename = f'files/assets/images/rDrama/banners/{num}.webp' copyfile(oldname, filename) process_image(v.patron, filename)