From 88bfaa33263dc2fcacb42f2ee2cdebfd442dce4d Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 17 Aug 2023 03:07:13 +0300 Subject: [PATCH] allow carp to delete image assets --- files/helpers/regex.py | 2 ++ files/routes/admin.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 32057be975..949d93b458 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -229,3 +229,5 @@ numbered_list_regex = re.compile('((\s|^)[0-9]+)\. ', flags=re.A) image_link_regex = re.compile(f"https:\/\/(i\.)?{SITE}\/(chat_)?images\/[0-9]{{11,17}}r?\.webp", flags=re.A) video_link_regex = re.compile(f"https://(videos\.)?{SITE}\/(videos\/)?[0-9a-zA-Z._-]{{4,66}}\.({video_regex_extensions})", flags=re.A) + +asset_image_link_regex = re.compile(f"https:\/\/(i\.)?{SITE}\/assets\/images\/[\w\/]+.webp(\?x=\d+)?", flags=re.A) diff --git a/files/routes/admin.py b/files/routes/admin.py index ab065592be..ffbec5c0b2 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1892,7 +1892,7 @@ def delete_media_post(v): if not url: abort(400, "No url provided!") - if not image_link_regex.fullmatch(url) and not video_link_regex.fullmatch(url): + if not image_link_regex.fullmatch(url) and not video_link_regex.fullmatch(url) and not asset_image_link_regex.fullmatch(url): abort(400, "Invalid url!") path = url.split(SITE)[1] @@ -1900,6 +1900,9 @@ def delete_media_post(v): if path.startswith('/1'): path = '/videos' + path + if path.startswith('/assets/images'): + path = 'files' + path.split('?x=')[0] + if not os.path.isfile(path): abort(400, "File not found on the server!")