forked from rDrama/rDrama
allow carp to delete image assets
parent
4787150b60
commit
88bfaa3326
|
@ -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)
|
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)
|
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)
|
||||||
|
|
|
@ -1892,7 +1892,7 @@ def delete_media_post(v):
|
||||||
if not url:
|
if not url:
|
||||||
abort(400, "No url provided!")
|
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!")
|
abort(400, "Invalid url!")
|
||||||
|
|
||||||
path = url.split(SITE)[1]
|
path = url.split(SITE)[1]
|
||||||
|
@ -1900,6 +1900,9 @@ def delete_media_post(v):
|
||||||
if path.startswith('/1'):
|
if path.startswith('/1'):
|
||||||
path = '/videos' + path
|
path = '/videos' + path
|
||||||
|
|
||||||
|
if path.startswith('/assets/images'):
|
||||||
|
path = 'files' + path.split('?x=')[0]
|
||||||
|
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
abort(400, "File not found on the server!")
|
abort(400, "File not found on the server!")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue