constantify image extensions and fix imgur .gif bug

remotes/1693176582716663532/tmp_refs/heads/watchparty
Aevann1 2022-11-05 23:01:23 +02:00
parent 5efdc43be5
commit d76fe63c7f
13 changed files with 30 additions and 33 deletions

View File

@ -79,13 +79,12 @@ document.onpaste = function(event) {
f.files = files;
document.getElementById('filename-show').textContent = filename;
document.getElementById('urlblock').classList.add('d-none');
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".gif") || filename.endsWith(".webp"))
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
{
var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]);
fileReader.addEventListener("load", function () {document.getElementById('image-preview').setAttribute('src', this.result);});
}
document.getElementById('file-upload').setAttribute('required', 'false');
document.getElementById('post-url').value = null;
localStorage.setItem("post-url", "")
document.getElementById('image-upload-block').classList.remove('d-none')
@ -99,7 +98,7 @@ document.getElementById('file-upload').addEventListener('change', function(){
document.getElementById('urlblock').classList.add('d-none');
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
filename = f.files[0].name.toLowerCase()
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".gif") || filename.endsWith(".webp"))
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
{
var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]);

View File

@ -1598,6 +1598,6 @@ BOOSTED_SITES = {
'forums.red'
}
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')
IMAGE_FORMATS = ['png','gif','jpg','jpeg','webp']
VIDEO_FORMATS = ['mp4','webm','mov','avi','mkv','flv','m4v','3gp']
AUDIO_FORMATS = ['mp3','wav','ogg','aac','m4a','flac']

View File

@ -53,5 +53,5 @@ def inject_constants():
"CONTENT_SECURITY_POLICY_DEFAULT":CONTENT_SECURITY_POLICY_DEFAULT,
"CONTENT_SECURITY_POLICY_HOME":CONTENT_SECURITY_POLICY_HOME,
"TRUESCORE_DONATE_LIMIT":TRUESCORE_DONATE_LIMIT,
"BAN_EVASION_DOMAIN":BAN_EVASION_DOMAIN, "HOUSE_JOIN_COST":HOUSE_JOIN_COST, "HOUSE_SWITCH_COST":HOUSE_SWITCH_COST
"BAN_EVASION_DOMAIN":BAN_EVASION_DOMAIN, "HOUSE_JOIN_COST":HOUSE_JOIN_COST, "HOUSE_SWITCH_COST":HOUSE_SWITCH_COST, "IMAGE_FORMATS":IMAGE_FORMATS
}

View File

@ -77,8 +77,9 @@ video_sub_regex = re.compile(f'(<p>[^<]*)(https:\/\/([a-z0-9-]+\.)*({hosts})\/[\
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 = re.compile("(^|\s)(https:\/\/[\w\-.#&/=\?@%;+,:]{5,250}(\.png|\.jpg|\.jpeg|\.gif|\.webp)(\?[\w\-.#&/=\?@%;+,:]*)?)($|\s)", flags=re.I|re.A)
image_regex_extensions = '|'.join(IMAGE_FORMATS)
image_regex = re.compile(f"(^|\s)(https:\/\/[\w\-.#&/=\?@%;+,:]{{5,250}}\.({image_regex_extensions})(\?[\w\-.#&/=\?@%;+,:]*)?)($|\s)", flags=re.I|re.A)
image_regex_extensions = image_regex_extensions.replace('|gif', '')
imgur_regex = re.compile(f'(https:\/\/i\.imgur\.com\/[a-z0-9]+)\.({image_regex_extensions})', flags=re.I|re.A)
giphy_regex = re.compile('(https:\/\/media\.giphy\.com\/media\/[a-z0-9]+\/giphy)\.gif', flags=re.I|re.A)

View File

@ -474,7 +474,7 @@ def normalize_url(url):
.replace("https://nitter.42l.fr/", "https://twitter.com/") \
.replace("https://nitter.lacontrevoie.fr/", "https://twitter.com/")
url = imgur_regex.sub(r'\1_d.webp?maxwidth=9999&fidelity=high', url)
url = imgur_regex.sub(r'\1_d.webp?maxwidth=9999&fidelity=grand', url)
url = giphy_regex.sub(r'\1.webp', url)
return url

View File

@ -375,7 +375,7 @@ if SITE not in ('pcmemes.net', 'watchpeopledie.tv'):
if not file.content_type.startswith('image/'):
return error("You need to submit an image!")
for x in ('png','jpeg','webp','gif'):
for x in IMAGE_FORMATS:
if path.isfile(f'/asset_submissions/marseys/original/{name}.{x}'):
os.remove(f'/asset_submissions/marseys/original/{name}.{x}')
@ -449,7 +449,7 @@ if SITE not in ('pcmemes.net', 'watchpeopledie.tv'):
format = i.format.lower()
new_path = f'/asset_submissions/hats/original/{name}.{format}'
for x in ('png','jpeg','webp','gif'):
for x in IMAGE_FORMATS:
if path.isfile(f'/asset_submissions/hats/original/{name}.{x}'):
os.remove(f'/asset_submissions/hats/original/{name}.{x}')

View File

@ -34,14 +34,10 @@ def marseys(v):
original = os.listdir("/asset_submissions/marseys/original")
for marsey, user in marseys:
if f'{marsey.name}.png' in original:
marsey.og = f'{marsey.name}.png'
elif f'{marsey.name}.webp' in original:
marsey.og = f'{marsey.name}.webp'
elif f'{marsey.name}.gif' in original:
marsey.og = f'{marsey.name}.gif'
elif f'{marsey.name}.jpeg' in original:
marsey.og = f'{marsey.name}.jpeg'
for x in IMAGE_FORMATS:
if f'{marsey.name}.{x}' in original:
marsey.og = f'{marsey.name}.{x}'
break
else:
marseys = g.db.query(Marsey).filter(Marsey.submitter_id==None).order_by(Marsey.count.desc())

View File

@ -367,6 +367,10 @@
<div id="formkey" class="d-none">{{v.formkey}}</div>
{% endif %}
<script>
IMAGE_FORMATS = {{IMAGE_FORMATS|safe}};
</script>
{% if not v %}
<style>
.pad {

View File

@ -197,7 +197,7 @@
</div>
<div class="text-small text-muted mt-3">JPG, PNG, GIF files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.</div>
<div class="text-small text-muted mt-3">All image files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.</div>
</div>
@ -232,7 +232,7 @@
</div>
<div class="text-small text-muted mt-3">JPG, PNG, GIF files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.</div>
<div class="text-small text-muted mt-3">All image files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.</div>
</div>

View File

@ -67,7 +67,7 @@
</div>
<div class="text-small text-muted mt-3">JPG, PNG, GIF files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.</div>
<div class="text-small text-muted mt-3">All image files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.</div>
</div>
@ -102,7 +102,7 @@
</div>
<div class="text-small text-muted mt-3">JPG, PNG, GIF files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.</div>
<div class="text-small text-muted mt-3">All image files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.</div>
</div>
@ -138,7 +138,7 @@
</div>
<div class="text-small text-muted mt-3">JPG, PNG, GIF files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.</div>
<div class="text-small text-muted mt-3">All image files are supported. Max file size is {% if v and v.patron %}16{% else %}8{% endif %} MB.</div>
</div>

View File

@ -84,7 +84,7 @@
f=document.getElementById('file-upload');
f.files = files;
document.getElementById('filename-show').textContent = filename;
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".gif") || filename.endsWith(".webp"))
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
{
var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]);
@ -93,7 +93,6 @@
document.getElementById('image-preview').classList.remove('d-none');
});
}
document.getElementById('file-upload').setAttribute('placeholder="Required" required', 'false');
}
}
@ -101,7 +100,7 @@
f=document.getElementById('file-upload');
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
filename = f.files[0].name.toLowerCase()
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".gif") || filename.endsWith(".webp"))
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
{
var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]);

View File

@ -86,7 +86,7 @@
f=document.getElementById('file-upload');
f.files = files;
document.getElementById('filename-show').textContent = filename;
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".gif") || filename.endsWith(".webp"))
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
{
var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]);
@ -95,7 +95,6 @@
document.getElementById('image-preview').classList.remove('d-none');
});
}
document.getElementById('file-upload').setAttribute('placeholder="Required" required', 'false');
}
}
@ -103,7 +102,7 @@
f=document.getElementById('file-upload');
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
filename = f.files[0].name.toLowerCase()
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".gif") || filename.endsWith(".webp"))
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
{
var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]);

View File

@ -75,7 +75,7 @@
f=document.getElementById('file-upload');
f.files = files;
document.getElementById('filename-show').textContent = filename;
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".gif") || filename.endsWith(".webp"))
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
{
var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]);
@ -84,7 +84,6 @@
document.getElementById('image-preview').classList.remove('d-none');
});
}
document.getElementById('file-upload').setAttribute('placeholder="Required" required', 'false');
}
}
@ -92,7 +91,7 @@
f=document.getElementById('file-upload');
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
filename = f.files[0].name.toLowerCase()
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".png") || filename.endsWith(".gif") || filename.endsWith(".webp"))
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
{
var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]);