remotes/1693045480750635534/spooky-22
Aevann1 2021-10-13 15:05:58 +02:00
parent 6ec2239f6f
commit 241ef545a0
4 changed files with 18 additions and 13 deletions

View File

@ -79,7 +79,7 @@ allowed_attributes = {'*': ['href', 'style', 'src', 'class', 'title', 'rel', 'da
allowed_protocols = ['http', 'https']
allowed_styles =['color', 'font-weight', 'transform', '-webkit-transform']
allowed_styles = ['color', 'font-weight', 'transform', '-webkit-transform']
def sanitize(sanitized, noimages=False):
@ -201,22 +201,22 @@ def sanitize(sanitized, noimages=False):
for i in re.finditer('" target="_blank">(https://youtube.com/watch\?v\=.*?)</a>', sanitized):
url = i.group(1)
replacing = f'<a href="{url}" rel="nofollow noopener noreferrer" target="_blank">{url}</a>'
htmlsource = f'<iframe class="embedvid" loading="lazy" data-src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
htmlsource = f'<iframe class="embedvid" loading="lazy" src="/assets/images/default_thumb_link.webp" data-src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
sanitized = sanitized.replace(replacing, htmlsource.replace("watch?v=", "embed/"))
for i in re.finditer('<a href="(https://streamable.com/e/.*?)"', sanitized):
url = i.group(1)
replacing = f'<a href="{url}" rel="nofollow noopener noreferrer" target="_blank">{url}</a>'
htmlsource = f'<iframe class="embedvid" loading="lazy" data-src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
htmlsource = f'<iframe class="embedvid" loading="lazy" src="/assets/images/default_thumb_link.webp" data-src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
sanitized = sanitized.replace(replacing, htmlsource)
for i in re.finditer('<p>(https:.*?\.mp4)</p>', sanitized):
sanitized = sanitized.replace(i.group(0), f'<p><video controls loop preload="metadata" class="embedvid"><source data-src="{i.group(1)}" type="video/mp4"></video>')
sanitized = sanitized.replace(i.group(0), f'<p><video controls loop preload="metadata" class="embedvid"><source src="/assets/images/default_thumb_link.webp" data-src="{i.group(1)}" type="video/mp4"></video>')
for i in re.finditer('<a href="(https://open.spotify.com/embed/.*?)"', sanitized):
url = i.group(1)
replacing = f'<a href="{url}" rel="nofollow noopener noreferrer" target="_blank">{url}</a>'
htmlsource = f'<iframe data-src="{url}" class="spotify" frameBorder="0" allowtransparency="true" allow="encrypted-media"></iframe>'
htmlsource = f'<iframe src="/assets/images/default_thumb_link.webp" data-src="{url}" class="spotify" frameBorder="0" allowtransparency="true" allow="encrypted-media"></iframe>'
sanitized = sanitized.replace(replacing, htmlsource)
for rd in ["https://reddit.com/", "https://new.reddit.com/", "https://www.reddit.com/", "https://redd.it/"]:

View File

@ -6,7 +6,7 @@
{% endblock %}
{% block content %}
<img class="in-comment-image rounded-sm my-2" data-src="https://media.giphy.com/media/c6Wwc9cT05vMdhyTcM/giphy.webp" loading="lazy" height="100px" rel="nofollow noopener noreferrer" data-placeholder-background="red" style="max-height: 100px; max-width: 100%;">
<img class="in-comment-image rounded-sm my-2" src="/assets/images/default_thumb_link.webp" data-src="https://media.giphy.com/media/c6Wwc9cT05vMdhyTcM/giphy.webp" loading="lazy" height="100px" rel="nofollow noopener noreferrer" data-placeholder-background="red" style="max-height: 100px; max-width: 100%;">
<pre>

View File

@ -468,17 +468,22 @@ Allowed styles:
</thead>
<tbody>
<tr>
<td>Color</td>
<td>color</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Font Weight</td>
<td>font-weight</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Transform</td>
<td>transform</td>
<td></td>
<td></td>
</tr>
<tr>
<td>-webkit-transform</td>
<td></td>
<td></td>
</tr>

View File

@ -436,7 +436,7 @@
{% if p.is_image and not p.over_18 and ((v and v.cardview) or (not v and environ.get('CARD_VIEW') == '1')) %}
<div style="text-align: center" class="mt-3 mb-4">
<a target="_blank" rel="nofollow noopener noreferrer" href="{{p.url}}">
<img loading="lazy" data-src="{{p.url}}" class="img-fluid" style="max-height:500px;" alt="Unable to load image">
<img loading="lazy" src="/assets/images/default_thumb_link.webp" data-src="{{p.url}}" class="img-fluid" style="max-height:500px;" alt="Unable to load image">
</a>
</div>
{% endif %}
@ -444,16 +444,16 @@
{% if p.url and p.url.lower().endswith('.mp4') %}
<div id="video-{{p.id}}" style="text-align: center" class="{% if p.over_18 or not ((v and v.cardview) or (not v and environ.get('CARD_VIEW') == '1')) %}d-none{% endif %} mt-4">
<video controls loop preload="metadata" style="max-width: 100%">
<source data-src="{{p.realurl(v)}}" type="video/mp4">
<source src="/assets/images/default_thumb_link.webp" data-src="{{p.realurl(v)}}" type="video/mp4">
</video>
</div>
{% elif p.embed_url and "youtu" in p.domain %}
<div id="video-{{p.id}}" style="text-align: center" class="{% if p.over_18 or not ((v and v.cardview) or (not v and environ.get('CARD_VIEW') == '1')) %}d-none{% endif %} mt-3 mb-4">
<iframe loading="lazy" data-src="{{p.embed_url}}" frameborder="0" style="max-width: 100%" width="600" height="337" allow="fullscreen"></iframe>
<iframe loading="lazy" src="/assets/images/default_thumb_link.webp" data-src="{{p.embed_url}}" frameborder="0" style="max-width: 100%" width="600" height="337" allow="fullscreen"></iframe>
</div>
{% elif p.url and "streamable.com/e/" in p.url %}
<div id="video-{{p.id}}" style="text-align: center" class="{% if p.over_18 or not ((v and v.cardview) or (not v and environ.get('CARD_VIEW') == '1')) %}d-none{% endif %} mt-3 mb-4">
<iframe loading="lazy" data-src="{{p.url}}" frameborder="0" style="max-width: 100%" width="600" height="337" allow="fullscreen"></iframe>
<iframe loading="lazy" src="/assets/images/default_thumb_link.webp" data-src="{{p.url}}" frameborder="0" style="max-width: 100%" width="600" height="337" allow="fullscreen"></iframe>
</div>
{% endif %}
{% endif %}