constantify file extensions
parent
23883c530b
commit
b9c482712a
|
@ -388,17 +388,17 @@ class Submission(Base):
|
|||
@property
|
||||
@lazy
|
||||
def is_video(self):
|
||||
return self.url and any((self.url.lower().endswith(x) for x in ('.mp4','.webm','.mov'))) and is_safe_url(self.url)
|
||||
return self.url and any((self.url.lower().split('?')[0].endswith(f'.{x}') for x in VIDEO_FORMATS)) and is_safe_url(self.url)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def is_audio(self):
|
||||
return self.url and any((self.url.lower().endswith(x) for x in ('.mp3','.wav','.ogg','.aac','.m4a','.flac'))) and is_safe_url(self.url)
|
||||
return self.url and any((self.url.lower().split('?')[0].endswith(f'.{x}') for x in AUDIO_FORMATS)) and is_safe_url(self.url)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def is_image(self):
|
||||
return self.url and any((self.url.lower().endswith(x) for x in ('.webp','.jpg','.png','.gif','.jpeg','?maxwidth=9999','&fidelity=high'))) and is_safe_url(self.url)
|
||||
return self.url and any((self.url.lower().split('?')[0].endswith(f'.{x}') for x in IMAGE_FORMATS)) and is_safe_url(self.url)
|
||||
|
||||
@lazy
|
||||
def filtered_flags(self, v):
|
||||
|
|
|
@ -1388,3 +1388,7 @@ BOOSTED_SITES = {
|
|||
't.me',
|
||||
'web.telegram.org'
|
||||
}
|
||||
|
||||
IMAGE_FORMATS = ('webp','jpg','jpeg','png','gif','gifv','tif','tiff')
|
||||
VIDEO_FORMATS = ('mp4','webm','mov','avi','mkv','flv','m4v','3gp')
|
||||
AUDIO_FORMATS = ('mp3','wav','ogg','aac','m4a','flac')
|
||||
|
|
|
@ -66,10 +66,15 @@ torture_regex_exclude = re.compile('^\s*>', flags=re.A)
|
|||
|
||||
image_check_regex = re.compile(f'!\[\]\(((?!(https:\/\/([a-z0-9-]+\.)*({hosts})\/|\/)).*?)\)', flags=re.A)
|
||||
|
||||
video_sub_regex = re.compile(f'(<p>[^<]*)(https:\/\/([a-z0-9-]+\.)*({hosts})\/[\w:~,()\-.#&\/=?@%;+]*?\.(mp4|webm|mov))', flags=re.A)
|
||||
audio_sub_regex = re.compile(f'(<p>[^<]*)(https:\/\/([a-z0-9-]+\.)*({hosts})\/[\w:~,()\-.#&\/=?@%;+]*?\.(mp3|wav|ogg|aac|m4a|flac))', flags=re.A)
|
||||
video_regex_extensions = '|'.join(VIDEO_FORMATS)
|
||||
video_sub_regex = re.compile(f'(<p>[^<]*)(https:\/\/([a-z0-9-]+\.)*({hosts})\/[\w:~,()\-.#&\/=?@%;+]*?\.({video_regex_extensions}))', flags=re.A)
|
||||
|
||||
audio_regex_extensions = '|'.join(AUDIO_FORMATS)
|
||||
audio_sub_regex = re.compile(f'(<p>[^<]*)(https:\/\/([a-z0-9-]+\.)*({hosts})\/[\w:~,()\-.#&\/=?@%;+]*?\.({audio_regex_extensions}))', flags=re.A)
|
||||
|
||||
image_regex_extensions = '|'.join(IMAGE_FORMATS)
|
||||
imgur_regex = re.compile(f'(https:\/\/i\.imgur\.com\/[a-z0-9]+)\.({image_regex_extensions})', flags=re.I|re.A)
|
||||
|
||||
imgur_regex = re.compile('(https:\/\/i\.imgur\.com\/[a-z0-9]+)\.(jpg|png|jpeg|webp)', flags=re.I|re.A)
|
||||
giphy_regex = re.compile('(https:\/\/media\.giphy\.com\/media\/[a-z0-9]+\/giphy)\.gif', flags=re.I|re.A)
|
||||
|
||||
youtube_regex = re.compile('(<p>[^<]*)(https:\/\/youtube\.com\/watch\?v\=([a-z0-9-_]{5,20})[\w\-.#&/=\?@%+]*)', flags=re.I|re.A)
|
||||
|
|
|
@ -1068,11 +1068,7 @@ def pin_post(post_id, v):
|
|||
return abort(404, "Post not found!")
|
||||
|
||||
|
||||
extensions = (
|
||||
'.webp','.jpg','.png','.jpeg','.gif','.gifv','.tif', '.tiff',
|
||||
'.mp4','.webm','.mov',
|
||||
'.mp3','.wav','.ogg','.aac','.m4a','.flac'
|
||||
)
|
||||
extensions = IMAGE_FORMATS + VIDEO_FORMATS + AUDIO_FORMATS
|
||||
|
||||
@app.get("/submit/title")
|
||||
@limiter.limit("3/minute")
|
||||
|
@ -1083,8 +1079,8 @@ def get_post_title(v):
|
|||
url = request.values.get("url")
|
||||
if not url or '\\' in url: abort(400)
|
||||
|
||||
checking_url = url.lower().rstrip('%3F').rstrip('?')
|
||||
if any((checking_url.endswith(x) for x in extensions)):
|
||||
checking_url = url.lower().split('?')[0].split('%3F')[0]
|
||||
if any((checking_url.endswith(f'.{x}') for x in extensions)):
|
||||
abort(400)
|
||||
|
||||
try: x = requests.get(url, headers=titleheaders, timeout=5, proxies=proxies)
|
||||
|
|
Loading…
Reference in New Issue