remotes/1693045480750635534/spooky-22
Aevann1 2022-04-10 01:41:36 +02:00
parent 30833f8130
commit 3b513d0841
3 changed files with 40 additions and 9 deletions

View File

@ -610,11 +610,11 @@ def message2(v, username):
message = embed_removing_regex.sub(r'\1', message)
text_html = sanitize(message, noimages=True)
body_html = sanitize(message, noimages=True)
existing = g.db.query(Comment.id).filter(Comment.author_id == v.id,
Comment.sentto == user.id,
Comment.body_html == text_html,
Comment.body_html == body_html,
).one_or_none()
if existing: return {"error": "Message already exists."}, 403
@ -623,7 +623,7 @@ def message2(v, username):
parent_submission=None,
level=1,
sentto=user.id,
body_html=text_html
body_html=body_html
)
g.db.add(c)
@ -654,7 +654,7 @@ def messagereply(v):
message = request.values.get("body", "").strip()[:10000].strip()
if not message: return {"error": "Message is empty!"}
if not message and not request.files.get("file"): return {"error": "Message is empty!"}
if 'linkedin.com' in message: return {"error": "this domain 'linkedin.com' is banned"}
@ -667,7 +667,26 @@ def messagereply(v):
if parent.sentto == 2: user_id = None
elif v.id == user_id: user_id = parent.sentto
text_html = sanitize(message, noimages=True)
body_html = sanitize(message, noimages=True)
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(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/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f:
try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']
except requests.Timeout: return {"error": "Video upload timed out, please try again!"}
try: url = req['link']
except: return {"error": req['error']}, 400
if url.endswith('.'): url += 'mp4'
body_html += f"<p>{url}</p>"
else: return {"error": "Image/Video files only"}, 400
new_comment = Comment(author_id=v.id,
parent_submission=None,
@ -675,7 +694,7 @@ def messagereply(v):
top_comment_id=parent.top_comment_id,
level=parent.level + 1,
sentto=user_id,
body_html=text_html,
body_html=body_html,
)
g.db.add(new_comment)
g.db.flush()

View File

@ -601,9 +601,16 @@
<input type="hidden" name="formkey" value="{{v.formkey}}">
<textarea required autocomplete="off" minlength="1" maxlength="10000" name="body" form="reply-to-t3_{{c.id}}" data-id="{{c.id}}" class="comment-box form-control rounded" id="reply-form-body-{{c.id}}" aria-label="With textarea" rows="3" oninput="markdown('reply-form-body-{{c.id}}', 'message-reply-{{c.id}}')"></textarea>
<div class="comment-format" id="comment-format-bar-{{c.id}}">
<label class="btn btn-secondary format m-0" for="gif-reply-btn-{{c.id}}" onclick="loadEmojis('reply-form-body-{{c.id}}')" aria-hidden="true" data-bs-toggle="modal" data-bs-target="#emojiModal" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Add Emoji">
<i id="emoji-reply-btn-{{c.id}}" class="fas fa-smile-beam"></i>
<label class="btn btn-secondary m-0 mt-3 mr-1" onclick="loadEmojis('reply-form-body-{{c.id}}')" aria-hidden="true" data-bs-toggle="modal" data-bs-target="#emojiModal" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Add Emoji">
<i class="fas fa-smile-beam"></i>
</label>
{% if c.sentto == 2 %}
<label class="btn btn-secondary m-0 mt-3" for="file-upload">
<div id="filename"><i class="far fa-image"></i></div>
<input autocomplete="off" id="file-upload" type="file" name="file" accept="image/*, video/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename','file-upload')" hidden>
</label>
{% endif %}
</div>
<a role="button" onclick="document.getElementById('reply-message-{{c.id}}').classList.add('d-none')" class="btn btn-link text-muted ml-auto cancel-form">Cancel</a>
@ -843,7 +850,7 @@
{% if v %}
<script src="/assets/js/marked.js?v=250"></script>
<script src="/assets/js/comments_v.js?v=263"></script>
<script src="/assets/js/comments_v.js?v=264"></script>
{% endif %}
<script src="/assets/js/clipboard.js?v=250"></script>

View File

@ -31,6 +31,9 @@
<label for="input-message" class="mt-3">Your message</label>
<input type="hidden" name="formkey" value="{{v.formkey}}">
<textarea autocomplete="off" maxlength="10000" id="input-message" form="contactform" name="message" class="form-control" required></textarea>
<label class="btn btn-secondary format m-0 mt-3" onclick="loadEmojis('input-message')" aria-hidden="true" data-bs-toggle="modal" data-bs-target="#emojiModal" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Add Emoji">
<i class="fas fa-smile-beam"></i>
</label>
<label class="btn btn-secondary m-0 mt-3" for="file-upload">
<div id="filename"><i class="far fa-image"></i></div>
<input autocomplete="off" id="file-upload" type="file" name="file" accept="image/*, video/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename','file-upload')" hidden>
@ -50,4 +53,6 @@
</pre>
{% include "emoji_modal.html" %}
{% endblock %}