forked from rDrama/rDrama
1
0
Fork 0

fdMerge branch 'frost' of https://github.com/Aevann1/Drama into frost

master
Aevann1 2022-06-18 16:13:56 +00:00
commit 378bfc76ba
14 changed files with 1120 additions and 1149 deletions

File diff suppressed because one or more lines are too long

View File

@ -9,6 +9,32 @@ import time
from .const import *
def process_files():
body = ''
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
files = request.files.getlist('file')[:4]
for file in files:
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
url = process_image(v.patron, name)
body += f"\n\n![]({url})"
elif file.content_type.startswith('video/'):
value = process_video(file)
if type(value) is str: body += f"\n\n{value}"
else: return value
elif file.content_type.startswith('audio/'):
body += f"\n\n{process_audio(file)}"
else:
body += f"\n\n{process_other(file)}"
return body
def process_other(file):
req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': file}, timeout=20).json()
return req['files'][0]['url']
def process_audio(file):
name = f'/audio/{time.time()}'.replace('.','') + '.mp3'
file.save(name)

View File

@ -32,7 +32,7 @@ TLDS = ( # Original gTLDs and ccTLDs
'vu','wf','ws','xn','xxx','ye','yt','yu','za','zm','zw',
# New gTLDs
'app','cleaning','club','florist','fun','gay','lgbt','life','lol',
'moe','mom','monster','pics','pub','win','wtf','xyz',
'moe','mom','monster','pics','press','pub','win','wtf','xyz',
)
allowed_tags = ('b','blockquote','br','code','del','em','h1','h2','h3','h4','h5','h6','hr','i',
@ -165,6 +165,8 @@ def sanitize(sanitized, alert=False, edit=False):
signal.signal(signal.SIGALRM, handler)
signal.alarm(1)
sanitized = sanitized.strip()
if '```' not in sanitized and '<pre>' not in sanitized:
sanitized = linefeeds_regex.sub(r'\1\n\n\2', sanitized)

View File

@ -298,7 +298,8 @@ def api_comment(v):
else: return value
elif file.content_type.startswith('audio/'):
body += f"\n\n{process_audio(file)}"
else: return {"error": "Image/Video/Audio files only"}, 400
else:
body += f"\n\n{process_other(file)}"
body = body.strip()
@ -460,7 +461,7 @@ def api_comment(v):
body = AGENDAPOSTER_MSG.format(username=v.username, type='comment', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
body_jannied_html = sanitize(body)
body_jannied_html = AGENDAPOSTER_MSG_HTML.format(id=v.id, username=v.username, type='comment', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
@ -470,6 +471,7 @@ def api_comment(v):
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body=body,
body_html=body_jannied_html,
top_comment_id=c.top_comment_id,
ghost=c.ghost
@ -498,15 +500,13 @@ def api_comment(v):
c.downvotes = 1
body_html2 = sanitize(body)
c2 = Comment(author_id=LONGPOSTBOT_ID,
parent_submission=parent_submission,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body_html=body_html2,
body=body,
body_html=f"<p>{body}</p>",
top_comment_id=c.top_comment_id,
ghost=c.ghost
)
@ -525,19 +525,13 @@ def api_comment(v):
if SITE_NAME == 'rDrama' and random.random() < 0.001:
body = "zoz"
body_html2 = sanitize(body)
c2 = Comment(author_id=ZOZBOT_ID,
parent_submission=parent_submission,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body_html=body_html2,
body="zoz",
body_html="<p>zoz</p>",
top_comment_id=c.top_comment_id,
ghost=c.ghost,
distinguish_level=6
@ -550,19 +544,13 @@ def api_comment(v):
body = "zle"
body_html2 = sanitize(body)
c3 = Comment(author_id=ZOZBOT_ID,
parent_submission=parent_submission,
parent_comment_id=c2.id,
level=level+2,
is_bot=True,
body_html=body_html2,
body="zle",
body_html="<p>zle</p>",
top_comment_id=c.top_comment_id,
ghost=c.ghost,
distinguish_level=6
@ -571,16 +559,14 @@ def api_comment(v):
g.db.add(c3)
g.db.flush()
body = "zozzle"
body_html2 = sanitize(body)
c4 = Comment(author_id=ZOZBOT_ID,
parent_submission=parent_submission,
parent_comment_id=c3.id,
level=level+3,
is_bot=True,
body_html=body_html2,
body="zozzle",
body_html="<p>zozzle</p>",
top_comment_id=c.top_comment_id,
ghost=c.ghost,
distinguish_level=6
@ -712,8 +698,6 @@ def edit_comment(cid, v):
)
g.db.add(c_choice)
body_html = sanitize(body, edit=True)
if '!slots' not in body.lower() and '!blackjack' not in body.lower() and '!wordle' not in body.lower() and AGENDAPOSTER_PHRASE not in body.lower():
now = int(time.time())
cutoff = now - 60 * 60 * 24
@ -748,25 +732,11 @@ def edit_comment(cid, v):
return {"error": "Too much spam!"}, 403
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
files = request.files.getlist('file')[:4]
for file in files:
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
url = process_image(v.patron, name)
body += f"\n\n![]({url})"
elif file.content_type.startswith('video/'):
value = process_video(file)
if type(value) is str: body += f"\n\n{value}"
else: return value
elif file.content_type.startswith('audio/'):
body += f"\n\n{process_audio(file)}"
else: return {"error": "Image/Video/Audio files only"}, 400
body += process_files()
body = body.strip()
body = body.strip()
body_html = sanitize(body, edit=True)
body_html = sanitize(body, edit=True)
if len(body_html) > 20000: abort(400)
@ -794,7 +764,7 @@ def edit_comment(cid, v):
body = AGENDAPOSTER_MSG.format(username=v.username, type='comment', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
body_jannied_html = sanitize(body)
body_jannied_html = AGENDAPOSTER_MSG_HTML.format(id=v.id, username=v.username, type='comment', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
@ -804,6 +774,7 @@ def edit_comment(cid, v):
parent_comment_id=c.id,
level=c.level+1,
is_bot=True,
body=body,
body_html=body_jannied_html,
top_comment_id=c.top_comment_id,
ghost=c.ghost

View File

@ -465,21 +465,7 @@ def edit_post(pid, v):
p.title = title[:500]
p.title_html = title_html
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
files = request.files.getlist('file')[:4]
for file in files:
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
url = process_image(v.patron, name)
body += f"\n\n![]({url})"
elif file.content_type.startswith('video/'):
value = process_video(file)
if type(value) is str: body += f"\n\n{value}"
else: return value
elif file.content_type.startswith('audio/'):
body += f"\n\n{process_audio(file)}"
else: return {"error": "Image/Video/Audio files only"}, 400
body += process_files()
body = body.strip()
@ -536,7 +522,7 @@ def edit_post(pid, v):
body = AGENDAPOSTER_MSG.format(username=v.username, type='post', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
body_jannied_html = sanitize(body)
body_jannied_html = AGENDAPOSTER_MSG_HTML.format(id=v.id, username=v.username, type='post', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
c_jannied = Comment(author_id=NOTIFICATIONS_ID,
parent_submission=p.id,
@ -546,6 +532,7 @@ def edit_post(pid, v):
app_id=None,
stickied='AutoJanny',
distinguish_level=6,
body=body,
body_html=body_jannied_html,
ghost=p.ghost
)
@ -972,21 +959,7 @@ def submit_post(v, sub=None):
if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username)
if request.files.get("file2") and request.headers.get("cf-ipcountry") != "T1":
files = request.files.getlist('file2')[:4]
for file in files:
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
body += f"\n\n![]({process_image(v.patron, name)})"
elif file.content_type.startswith('video/'):
value = process_video(file)
if type(value) is str: body += f"\n\n{value}"
else: return error(value['error'])
elif file.content_type.startswith('audio/'):
body += f"\n\n{process_audio(file)}"
else:
return error("Image/Video/Audio files only.")
body += process_files()
body = body.strip()
@ -1074,9 +1047,9 @@ def submit_post(v, sub=None):
)
g.db.add(vote)
if request.files.get('file') and request.headers.get("cf-ipcountry") != "T1":
if request.files.get('file-url') and request.headers.get("cf-ipcountry") != "T1":
file = request.files['file']
file = request.files['file-url']
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
@ -1093,7 +1066,7 @@ def submit_post(v, sub=None):
elif file.content_type.startswith('audio/'):
post.url = process_audio(file)
else:
return error("Image/Video/Audio files only.")
post.url = process_other(file)
if not post.thumburl and post.url:
gevent.spawn(thumbnail_thread, post.id)
@ -1136,8 +1109,7 @@ def submit_post(v, sub=None):
body = AGENDAPOSTER_MSG.format(username=v.username, type='post', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
body_jannied_html = sanitize(body)
body_jannied_html = AGENDAPOSTER_MSG_HTML.format(id=v.id, username=v.username, type='post', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
c_jannied = Comment(author_id=NOTIFICATIONS_ID,
@ -1148,6 +1120,7 @@ def submit_post(v, sub=None):
app_id=None,
stickied='AutoJanny',
distinguish_level=6,
body=body,
body_html=body_jannied_html,
ghost=post.ghost
)
@ -1240,6 +1213,8 @@ def submit_post(v, sub=None):
body += f'* [ghostarchive.org](https://ghostarchive.org/search?term={quote(href)}) (click to archive)\n\n'
gevent.spawn(archiveorg, href)
body = body.strip()
body_html = sanitize(body)
if len(body_html) < 40000:
@ -1250,6 +1225,7 @@ def submit_post(v, sub=None):
over_18=False,
is_bot=True,
app_id=None,
body=body,
body_html=body_html,
ghost=post.ghost
)

View File

@ -215,25 +215,10 @@ def settings_profile_post(v):
msg="Your enemies list has been updated.")
elif request.values.get("bio") or request.files.get('file') and request.headers.get("cf-ipcountry") != "T1":
elif request.values.get("bio") or request.files.get('file'):
bio = request.values.get("bio")[:1500]
if request.files.get('file'):
file = request.files['file']
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
url = process_image(v.patron, name)
bio += f"\n\n![]({url})"
elif file.content_type.startswith('video/'):
value = process_video(file)
if type(value) is str: bio += f"\n\n{value}"
else: return value
elif file.content_type.startswith('audio/'):
bio += f"\n\n{process_audio(file)}"
else:
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "Image/Video/Audio files only"}, 400
return render_template("settings_profile.html", v=v, error="Image/Video/Audio files only."), 400
bio += process_files()
bio = bio.strip()

View File

@ -199,19 +199,21 @@ def submit_contact(v):
body_html = sanitize(body)
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file"]
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
url = process_image(v.patron, name)
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="img" src="{url}" loading="lazy">'
elif file.content_type.startswith('video/'):
value = process_video(file)
if type(value) is str: body_html += f"<p>{value}</p>"
else: return value
elif file.content_type.startswith('audio/'):
body_html += f"<p>{process_audio(file)}</p>"
else: return {"error": "Image/Video/Audio files only"}, 400
files = request.files.getlist('file')[:4]
for file in files:
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
url = process_image(v.patron, name)
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="img" src="{url}" loading="lazy">'
elif file.content_type.startswith('video/'):
value = process_video(file)
if type(value) is str: body_html += f"<p>{value}</p>"
else: return value
elif file.content_type.startswith('audio/'):
body_html += f"<p>{process_audio(file)}</p>"
else:
body_html += f"<p>{process_other(file)}</p>"

View File

@ -726,19 +726,21 @@ def messagereply(v):
body_html = sanitize(message)
if parent.sentto == 2 and request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file"]
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
url = process_image(v.patron, name)
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="img" src="{url}" loading="lazy">'
elif file.content_type.startswith('video/'):
value = process_video(file)
if type(value) is str: body_html += f"<p>{value}</p>"
else: return value
elif file.content_type.startswith('audio/'):
body_html += f"<p>{process_audio(file)}</p>"
else: return {"error": "Image/Video/Audio files only"}, 400
files = request.files.getlist('file')[:4]
for file in files:
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
url = process_image(v.patron, name)
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="img" src="{url}" loading="lazy">'
elif file.content_type.startswith('video/'):
value = process_video(file)
if type(value) is str: body_html += f"<p>{value}</p>"
else: return value
elif file.content_type.startswith('audio/'):
body_html += f"<p>{process_audio(file)}</p>"
else:
body_html += f"<p>{process_other(file)}</p>"
c = Comment(author_id=v.id,

View File

@ -329,7 +329,7 @@
<label class="btn btn-secondary format m-0" for="file-edit-reply-{{c.id}}">
<div id="filename-edit-reply-{{c.id}}"><i class="fas fa-file"></i></div>
<input autocomplete="off" id="file-edit-reply-{{c.id}}" type="file" multiple="multiple" name="file" accept="image/*, video/*, audio/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-edit-reply-{{c.id}}','file-edit-reply-{{c.id}}')" hidden>
<input autocomplete="off" id="file-edit-reply-{{c.id}}" type="file" multiple="multiple" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-edit-reply-{{c.id}}','file-edit-reply-{{c.id}}')" hidden>
</label>
</div>
<a id="edit-btn-{{c.id}}" role="button" form="comment-edit-form-{{c.id}}" class="btn btn-primary ml-2 fl-r commentmob" onclick="comment_edit('{{c.id}}')">Save Edit</a>
@ -581,7 +581,7 @@
&nbsp;
<label class="btn btn-secondary format m-0" for="file-upload-reply-{{c.fullname}}">
<div id="filename-show-reply-{{c.fullname}}"><i class="fas fa-file"></i></div>
<input autocomplete="off" id="file-upload-reply-{{c.fullname}}" type="file" multiple="multiple" name="file" accept="image/*, video/*, audio/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-reply-{{c.fullname}}','file-upload-reply-{{c.fullname}}')" hidden>
<input autocomplete="off" id="file-upload-reply-{{c.fullname}}" type="file" multiple="multiple" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-reply-{{c.fullname}}','file-upload-reply-{{c.fullname}}')" hidden>
</label>
</div>
<a id="save-reply-to-{{c.fullname}}" class="btn btn-primary ml-2 fl-r commentmob" onclick="post_comment('{{c.fullname}}', '{{c.post.id}}')"role="button">Comment</a>
@ -620,7 +620,7 @@
{% if c.sentto == 2 %}
<label class="btn btn-secondary m-0 mt-3" for="file-upload">
<div id="filename"><i class="fas fa-file"></i></div>
<input autocomplete="off" id="file-upload" type="file" name="file" accept="image/*, video/*, audio/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename','file-upload')" hidden>
<input autocomplete="off" id="file-upload" type="file" name="file" multiple="multiple" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename','file-upload')" hidden>
</label>
{% endif %}
</div>

View File

@ -36,7 +36,7 @@
</label>
<label class="btn btn-secondary m-0 mt-3" for="file-upload">
<div id="filename"><i class="fas fa-file"></i></div>
<input autocomplete="off" id="file-upload" type="file" name="file" accept="image/*, video/*, audio/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename','file-upload')" hidden>
<input autocomplete="off" id="file-upload" type="file" name="file" multiple="multiple" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename','file-upload')" hidden>
</label>
<input type="submit" value="Submit" class="btn btn-primary mt-3">
</form>

View File

@ -16,7 +16,7 @@
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="{{asset('css/' + v.theme + '.css')}}">
<link rel="stylesheet" href="/assets/css/awards.css?v=8">
<link rel="stylesheet" href="/assets/css/awards.css?v=11">
{% if v.agendaposter %}
<style>
html {
@ -42,7 +42,7 @@
<style>:root{--primary:#{{config('DEFAULT_COLOR')}}</style>
<link rel="stylesheet" href="{{asset('css/main.css')}}">
<link rel="stylesheet" href="/assets/css/{{config('DEFAULT_THEME')}}.css?v=57">
<link rel="stylesheet" href="/assets/css/awards.css?v=8">
<link rel="stylesheet" href="/assets/css/awards.css?v=11">
{% endif %}
{% if request.path == '/catalog' %}

View File

@ -606,7 +606,7 @@
&nbsp;
<label class="btn btn-secondary format d-inline-block m-0">
<div id="filename-show"><i class="fas fa-file"></i></div>
<input autocomplete="off" id="file-upload" type="file" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} accept="image/*, video/*, audio/*" onchange="changename('filename-show','file-upload')" hidden>
<input autocomplete="off" id="file-upload" type="file" name="file" multiple="multiple" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show','file-upload')" hidden>
</label>
</div>
<pre></pre>

View File

@ -878,7 +878,7 @@
<label class="format btn btn-secondary m-0 ml-1 {% if v %}d-inline-block{% else %}d-none{% endif %}" for="file-upload-edit-{{p.id}}">
<div id="filename-show-edit-{{p.id}}"><i class="fas fa-file"></i></div>
<input autocomplete="off" id="file-upload-edit-{{p.id}}" type="file" multiple="multiple" name="file" accept="image/*, video/*, audio/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-edit-{{p.id}}','file-upload-edit-{{p.id}}')" hidden>
<input autocomplete="off" id="file-upload-edit-{{p.id}}" type="file" multiple="multiple" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-edit-{{p.id}}','file-upload-edit-{{p.id}}')" hidden>
</label>
<small class="format d-none"><i class="fas fa-link" aria-hidden="true"></i></small>
@ -1075,7 +1075,7 @@
&nbsp;
<label class="format btn btn-secondary m-0 ml-1 {% if v %}d-inline-block{% else %}d-none{% endif %}" for="file-upload-reply-{{p.fullname}}">
<div id="filename-show-reply-{{p.fullname}}"><i class="fas fa-file"></i></div>
<input autocomplete="off" id="file-upload-reply-{{p.fullname}}" type="file" multiple="multiple" name="file" accept="image/*, video/*, audio/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-reply-{{p.fullname}}','file-upload-reply-{{p.fullname}}')" hidden>
<input autocomplete="off" id="file-upload-reply-{{p.fullname}}" type="file" multiple="multiple" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-reply-{{p.fullname}}','file-upload-reply-{{p.fullname}}')" hidden>
</label>
</div>
<a id="save-reply-to-{{p.fullname}}" role="button" form="reply-to-{{p.fullname}}" class="btn btn-primary text-whitebtn ml-auto fl-r" onclick="post_comment('{{p.fullname}}', '{{p.id}}')">Comment</a>

View File

@ -111,7 +111,7 @@
<img loading="lazy" id="image-preview" style="max-width:50%">
<label class="btn btn-secondary m-0" for="file-upload">
<div id="filename-show">Select File</div>
<input autocomplete="off" id="file-upload" type="file" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} accept="image/*, video/*, audio/*" hidden>
<input autocomplete="off" id="file-upload" type="file" name="file-url" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} hidden>
</label>
<small class="form-text text-muted">Optional if you have text.</small>
<small class="form-text text-muted">You can upload images or videos up to 60 seconds.</small>
@ -147,7 +147,7 @@
<label class="format btn btn-secondary m-0 ml-1 {% if v %}d-inline-block{% else %}d-none{% endif %}" for="file-upload-submit">
<div id="filename-show-submit"><i class="fas fa-file"></i></div>
<input autocomplete="off" id="file-upload-submit" multiple="multiple" type="file" name="file2" accept="image/*, video/*, audio/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-submit','file-upload-submit');checkForRequired()" hidden>
<input autocomplete="off" id="file-upload-submit" multiple="multiple" type="file" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-submit','file-upload-submit');checkForRequired()" hidden>
</label>
<div id="preview" class="preview my-3"></div>