allow carp to delete image assets

pull/195/head
Aevann 2023-08-17 03:07:13 +03:00
parent 4787150b60
commit 88bfaa3326
2 changed files with 6 additions and 1 deletions

View File

@ -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)

View File

@ -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!")