Merge branch 'frost' of https://github.com/Aevann1/rDrama into frost
commit
7316d8e827
|
@ -215,7 +215,7 @@ class Comment(Base):
|
|||
if not self.parent_submission: sort='old'
|
||||
|
||||
return sort_objects(sort, replies, Comment,
|
||||
include_shadowbanned=(not (v and v.can_see_shadowbanned)))
|
||||
include_shadowbanned=(not (v and v.can_see_shadowbanned))).all()
|
||||
|
||||
|
||||
@property
|
||||
|
|
|
@ -176,6 +176,7 @@ PERMS = { # Minimum admin_level to perform action.
|
|||
'USER_BLOCKS_VISIBLE': 0,
|
||||
'USER_FOLLOWS_VISIBLE': 0,
|
||||
'USER_VOTERS_VISIBLE': 0,
|
||||
'POST_COMMENT_INFINITE_PINGS': 1,
|
||||
'POST_COMMENT_MODERATION': 2,
|
||||
'POST_COMMENT_DISTINGUISH': 1,
|
||||
'POST_COMMENT_MODERATION_TOOLS_VISIBLE': 2, # note: does not affect API at all
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
from typing import Optional
|
||||
from files.classes import *
|
||||
from flask import g
|
||||
|
||||
def get_id(username, graceful=False):
|
||||
|
||||
def get_id(username, graceful=False) -> Optional[int]:
|
||||
username = username.replace('\\', '').replace('_', '\_').replace('%', '').strip()
|
||||
|
||||
user = g.db.query(
|
||||
User.id
|
||||
).filter(
|
||||
|
@ -21,13 +20,12 @@ def get_id(username, graceful=False):
|
|||
return user[0]
|
||||
|
||||
|
||||
def get_user(username, v=None, graceful=False, rendered=False, include_blocks=False, include_shadowbanned=True):
|
||||
def get_user(username, v=None, graceful=False, rendered=False, include_blocks=False, include_shadowbanned=True) -> Optional[User]:
|
||||
if not username:
|
||||
if not graceful: abort(404)
|
||||
else: return None
|
||||
|
||||
username = username.replace('\\', '').replace('_', '\_').replace('%', '').replace('(', '').replace(')', '').strip()
|
||||
|
||||
user = g.db.query(
|
||||
User
|
||||
).filter(
|
||||
|
@ -66,13 +64,11 @@ def get_user(username, v=None, graceful=False, rendered=False, include_blocks=Fa
|
|||
|
||||
return user
|
||||
|
||||
def get_users(usernames, graceful=False):
|
||||
|
||||
def get_users(usernames, graceful=False) -> list[User]:
|
||||
def clean(n):
|
||||
return n.replace('\\', '').replace('_', '\_').replace('%', '').strip()
|
||||
|
||||
usernames = [clean(n) for n in usernames]
|
||||
|
||||
users = g.db.query(User).filter(
|
||||
or_(
|
||||
User.username.ilike(any_(usernames)),
|
||||
|
@ -85,8 +81,7 @@ def get_users(usernames, graceful=False):
|
|||
|
||||
return users
|
||||
|
||||
def get_account(id, v=None, graceful=False, include_blocks=False, include_shadowbanned=True):
|
||||
|
||||
def get_account(id, v=None, graceful=False, include_blocks=False, include_shadowbanned=True) -> Optional[User]:
|
||||
try:
|
||||
id = int(id)
|
||||
except:
|
||||
|
@ -118,8 +113,7 @@ def get_account(id, v=None, graceful=False, include_blocks=False, include_shadow
|
|||
return user
|
||||
|
||||
|
||||
def get_post(i, v=None, graceful=False):
|
||||
|
||||
def get_post(i, v=None, graceful=False) -> Optional[Submission]:
|
||||
try: i = int(i)
|
||||
except: abort(404)
|
||||
|
||||
|
@ -167,8 +161,7 @@ def get_post(i, v=None, graceful=False):
|
|||
return x
|
||||
|
||||
|
||||
def get_posts(pids, v=None):
|
||||
|
||||
def get_posts(pids, v=None) -> list[Submission]:
|
||||
if not pids:
|
||||
return []
|
||||
|
||||
|
@ -210,8 +203,7 @@ def get_posts(pids, v=None):
|
|||
|
||||
return sorted(output, key=lambda x: pids.index(x.id))
|
||||
|
||||
def get_comment(i, v=None, graceful=False):
|
||||
|
||||
def get_comment(i, v=None, graceful=False) -> Optional[Comment]:
|
||||
try: i = int(i)
|
||||
except: abort(404)
|
||||
|
||||
|
@ -246,8 +238,7 @@ def get_comment(i, v=None, graceful=False):
|
|||
return comment
|
||||
|
||||
|
||||
def get_comments(cids, v=None, load_parent=False):
|
||||
|
||||
def get_comments(cids, v=None, load_parent=False) -> list[Comment]:
|
||||
if not cids: return []
|
||||
|
||||
if v:
|
||||
|
@ -295,7 +286,7 @@ def get_comments(cids, v=None, load_parent=False):
|
|||
|
||||
return sorted(output, key=lambda x: cids.index(x.id))
|
||||
|
||||
def get_sub_by_name(sub, v=None, graceful=False):
|
||||
def get_sub_by_name(sub, v=None, graceful=False) -> Optional[Sub]:
|
||||
if not sub:
|
||||
if graceful: return None
|
||||
else: abort(404)
|
||||
|
@ -309,8 +300,7 @@ def get_sub_by_name(sub, v=None, graceful=False):
|
|||
else: abort(404)
|
||||
return sub
|
||||
|
||||
def get_domain(s):
|
||||
|
||||
def get_domain(s) -> Optional[BannedDomain]:
|
||||
parts = s.split(".")
|
||||
domain_list = set()
|
||||
for i in range(len(parts)):
|
||||
|
|
|
@ -45,7 +45,7 @@ def process_audio(file):
|
|||
size = os.stat(name).st_size
|
||||
if size > MAX_IMAGE_AUDIO_SIZE_MB_PATRON * 1024 * 1024 or not g.v.patron and size > MAX_IMAGE_AUDIO_SIZE_MB * 1024 * 1024:
|
||||
os.remove(name)
|
||||
abort(413, f"Max image/audio size is {MAX_IMAGE_AUDIO_SIZE_MB} MB ({MAX_IMAGE_AUDIO_SIZE_MB_PATRON} MB for paypigs)")
|
||||
abort(413, f"Max image/audio size is {MAX_IMAGE_AUDIO_SIZE_MB} MB ({MAX_IMAGE_AUDIO_SIZE_MB_PATRON} MB for {patron.lower()}s)")
|
||||
|
||||
media = g.db.query(Media).filter_by(filename=name, kind='audio').one_or_none()
|
||||
if media: g.db.delete(media)
|
||||
|
|
|
@ -241,7 +241,7 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
|
|||
v = getattr(g, 'v', None)
|
||||
|
||||
names = set(m.group(2) for m in mention_regex.finditer(sanitized))
|
||||
if limit_pings and len(names) > limit_pings and not v.admin_level: abort(406)
|
||||
if limit_pings and len(names) > limit_pings and not v.admin_level >= PERMS['POST_COMMENT_INFINITE_PINGS']: abort(406)
|
||||
users_list = get_users(names, graceful=True)
|
||||
users_dict = {}
|
||||
for u in users_list:
|
||||
|
|
|
@ -313,7 +313,7 @@ def award_thing(v, thing_type, id):
|
|||
else: author.progressivestack = int(time.time()) + 21600
|
||||
badge_grant(user=author, badge_id=94)
|
||||
elif kind == "benefactor":
|
||||
if author.patron: abort(400, "This user is already a paypig!")
|
||||
if author.patron: abort(409, f"This user is already a {patron.lower()}!")
|
||||
author.patron = 1
|
||||
if author.patron_utc: author.patron_utc += 2629746
|
||||
else: author.patron_utc = int(time.time()) + 2629746
|
||||
|
|
|
@ -188,28 +188,26 @@ def comment(v):
|
|||
image = process_image(oldname, patron=v.patron)
|
||||
if image == "": abort(400, "Image upload failed")
|
||||
if v.admin_level >= PERMS['SITE_SETTINGS_SIDEBARS_BANNERS_BADGES'] and level == 1:
|
||||
if parent_post.id == SIDEBAR_THREAD:
|
||||
li = sorted(os.listdir(f'files/assets/images/{SITE_NAME}/sidebar'),
|
||||
def process_sidebar_or_banner(type, resize=0):
|
||||
li = sorted(os.listdir(f'files/assets/images/{SITE_NAME}/{type}'),
|
||||
key=lambda e: int(e.split('.webp')[0]))[-1]
|
||||
num = int(li.split('.webp')[0]) + 1
|
||||
filename = f'files/assets/images/{SITE_NAME}/sidebar/{num}.webp'
|
||||
filename = f'files/assets/images/{SITE_NAME}/{type}/{num}.webp'
|
||||
copyfile(oldname, filename)
|
||||
process_image(filename, resize=400)
|
||||
process_image(filename, resize=resize)
|
||||
|
||||
if parent_post.id == SIDEBAR_THREAD:
|
||||
process_sidebar_or_banner('sidebar', 400)
|
||||
elif parent_post.id == BANNER_THREAD:
|
||||
banner_width = 1200 if not SITE_NAME == 'PCM' else 0
|
||||
li = sorted(os.listdir(f'files/assets/images/{SITE_NAME}/banners'),
|
||||
key=lambda e: int(e.split('.webp')[0]))[-1]
|
||||
num = int(li.split('.webp')[0]) + 1
|
||||
filename = f'files/assets/images/{SITE_NAME}/banners/{num}.webp'
|
||||
copyfile(oldname, filename)
|
||||
process_image(filename, resize=banner_width)
|
||||
process_sidebar_or_banner('banners', banner_width)
|
||||
elif parent_post.id == BADGE_THREAD:
|
||||
try:
|
||||
badge_def = loads(body)
|
||||
name = badge_def["name"]
|
||||
|
||||
existing = g.db.query(BadgeDef).filter_by(name=name).one_or_none()
|
||||
if existing: abort(403, "A badge with this name already exists!")
|
||||
if existing: abort(409, "A badge with this name already exists!")
|
||||
|
||||
badge = BadgeDef(name=name, description=badge_def["description"])
|
||||
g.db.add(badge)
|
||||
|
|
Loading…
Reference in New Issue