forked from MarseyWorld/MarseyWorld
constantify image extensions and fix imgur .gif bug
parent
5efdc43be5
commit
d76fe63c7f
|
@ -79,13 +79,12 @@ document.onpaste = function(event) {
|
||||||
f.files = files;
|
f.files = files;
|
||||||
document.getElementById('filename-show').textContent = filename;
|
document.getElementById('filename-show').textContent = filename;
|
||||||
document.getElementById('urlblock').classList.add('d-none');
|
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();
|
var fileReader = new FileReader();
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
fileReader.readAsDataURL(f.files[0]);
|
||||||
fileReader.addEventListener("load", function () {document.getElementById('image-preview').setAttribute('src', this.result);});
|
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;
|
document.getElementById('post-url').value = null;
|
||||||
localStorage.setItem("post-url", "")
|
localStorage.setItem("post-url", "")
|
||||||
document.getElementById('image-upload-block').classList.remove('d-none')
|
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('urlblock').classList.add('d-none');
|
||||||
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
|
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
|
||||||
filename = f.files[0].name.toLowerCase()
|
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();
|
var fileReader = new FileReader();
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
fileReader.readAsDataURL(f.files[0]);
|
||||||
|
|
|
@ -1598,6 +1598,6 @@ BOOSTED_SITES = {
|
||||||
'forums.red'
|
'forums.red'
|
||||||
}
|
}
|
||||||
|
|
||||||
IMAGE_FORMATS = ('webp','jpg','jpeg','png','gif','gifv','tif','tiff')
|
IMAGE_FORMATS = ['png','gif','jpg','jpeg','webp']
|
||||||
VIDEO_FORMATS = ('mp4','webm','mov','avi','mkv','flv','m4v','3gp')
|
VIDEO_FORMATS = ['mp4','webm','mov','avi','mkv','flv','m4v','3gp']
|
||||||
AUDIO_FORMATS = ('mp3','wav','ogg','aac','m4a','flac')
|
AUDIO_FORMATS = ['mp3','wav','ogg','aac','m4a','flac']
|
||||||
|
|
|
@ -53,5 +53,5 @@ def inject_constants():
|
||||||
"CONTENT_SECURITY_POLICY_DEFAULT":CONTENT_SECURITY_POLICY_DEFAULT,
|
"CONTENT_SECURITY_POLICY_DEFAULT":CONTENT_SECURITY_POLICY_DEFAULT,
|
||||||
"CONTENT_SECURITY_POLICY_HOME":CONTENT_SECURITY_POLICY_HOME,
|
"CONTENT_SECURITY_POLICY_HOME":CONTENT_SECURITY_POLICY_HOME,
|
||||||
"TRUESCORE_DONATE_LIMIT":TRUESCORE_DONATE_LIMIT,
|
"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
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,9 @@ video_sub_regex = re.compile(f'(<p>[^<]*)(https:\/\/([a-z0-9-]+\.)*({hosts})\/[\
|
||||||
audio_regex_extensions = '|'.join(AUDIO_FORMATS)
|
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)
|
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_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)
|
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)
|
giphy_regex = re.compile('(https:\/\/media\.giphy\.com\/media\/[a-z0-9]+\/giphy)\.gif', flags=re.I|re.A)
|
||||||
|
|
|
@ -474,7 +474,7 @@ def normalize_url(url):
|
||||||
.replace("https://nitter.42l.fr/", "https://twitter.com/") \
|
.replace("https://nitter.42l.fr/", "https://twitter.com/") \
|
||||||
.replace("https://nitter.lacontrevoie.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)
|
url = giphy_regex.sub(r'\1.webp', url)
|
||||||
|
|
||||||
return url
|
return url
|
||||||
|
|
|
@ -375,7 +375,7 @@ if SITE not in ('pcmemes.net', 'watchpeopledie.tv'):
|
||||||
if not file.content_type.startswith('image/'):
|
if not file.content_type.startswith('image/'):
|
||||||
return error("You need to submit an 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}'):
|
if path.isfile(f'/asset_submissions/marseys/original/{name}.{x}'):
|
||||||
os.remove(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()
|
format = i.format.lower()
|
||||||
new_path = f'/asset_submissions/hats/original/{name}.{format}'
|
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}'):
|
if path.isfile(f'/asset_submissions/hats/original/{name}.{x}'):
|
||||||
os.remove(f'/asset_submissions/hats/original/{name}.{x}')
|
os.remove(f'/asset_submissions/hats/original/{name}.{x}')
|
||||||
|
|
||||||
|
|
|
@ -34,14 +34,10 @@ def marseys(v):
|
||||||
|
|
||||||
original = os.listdir("/asset_submissions/marseys/original")
|
original = os.listdir("/asset_submissions/marseys/original")
|
||||||
for marsey, user in marseys:
|
for marsey, user in marseys:
|
||||||
if f'{marsey.name}.png' in original:
|
for x in IMAGE_FORMATS:
|
||||||
marsey.og = f'{marsey.name}.png'
|
if f'{marsey.name}.{x}' in original:
|
||||||
elif f'{marsey.name}.webp' in original:
|
marsey.og = f'{marsey.name}.{x}'
|
||||||
marsey.og = f'{marsey.name}.webp'
|
break
|
||||||
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'
|
|
||||||
else:
|
else:
|
||||||
marseys = g.db.query(Marsey).filter(Marsey.submitter_id==None).order_by(Marsey.count.desc())
|
marseys = g.db.query(Marsey).filter(Marsey.submitter_id==None).order_by(Marsey.count.desc())
|
||||||
|
|
||||||
|
|
|
@ -367,6 +367,10 @@
|
||||||
<div id="formkey" class="d-none">{{v.formkey}}</div>
|
<div id="formkey" class="d-none">{{v.formkey}}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
IMAGE_FORMATS = {{IMAGE_FORMATS|safe}};
|
||||||
|
</script>
|
||||||
|
|
||||||
{% if not v %}
|
{% if not v %}
|
||||||
<style>
|
<style>
|
||||||
.pad {
|
.pad {
|
||||||
|
|
|
@ -197,7 +197,7 @@
|
||||||
|
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@
|
||||||
|
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
|
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@
|
||||||
|
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@
|
||||||
|
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@
|
||||||
f=document.getElementById('file-upload');
|
f=document.getElementById('file-upload');
|
||||||
f.files = files;
|
f.files = files;
|
||||||
document.getElementById('filename-show').textContent = filename;
|
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();
|
var fileReader = new FileReader();
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
fileReader.readAsDataURL(f.files[0]);
|
||||||
|
@ -93,7 +93,6 @@
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
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');
|
f=document.getElementById('file-upload');
|
||||||
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
|
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
|
||||||
filename = f.files[0].name.toLowerCase()
|
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();
|
var fileReader = new FileReader();
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
fileReader.readAsDataURL(f.files[0]);
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
f=document.getElementById('file-upload');
|
f=document.getElementById('file-upload');
|
||||||
f.files = files;
|
f.files = files;
|
||||||
document.getElementById('filename-show').textContent = filename;
|
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();
|
var fileReader = new FileReader();
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
fileReader.readAsDataURL(f.files[0]);
|
||||||
|
@ -95,7 +95,6 @@
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
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');
|
f=document.getElementById('file-upload');
|
||||||
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
|
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
|
||||||
filename = f.files[0].name.toLowerCase()
|
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();
|
var fileReader = new FileReader();
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
fileReader.readAsDataURL(f.files[0]);
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
f=document.getElementById('file-upload');
|
f=document.getElementById('file-upload');
|
||||||
f.files = files;
|
f.files = files;
|
||||||
document.getElementById('filename-show').textContent = filename;
|
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();
|
var fileReader = new FileReader();
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
fileReader.readAsDataURL(f.files[0]);
|
||||||
|
@ -84,7 +84,6 @@
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
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');
|
f=document.getElementById('file-upload');
|
||||||
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
|
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
|
||||||
filename = f.files[0].name.toLowerCase()
|
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();
|
var fileReader = new FileReader();
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
fileReader.readAsDataURL(f.files[0]);
|
||||||
|
|
Loading…
Reference in New Issue