xvc
This commit is contained in:
parent
aa3e20a5ca
commit
dcf373ef1e
7 changed files with 66 additions and 7 deletions
|
@ -53,3 +53,32 @@ function savetext() {
|
||||||
localStorage.setItem("post_title", post_title)
|
localStorage.setItem("post_title", post_title)
|
||||||
localStorage.setItem("post_text", post_text)
|
localStorage.setItem("post_text", post_text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function autoSuggestTitle() {
|
||||||
|
|
||||||
|
var urlField = document.getElementById("post-URL");
|
||||||
|
|
||||||
|
var titleField = document.getElementById("post-title");
|
||||||
|
|
||||||
|
var isValidURL = urlField.checkValidity();
|
||||||
|
|
||||||
|
if (isValidURL && urlField.value.length > 0 && titleField.value === "") {
|
||||||
|
|
||||||
|
var x = new XMLHttpRequest();
|
||||||
|
x.withCredentials=true;
|
||||||
|
x.onreadystatechange = function() {
|
||||||
|
if (x.readyState == 4 && x.status == 200) {
|
||||||
|
|
||||||
|
title=JSON.parse(x.responseText)["title"];
|
||||||
|
titleField.value=title;
|
||||||
|
|
||||||
|
checkForRequired()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x.open('get','/submit/title?url=' + urlField.value);
|
||||||
|
x.send(null);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
|
@ -8,7 +8,8 @@ def process_image(filename=None, resize=0):
|
||||||
i = Image.open(filename)
|
i = Image.open(filename)
|
||||||
|
|
||||||
if resize and i.width > resize:
|
if resize and i.width > resize:
|
||||||
subprocess.call(["convert", filename, "-coalesce", "-resize", f"{resize}>", filename])
|
try: subprocess.call(["convert", filename, "-coalesce", "-resize", f"{resize}>", filename])
|
||||||
|
except: pass
|
||||||
elif i.format.lower() != "webp":
|
elif i.format.lower() != "webp":
|
||||||
|
|
||||||
exif = i.getexif()
|
exif = i.getexif()
|
||||||
|
|
|
@ -302,6 +302,12 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
||||||
|
|
||||||
def filter_emojis_only(title, edit=False, graceful=False):
|
def filter_emojis_only(title, edit=False, graceful=False):
|
||||||
|
|
||||||
|
signal.signal(signal.SIGALRM, handler)
|
||||||
|
signal.alarm(1)
|
||||||
|
|
||||||
|
if title.count(':') > 100: abort(418)
|
||||||
|
if title.count('@') > 50: abort(418)
|
||||||
|
|
||||||
title = title.replace('<','<').replace('>','>').replace("\n", "").replace("\r", "").replace("\t", "").strip()
|
title = title.replace('<','<').replace('>','>').replace("\n", "").replace("\r", "").replace("\t", "").strip()
|
||||||
|
|
||||||
title = bleach.clean(title, tags=[])
|
title = bleach.clean(title, tags=[])
|
||||||
|
@ -334,5 +340,7 @@ def filter_emojis_only(title, edit=False, graceful=False):
|
||||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||||
title = re.sub(f'(?<!"):{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" delay="0" class="{classes}" src="/static/assets/images/emojis/{emoji}.webp">', title, re.I)
|
title = re.sub(f'(?<!"):{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" delay="0" class="{classes}" src="/static/assets/images/emojis/{emoji}.webp">', title, re.I)
|
||||||
|
|
||||||
|
signal.alarm(0)
|
||||||
|
|
||||||
if len(title) > 1500 and not graceful: abort(400)
|
if len(title) > 1500 and not graceful: abort(400)
|
||||||
else: return title
|
else: return title
|
|
@ -40,6 +40,8 @@ discounts = {
|
||||||
73: 0.10,
|
73: 0.10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
titleheaders = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36"}
|
||||||
|
|
||||||
def ghost_price(v):
|
def ghost_price(v):
|
||||||
if v.patron == 1: discount = 0.90
|
if v.patron == 1: discount = 0.90
|
||||||
elif v.patron == 2: discount = 0.85
|
elif v.patron == 2: discount = 0.85
|
||||||
|
@ -1494,3 +1496,22 @@ def api_pin_post(post_id, v):
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
if post.is_pinned: return {"message": "Post pinned!"}
|
if post.is_pinned: return {"message": "Post pinned!"}
|
||||||
else: return {"message": "Post unpinned!"}
|
else: return {"message": "Post unpinned!"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/submit/title")
|
||||||
|
@limiter.limit("6/minute")
|
||||||
|
@auth_required
|
||||||
|
def get_post_title(v):
|
||||||
|
|
||||||
|
url = request.values.get("url", None)
|
||||||
|
if not url: abort(400)
|
||||||
|
|
||||||
|
try: x = requests.get(url, headers=titleheaders, timeout=5)
|
||||||
|
except: abort(400)
|
||||||
|
|
||||||
|
soup = BeautifulSoup(x.content, 'html.parser')
|
||||||
|
|
||||||
|
title = soup.find('title')
|
||||||
|
if not title: abort(400)
|
||||||
|
|
||||||
|
return {"url": url, "title": title.string}
|
|
@ -356,7 +356,7 @@ def leaderboard(v):
|
||||||
sq = g.db.query(User.id, func.rank().over(order_by=User.truecoins.desc()).label("rank")).subquery()
|
sq = g.db.query(User.id, func.rank().over(order_by=User.truecoins.desc()).label("rank")).subquery()
|
||||||
pos10 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1]
|
pos10 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1]
|
||||||
|
|
||||||
sq = g.db.query(Badge.user_id, func.count(Badge.user_id).label("count"), func.rank().over(order_by=func.count(Badge.user_id).desc()).label("rank")).group_by(Badge.user_id).subquery()
|
sq = g.db.query(Badge.user_id, func.count(Badge.user_id).label("count"), func.rank().over(order_by=func.count(Badge.user_id).desc()).label("rank")).group_by(Badge.user_id).order_by=func.count(Badge.user_id).subquery()
|
||||||
users11 = g.db.query(User, sq.c.count).join(sq, User.id==sq.c.user_id).order_by(sq.c.count.desc())
|
users11 = g.db.query(User, sq.c.count).join(sq, User.id==sq.c.user_id).order_by(sq.c.count.desc())
|
||||||
pos11 = g.db.query(User.id, sq.c.rank, sq.c.count).join(sq, User.id==sq.c.user_id).filter(User.id == v.id).one_or_none()
|
pos11 = g.db.query(User.id, sq.c.rank, sq.c.count).join(sq, User.id==sq.c.user_id).filter(User.id == v.id).one_or_none()
|
||||||
if pos11: pos11 = (pos11[1],pos11[2])
|
if pos11: pos11 = (pos11[1],pos11[2])
|
||||||
|
|
|
@ -532,7 +532,7 @@
|
||||||
|
|
||||||
{% if not p.club or v and (v.paid_dues or v.id == p.author_id) %}
|
{% if not p.club or v and (v.paid_dues or v.id == p.author_id) %}
|
||||||
{% if p.realbody(v) %}
|
{% if p.realbody(v) %}
|
||||||
<div class="d-none card rounded border py-3 my-2 {% if p.author.agendaposter %}agendaposter{% endif %}" id="post-text-{{p.id}}">
|
<div class="d-none card rounded border pt-3 pb-2 my-2 {% if p.author.agendaposter %}agendaposter{% endif %}" id="post-text-{{p.id}}">
|
||||||
{{p.realbody(v) | safe}}
|
{{p.realbody(v) | safe}}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
|
|
||||||
<div id="urlblock">
|
<div id="urlblock">
|
||||||
<label for="URL" class="mt-3">URL</label>
|
<label for="URL" class="mt-3">URL</label>
|
||||||
<input autocomplete="off" class="form-control" id="post-URL" aria-describedby="URLHelp" name="url" placeholder="Optional if you have text." value="{{request.values.get('url','')}}" required oninput="checkForRequired();hide_image()">
|
<input autocomplete="off" class="form-control" id="post-URL" aria-describedby="URLHelp" name="url" placeholder="Optional if you have text." value="{{request.values.get('url','')}}" required oninput="checkForRequired();hide_image();autoSuggestTitle()">
|
||||||
<small class="form-text text-muted">To post an image, use a direct image link such as i.imgur.com</small>
|
<small class="form-text text-muted">To post an image, use a direct image link such as i.imgur.com</small>
|
||||||
</div>
|
</div>
|
||||||
<div id="image-upload-block">
|
<div id="image-upload-block">
|
||||||
|
@ -271,7 +271,7 @@
|
||||||
|
|
||||||
<script src="/static/assets/js/marked.js?a=242"></script>
|
<script src="/static/assets/js/marked.js?a=242"></script>
|
||||||
<script src="/static/assets/js/formatting.js?a=240"></script>
|
<script src="/static/assets/js/formatting.js?a=240"></script>
|
||||||
<script src="/static/assets/js/submit.js?a=243"></script>
|
<script src="/static/assets/js/submit.js?a=244"></script>
|
||||||
{% include "emoji_modal.html" %}
|
{% include "emoji_modal.html" %}
|
||||||
{% include "gif_modal.html" %}
|
{% include "gif_modal.html" %}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue