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