MarseyWorld/files/routes/static.py

349 lines
10 KiB
Python
Raw Normal View History

2022-05-18 19:29:07 +00:00
import os
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from shutil import copyfile
from sqlalchemy import func, nullslast
from files.helpers.media import process_files
import files.helpers.stats as statshelper
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.classes.award import AWARDS
from files.classes.badges import Badge, BadgeDef
from files.classes.mod_logs import ModAction
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.classes.userblock import UserBlock
from files.helpers.actions import *
from files.helpers.alerts import *
from files.helpers.config.const import *
from files.helpers.config.modaction_types import MODACTION_TYPES, MODACTION_TYPES_FILTERED, MODACTION_PRIVILEGED_TYPES
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.routes.wrappers import *
from files.__main__ import app, cache, limiter
2022-05-04 23:09:46 +00:00
2022-05-04 23:09:46 +00:00
@app.get("/r/drama/comments/<id>/<title>")
@app.get("/r/Drama/comments/<id>/<title>")
def rdrama(id, title):
id = ''.join(f'{x}/' for x in id)
return redirect(f'/archives/drama/comments/{id}{title}.html')
2022-11-28 22:12:39 +00:00
@app.get("/r/<subreddit>")
@auth_desired
def subreddit(subreddit, v):
reddit = v.reddit if v else "old.reddit.com"
return redirect(f'https://{reddit}/r/{subreddit}')
2022-05-04 23:09:46 +00:00
@app.get("/reddit/<subreddit>/comments/<path:path>")
@app.get("/r/<subreddit>/comments/<path:path>")
@auth_desired
def reddit_post(subreddit, v, path):
post_id = path.rsplit("/", 1)[0].replace('/', '')
reddit = v.reddit if v else "old.reddit.com"
return redirect(f'https://{reddit}/{post_id}')
2022-05-04 23:09:46 +00:00
@app.get("/marseys")
@auth_required
2022-11-26 21:00:03 +00:00
def marseys(v:User):
marseys = get_marseys(g.db)
authors = get_accounts_dict([m.author_id for m in marseys], v=v, graceful=True, include_shadowbanned=False)
original = os.listdir("/asset_submissions/marseys/original")
for marsey in marseys:
marsey.user = authors.get(marsey.author_id)
for x in IMAGE_FORMATS:
if f'{marsey.name}.{x}' in original:
marsey.og = f'{marsey.name}.{x}'
break
2022-05-04 23:09:46 +00:00
return render_template("marseys.html", v=v, marseys=marseys)
@app.get("/emojis")
def emoji_list():
return jsonify(get_emojis(g.db))
@cache.cached(timeout=86400, key_prefix=MARSEYS_CACHE_KEY)
def get_marseys(db:scoped_session):
if not FEATURES['MARSEYS']: return []
marseys = []
for marsey, author in db.query(Marsey, User).join(User, Marsey.author_id == User.id).filter(Marsey.submitter_id == None).order_by(Marsey.count.desc()):
marsey.author = author.username if FEATURES['ASSET_SUBMISSIONS'] else None
setattr(marsey, "class", "Marsey")
marseys.append(marsey)
return marseys
@cache.cached(timeout=600, key_prefix=EMOJIS_CACHE_KEY)
def get_emojis(db:scoped_session):
emojis = [m.json() for m in get_marseys(db)]
2022-07-09 04:32:48 +00:00
for src in EMOJI_SRCS:
with open(src, "r", encoding="utf-8") as f:
emojis = emojis + json.load(f)
return emojis
2022-05-04 23:09:46 +00:00
@app.get('/sidebar')
@auth_desired
2022-11-26 21:00:03 +00:00
def sidebar(v:Optional[User]):
2022-05-04 23:09:46 +00:00
return render_template('sidebar.html', v=v)
2022-12-20 00:42:39 +00:00
@app.get("/stats")
@auth_required
def participation_stats(v:User):
2022-12-20 02:26:23 +00:00
stats = cache.get(f'{SITE}_stats') or {}
if v.client: return stats
return render_template("stats.html", v=v, title="Content Statistics", data=stats)
2022-05-04 23:09:46 +00:00
@app.get("/chart")
def chart():
return redirect('/weekly_chart')
@app.get("/weekly_chart")
@auth_required
2022-11-26 21:00:03 +00:00
def weekly_chart(v:User):
return send_file(statshelper.chart_path(kind="weekly", site=SITE))
2022-05-04 23:09:46 +00:00
@app.get("/daily_chart")
@auth_required
2022-11-26 21:00:03 +00:00
def daily_chart(v:User):
return send_file(statshelper.chart_path(kind="daily", site=SITE))
2022-05-04 23:09:46 +00:00
@app.get("/patrons")
@app.get("/paypigs")
2022-10-06 05:48:55 +00:00
@admin_level_required(PERMS['VIEW_PATRONS'])
2022-05-04 23:09:46 +00:00
def patrons(v):
2022-12-23 22:22:41 +00:00
if AEVANN_ID and v.id not in {AEVANN_ID, CARP_ID, SNAKES_ID}:
abort(404)
2022-09-17 22:06:29 +00:00
2022-05-04 23:09:46 +00:00
users = g.db.query(User).filter(User.patron > 0).order_by(User.patron.desc(), User.id).all()
2022-10-02 19:37:07 +00:00
return render_template("patrons.html", v=v, users=users, benefactor_def=AWARDS['benefactor'])
2022-05-04 23:09:46 +00:00
@app.get("/admins")
@app.get("/badmins")
@auth_required
2022-11-26 21:00:03 +00:00
def admins(v:User):
2022-11-26 01:15:39 +00:00
admins = g.db.query(User).filter(User.admin_level >= PERMS['ADMIN_MOP_VISIBLE']).order_by(User.truescore.desc()).all()
2022-05-04 23:09:46 +00:00
return render_template("admins.html", v=v, admins=admins)
@app.get("/log")
@app.get("/modlog")
@auth_required
2022-11-26 21:00:03 +00:00
def log(v:User):
2022-05-04 23:09:46 +00:00
try: page = max(int(request.values.get("page", 1)), 1)
except: page = 1
admin = request.values.get("admin")
2022-10-01 05:15:56 +00:00
if admin: admin_id = get_id(admin)
2022-05-04 23:09:46 +00:00
else: admin_id = 0
kind = request.values.get("kind")
if v and v.admin_level >= PERMS['USER_SHADOWBAN']: types = MODACTION_TYPES
else: types = MODACTION_TYPES_FILTERED
2022-05-04 23:09:46 +00:00
if kind and kind not in types:
kind = None
actions = []
else:
actions = g.db.query(ModAction)
2022-10-06 02:24:37 +00:00
if not (v and v.admin_level >= PERMS['USER_SHADOWBAN']):
actions = actions.filter(ModAction.kind.notin_(MODACTION_PRIVILEGED_TYPES))
if admin_id:
actions = actions.filter_by(user_id=admin_id)
kinds = set([x.kind for x in actions])
kinds.add(kind)
types2 = {}
for k,val in types.items():
if k in kinds: types2[k] = val
types = types2
if kind: actions = actions.filter_by(kind=kind)
actions = actions.order_by(ModAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE+1).all()
next_exists=len(actions) > PAGE_SIZE
actions=actions[:PAGE_SIZE]
admins = [x[0] for x in g.db.query(User.username).filter(User.admin_level >= PERMS['ADMIN_MOP_VISIBLE']).order_by(User.username).all()]
2022-05-04 23:09:46 +00:00
2022-11-04 23:51:42 +00:00
return render_template("log.html", v=v, admins=admins, types=types, admin=admin, type=kind, actions=actions, next_exists=next_exists, page=page, single_user_url='admin')
2022-05-04 23:09:46 +00:00
@app.get("/log/<id>")
@auth_required
def log_item(id, v):
try: id = int(id)
except: abort(404)
action=g.db.get(ModAction, id)
2022-05-04 23:09:46 +00:00
if not action: abort(404)
admins = [x[0] for x in g.db.query(User.username).filter(User.admin_level >= PERMS['ADMIN_MOP_VISIBLE']).all()]
2022-05-04 23:09:46 +00:00
if v and v.admin_level >= PERMS['USER_SHADOWBAN']: types = MODACTION_TYPES
else: types = MODACTION_TYPES_FILTERED
2022-05-04 23:09:46 +00:00
2022-11-04 23:51:42 +00:00
return render_template("log.html", v=v, actions=[action], next_exists=False, page=1, action=action, admins=admins, types=types, single_user_url='admin')
2022-05-04 23:09:46 +00:00
@app.get("/directory")
@auth_required
2022-11-26 21:00:03 +00:00
def static_megathread_index(v:User):
return render_template("megathread_index.html", v=v)
2022-05-04 23:09:46 +00:00
2022-11-26 21:04:39 +00:00
@app.get("/api")
@auth_required
def api(v):
return render_template("api.html", v=v)
2022-05-04 23:09:46 +00:00
@app.get("/contact")
2022-09-09 09:13:50 +00:00
@app.get("/contactus")
@app.get("/contact_us")
2022-05-04 23:09:46 +00:00
@app.get("/press")
@app.get("/media")
@auth_desired
2022-11-26 21:00:03 +00:00
def contact(v:Optional[User]):
2022-05-04 23:09:46 +00:00
return render_template("contact.html", v=v)
@app.post("/send_admin")
2022-11-13 02:37:33 +00:00
@limiter.limit("1/second;1/2 minutes;10/day")
2022-05-04 23:09:46 +00:00
@auth_required
2022-11-25 23:37:04 +00:00
@ratelimit_user("1/second;1/2 minutes;10/day")
2022-05-04 23:09:46 +00:00
def submit_contact(v):
body = request.values.get("message")
if not body: abort(400)
if v.is_muted:
abort(403)
body = f'This message has been sent automatically to all admins via [/contact](/contact)\n\nMessage:\n\n{body}'
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
body += process_files(request.files, v)
body = body.strip()
body_html = sanitize(body)
2022-05-04 23:09:46 +00:00
2022-11-14 03:48:52 +00:00
execute_antispam_duplicate_comment_check(v, body_html)
2022-11-13 02:48:33 +00:00
2022-05-04 23:09:46 +00:00
new_comment = Comment(author_id=v.id,
2022-09-04 23:15:37 +00:00
parent_submission=None,
level=1,
body_html=body_html,
sentto=MODMAIL_ID
2022-09-04 23:15:37 +00:00
)
2022-05-04 23:09:46 +00:00
g.db.add(new_comment)
g.db.flush()
2022-11-14 02:43:26 +00:00
execute_blackjack(v, new_comment, new_comment.body_html, 'modmail')
2022-11-30 17:37:35 +00:00
execute_under_siege(v, new_comment, new_comment.body_html, 'modmail')
2022-05-04 23:09:46 +00:00
new_comment.top_comment_id = new_comment.id
admins = g.db.query(User).filter(User.admin_level >= PERMS['NOTIFICATIONS_MODMAIL'], User.id != AEVANN_ID)
2022-09-21 19:38:29 +00:00
for admin in admins.all():
2022-05-04 23:09:46 +00:00
notif = Notification(comment_id=new_comment.id, user_id=admin.id)
g.db.add(notif)
2022-09-12 05:23:08 +00:00
return render_template("contact.html", v=v, msg="Your message has been sent to the admins!")
2022-05-04 23:09:46 +00:00
@app.get('/archives')
def archivesindex():
return redirect("/archives/index.html")
no = (21,22,23,24,25,26,27)
@cache.memoize(timeout=3600)
def badge_list(site):
badges = g.db.query(BadgeDef).filter(BadgeDef.id.notin_(no)).order_by(BadgeDef.id).all()
counts_raw = g.db.query(Badge.badge_id, func.count()).group_by(Badge.badge_id).all()
2022-05-09 11:21:49 +00:00
users = g.db.query(User).count()
2022-05-04 23:09:46 +00:00
counts = {}
for c in counts_raw:
counts[c[0]] = (c[1], float(c[1]) * 100 / max(users, 1))
return badges, counts
@app.get("/badges")
2022-10-11 07:29:24 +00:00
@feature_required('BADGES')
2022-11-14 15:11:05 +00:00
@auth_required
2022-11-26 21:00:03 +00:00
def badges(v:User):
2022-05-04 23:09:46 +00:00
badges, counts = badge_list(SITE)
return render_template("badges.html", v=v, badges=badges, counts=counts)
@app.get("/blocks")
@admin_level_required(PERMS['USER_BLOCKS_VISIBLE'])
2022-05-04 23:09:46 +00:00
def blocks(v):
blocks=g.db.query(UserBlock).all()
users = []
targets = []
for x in blocks:
acc_user = get_account(x.user_id)
2022-09-04 23:15:37 +00:00
acc_tgt = get_account(x.target_id)
if acc_user.shadowbanned or acc_tgt.shadowbanned: continue
users.append(acc_user)
targets.append(acc_tgt)
2022-05-04 23:09:46 +00:00
return render_template("blocks.html", v=v, users=users, targets=targets)
@app.get("/formatting")
@auth_required
2022-11-26 21:00:03 +00:00
def formatting(v:User):
2022-05-04 23:09:46 +00:00
return render_template("formatting.html", v=v)
@app.get("/app")
@auth_desired
2022-11-26 21:00:03 +00:00
def mobile_app(v:Optional[User]):
return render_template("app.html", v=v)
2022-05-04 23:09:46 +00:00
@app.post("/dismiss_mobile_tip")
def dismiss_mobile_tip():
session["tooltip_last_dismissed"] = int(time.time())
return "", 204
@app.get("/transfers/<id>")
@auth_required
def transfers_id(id, v):
try: id = int(id)
except: abort(404)
transfer = g.db.get(Comment, id)
if not transfer: abort(404)
return render_template("transfers.html", v=v, page=1, comments=[transfer], standalone=True, next_exists=False)
@app.get("/transfers")
@auth_required
2022-11-26 21:00:03 +00:00
def transfers(v:User):
comments = g.db.query(Comment).filter(Comment.author_id == AUTOJANNY_ID, Comment.parent_submission == None, Comment.body_html.like("%</a> has transferred %")).order_by(Comment.id.desc())
try: page = max(int(request.values.get("page", 1)), 1)
except: page = 1
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all()
next_exists = len(comments) > PAGE_SIZE
comments = comments[:PAGE_SIZE]
if v.client:
2022-11-15 09:28:39 +00:00
return {"data": [x.json(g.db) for x in comments]}
else:
return render_template("transfers.html", v=v, page=page, comments=comments, standalone=True, next_exists=next_exists)
2022-09-19 23:59:24 +00:00
if not os.path.exists(f'files/templates/donate_{SITE_NAME}.html'):
copyfile('files/templates/donate_rDrama.html', f'files/templates/donate_{SITE_NAME}.html')
2022-09-19 23:59:24 +00:00
@app.get('/donate')
2022-10-30 18:43:06 +00:00
@auth_desired_with_logingate
2022-09-19 23:59:24 +00:00
def donate(v):
return render_template(f'donate_{SITE_NAME}.html', v=v)
2022-12-27 01:22:39 +00:00
2022-12-28 10:25:52 +00:00
items_we_want = ('blocked-uri', 'document-uri', 'effective-directive', 'source-file', 'violated-directive')
2022-12-27 01:22:39 +00:00
@app.post('/csp_violations')
@limiter.limit("10/minute;50/day")
def csp_violations():
2022-12-28 10:25:52 +00:00
content = json.dumps(request.get_json())
if content["source-file"].startswith(SITE_FULL):
print('--------', flush=True)
for i in items_we_want:
print(f"{i}: {content['i']}")
2022-12-27 01:22:39 +00:00
return ''