rDrama/files/routes/subs.py

767 lines
19 KiB
Python
Raw Normal View History

[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 sqlalchemy import nullslast
from files.classes import *
2022-02-10 20:35:16 +00:00
from files.helpers.alerts import *
2022-06-24 13:19:53 +00:00
from files.helpers.get import *
from files.helpers.regex import *
[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 *
2022-02-10 20:35:16 +00:00
from .front import frontlist
[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.__main__ import app, cache, limiter
2022-02-14 01:22:26 +00:00
2022-02-16 04:33:13 +00:00
@app.post("/exile/post/<pid>")
@is_not_permabanned
def exile_post(v, pid):
if v.shadowbanned: return {"error": "Internal Server Error"}, 500
2022-02-16 04:33:13 +00:00
p = get_post(pid)
sub = p.sub
if not sub: abort(400)
if not v.mods(sub): abort(403)
u = p.author
2022-03-05 19:46:47 +00:00
if u.mods(sub): abort(403)
2022-08-20 20:24:20 +00:00
if not u.exiled_from(sub):
2022-02-22 12:39:02 +00:00
exile = Exile(user_id=u.id, sub=sub, exiler_id=v.id)
2022-02-16 04:33:13 +00:00
g.db.add(exile)
2022-03-09 02:04:37 +00:00
send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{p.title}]({p.shortlink})")
2022-02-16 04:33:13 +00:00
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub,
2022-09-29 09:39:37 +00:00
kind='exile_user',
user_id=v.id,
target_user_id=u.id,
_note=f'for <a href="{p.permalink}">{p.title_html}</a>'
)
g.db.add(ma)
2022-02-16 04:33:13 +00:00
return {"message": f"@{u.username} has been exiled from /h/{sub} successfully!"}
2022-02-16 04:33:13 +00:00
@app.post("/exile/comment/<cid>")
@is_not_permabanned
def exile_comment(v, cid):
if v.shadowbanned: return {"error": "Internal Server Error"}, 500
2022-02-16 04:33:13 +00:00
c = get_comment(cid)
sub = c.post.sub
if not sub: abort(400)
if not v.mods(sub): abort(403)
u = c.author
2022-11-03 19:23:37 +00:00
if u.mods(sub): abort(403)
2022-03-05 19:46:47 +00:00
2022-08-20 20:24:20 +00:00
if not u.exiled_from(sub):
2022-02-22 12:39:02 +00:00
exile = Exile(user_id=u.id, sub=sub, exiler_id=v.id)
2022-02-16 04:33:13 +00:00
g.db.add(exile)
2022-03-09 02:04:37 +00:00
send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{c.permalink}]({c.shortlink})")
2022-02-16 04:33:13 +00:00
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub,
2022-09-29 09:39:37 +00:00
kind='exile_user',
user_id=v.id,
target_user_id=u.id,
_note=f'for <a href="/comment/{c.id}?context=8#context">comment</a>'
)
g.db.add(ma)
return {"message": f"@{u.username} has been exiled from /h/{sub} successfully!"}
2022-02-16 04:33:13 +00:00
2022-03-09 02:04:37 +00:00
@app.post("/h/<sub>/unexile/<uid>")
2022-02-16 04:33:13 +00:00
@is_not_permabanned
2022-03-09 01:44:53 +00:00
def unexile(v, sub, uid):
u = get_account(uid)
2022-02-16 04:33:13 +00:00
if not v.mods(sub): abort(403)
if v.shadowbanned: return redirect(f'/h/{sub}/exilees')
2022-02-16 04:33:13 +00:00
if u.exiled_from(sub):
exile = g.db.query(Exile).filter_by(user_id=u.id, sub=sub).one_or_none()
g.db.delete(exile)
2022-03-09 02:04:37 +00:00
send_notification(u.id, f"@{v.username} has revoked your exile from /h/{sub}")
2022-02-16 04:33:13 +00:00
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub,
2022-09-29 09:39:37 +00:00
kind='unexile_user',
user_id=v.id,
target_user_id=u.id
)
g.db.add(ma)
2022-03-09 01:44:53 +00:00
if g.is_api_or_xhr:
return {"message": f"@{u.username} has been unexiled from /h/{sub} successfully!"}
2022-03-09 02:04:37 +00:00
return redirect(f'/h/{sub}/exilees')
2022-03-09 01:44:53 +00:00
2022-02-16 04:33:13 +00:00
2022-03-09 02:04:37 +00:00
@app.post("/h/<sub>/block")
2022-02-14 01:22:26 +00:00
@auth_required
2022-11-26 21:00:03 +00:00
def block_sub(v:User, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub).name
2022-02-14 01:22:26 +00:00
existing = g.db.query(SubBlock).filter_by(user_id=v.id, sub=sub).one_or_none()
if not existing:
block = SubBlock(user_id=v.id, sub=sub)
g.db.add(block)
cache.delete_memoized(frontlist)
return {"message": f"/h/{sub} blocked successfully!"}
2022-02-14 01:22:26 +00:00
2022-03-09 02:04:37 +00:00
@app.post("/h/<sub>/unblock")
2022-02-14 01:22:26 +00:00
@auth_required
2022-11-26 21:00:03 +00:00
def unblock_sub(v:User, sub):
sub = get_sub_by_name(sub)
if not User.can_see(v, sub):
abort(403)
block = g.db.query(SubBlock).filter_by(user_id=v.id, sub=sub.name).one_or_none()
2022-02-14 01:22:26 +00:00
if block:
g.db.delete(block)
cache.delete_memoized(frontlist)
return {"message": f"/h/{sub.name} unblocked successfully!"}
@app.post("/h/<sub>/subscribe")
@auth_required
2022-11-26 21:00:03 +00:00
def subscribe_sub(v:User, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub).name
existing = g.db.query(SubJoin).filter_by(user_id=v.id, sub=sub).one_or_none()
if not existing:
subscribe = SubJoin(user_id=v.id, sub=sub)
g.db.add(subscribe)
cache.delete_memoized(frontlist)
return {"message": f"/h/{sub} unblocked successfully!"}
@app.post("/h/<sub>/unsubscribe")
@auth_required
2022-11-26 21:00:03 +00:00
def unsubscribe_sub(v:User, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub).name
subscribe = g.db.query(SubJoin).filter_by(user_id=v.id, sub=sub).one_or_none()
if subscribe:
g.db.delete(subscribe)
cache.delete_memoized(frontlist)
return {"message": f"/h/{sub} blocked successfully!"}
2022-02-14 01:22:26 +00:00
2022-06-09 20:24:24 +00:00
@app.post("/h/<sub>/follow")
@auth_required
2022-11-26 21:00:03 +00:00
def follow_sub(v:User, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
if not User.can_see(v, sub):
abort(403)
existing = g.db.query(SubSubscription).filter_by(user_id=v.id, sub=sub.name).one_or_none()
2022-06-09 20:24:24 +00:00
if not existing:
subscription = SubSubscription(user_id=v.id, sub=sub.name)
g.db.add(subscription)
cache.delete_memoized(frontlist)
2022-06-09 20:24:24 +00:00
return {"message": f"/h/{sub} followed successfully!"}
2022-06-09 20:24:24 +00:00
@app.post("/h/<sub>/unfollow")
@auth_required
2022-11-26 21:00:03 +00:00
def unfollow_sub(v:User, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
subscription = g.db.query(SubSubscription).filter_by(user_id=v.id, sub=sub.name).one_or_none()
2022-06-09 20:24:24 +00:00
if subscription:
g.db.delete(subscription)
cache.delete_memoized(frontlist)
2022-06-09 20:24:24 +00:00
return {"message": f"/h/{sub} unfollowed successfully!"}
2022-06-09 20:24:24 +00:00
2022-03-09 02:04:37 +00:00
@app.get("/h/<sub>/mods")
2022-02-21 06:45:01 +00:00
@auth_required
2022-11-26 21:00:03 +00:00
def mods(v:User, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
if not User.can_see(v, sub):
abort(403)
2022-07-03 06:12:53 +00:00
users = g.db.query(User, Mod).join(Mod).filter_by(sub=sub.name).order_by(Mod.created_utc).all()
2022-02-11 23:32:14 +00:00
2022-02-10 20:35:16 +00:00
return render_template("sub/mods.html", v=v, sub=sub, users=users)
2022-03-09 02:04:37 +00:00
@app.get("/h/<sub>/exilees")
2022-02-21 06:45:01 +00:00
@auth_required
2022-11-26 21:00:03 +00:00
def sub_exilees(v:User, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
if not User.can_see(v, sub):
abort(403)
users = g.db.query(User, Exile).join(Exile, Exile.user_id==User.id) \
.filter_by(sub=sub.name) \
.order_by(nullslast(Exile.created_utc.desc()), User.username).all()
2022-02-21 06:45:01 +00:00
return render_template("sub/exilees.html", v=v, sub=sub, users=users)
2022-03-09 02:04:37 +00:00
@app.get("/h/<sub>/blockers")
2022-02-21 06:45:01 +00:00
@auth_required
2022-11-26 21:00:03 +00:00
def sub_blockers(v:User, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
if not User.can_see(v, sub):
abort(403)
users = g.db.query(User, SubBlock).join(SubBlock) \
.filter_by(sub=sub.name) \
.order_by(nullslast(SubBlock.created_utc.desc()), User.username).all()
2022-02-21 06:45:01 +00:00
2022-06-09 20:24:24 +00:00
return render_template("sub/blockers.html",
v=v, sub=sub, users=users, verb="blocking")
2022-06-09 20:24:24 +00:00
@app.get("/h/<sub>/followers")
@auth_required
2022-11-26 21:00:03 +00:00
def sub_followers(v:User, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
if not User.can_see(v, sub):
abort(403)
users = g.db.query(User, SubSubscription).join(SubSubscription) \
.filter_by(sub=sub.name) \
.order_by(nullslast(SubSubscription.created_utc.desc()), User.username).all()
2022-02-21 06:45:01 +00:00
2022-06-09 20:24:24 +00:00
return render_template("sub/blockers.html",
v=v, sub=sub, users=users, verb="following")
2022-02-21 06:45:01 +00:00
2022-03-09 02:04:37 +00:00
@app.post("/h/<sub>/add_mod")
2022-09-06 02:40:46 +00:00
@limiter.limit("1/second;30/day")
2022-02-11 15:02:27 +00:00
@is_not_permabanned
2022-11-25 23:37:04 +00:00
@ratelimit_user("1/second;30/day")
2022-02-10 20:35:16 +00:00
def add_mod(v, sub):
2022-09-01 23:54:05 +00:00
if SITE_NAME == 'WPD': abort(403)
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub).name
2022-02-10 20:35:16 +00:00
if not v.mods(sub): abort(403)
if v.shadowbanned: return redirect(f'/h/{sub}/mods')
2022-02-10 20:35:16 +00:00
user = request.values.get('user')
if not user: abort(400)
user = get_user(user, v=v, include_shadowbanned=False)
2022-02-10 20:35:16 +00:00
2022-09-11 01:53:16 +00:00
if sub in ('furry','vampire','racist','femboy') and not v.client and not user.house.lower().startswith(sub):
abort(403, f"@{user.username} needs to be a member of House {sub.capitalize()} to be added as a mod there!")
2022-02-11 23:32:14 +00:00
existing = g.db.query(Mod).filter_by(user_id=user.id, sub=sub).one_or_none()
if not existing:
2022-02-14 21:07:31 +00:00
mod = Mod(user_id=user.id, sub=sub)
2022-02-11 23:32:14 +00:00
g.db.add(mod)
2022-03-02 04:27:53 +00:00
if v.id != user.id:
2022-03-09 02:04:37 +00:00
send_repeatable_notification(user.id, f"@{v.username} has added you as a mod to /h/{sub}")
2022-02-11 23:32:14 +00:00
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub,
2022-09-29 09:39:37 +00:00
kind='make_mod',
user_id=v.id,
target_user_id=user.id
)
g.db.add(ma)
2022-03-09 02:04:37 +00:00
return redirect(f'/h/{sub}/mods')
2022-02-11 23:32:14 +00:00
2022-03-09 02:04:37 +00:00
@app.post("/h/<sub>/remove_mod")
2022-02-11 23:32:14 +00:00
@is_not_permabanned
def remove_mod(v, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub).name
2022-02-11 23:32:14 +00:00
if not v.mods(sub): abort(403)
2022-11-07 06:41:23 +00:00
if v.shadowbanned: abort(500)
2022-02-11 23:32:14 +00:00
uid = request.values.get('uid')
if not uid: abort(400)
try: uid = int(uid)
except: abort(400)
2022-06-24 13:19:53 +00:00
user = get_account(uid)
2022-02-12 19:33:34 +00:00
if not user: abort(404)
mod = g.db.query(Mod).filter_by(user_id=user.id, sub=sub).one_or_none()
2022-02-11 23:32:14 +00:00
if not mod: abort(400)
2022-02-25 12:46:33 +00:00
if not (v.id == user.id or v.mod_date(sub) and v.mod_date(sub) < mod.created_utc): abort(403)
2022-02-12 19:33:34 +00:00
2022-02-11 23:32:14 +00:00
g.db.delete(mod)
2022-02-10 20:35:16 +00:00
2022-03-02 04:27:53 +00:00
if v.id != user.id:
2022-03-09 02:04:37 +00:00
send_repeatable_notification(user.id, f"@{v.username} has removed you as a mod from /h/{sub}")
2022-02-10 20:35:16 +00:00
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub,
2022-09-29 09:39:37 +00:00
kind='remove_mod',
user_id=v.id,
target_user_id=user.id
)
g.db.add(ma)
2022-11-07 06:32:30 +00:00
return {"message": f"@{user.username} has been removed as a mod!"}
2022-02-10 20:35:16 +00:00
2022-06-09 22:29:45 +00:00
@app.get("/create_hole")
2022-05-09 02:16:28 +00:00
@is_not_permabanned
def create_sub(v):
2022-06-21 05:20:21 +00:00
if not v.can_create_hole:
abort(403)
2022-03-01 21:19:51 +00:00
2022-06-21 05:20:21 +00:00
return render_template("sub/create_hole.html", v=v, cost=HOLE_COST)
2022-03-01 21:19:51 +00:00
2022-06-09 22:29:45 +00:00
@app.post("/create_hole")
2022-03-02 04:24:36 +00:00
@is_not_permabanned
def create_sub2(v):
2022-06-21 05:20:21 +00:00
if not v.can_create_hole:
abort(403)
2022-03-02 04:24:36 +00:00
name = request.values.get('name')
if not name: abort(400)
name = name.strip().lower()
2022-03-01 21:19:51 +00:00
2022-03-02 04:24:36 +00:00
if not valid_sub_regex.fullmatch(name):
2022-07-13 09:13:42 +00:00
return render_template("sub/create_hole.html", v=v, cost=HOLE_COST, error=f"{HOLE_NAME.capitalize()} name not allowed."), 400
2022-03-01 21:19:51 +00:00
sub = get_sub_by_name(name, graceful=True)
2022-03-02 04:24:36 +00:00
if not sub:
2022-11-01 05:25:19 +00:00
if not v.charge_account('coins', HOLE_COST):
return render_template("sub/create_hole.html", v=v, cost=HOLE_COST, error="You don't have enough coins!"), 403
2022-03-01 21:19:51 +00:00
2022-03-02 04:24:36 +00:00
g.db.add(v)
if v.shadowbanned: return {"error": "Internal Server Error"}, 500
2022-03-02 04:24:36 +00:00
sub = Sub(name=name)
g.db.add(sub)
g.db.flush()
2022-03-02 04:24:36 +00:00
mod = Mod(user_id=v.id, sub=sub.name)
g.db.add(mod)
2022-03-01 21:19:51 +00:00
admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_HOLE_CREATION'], User.id != v.id).all()]
2022-08-11 13:25:56 +00:00
for admin in admins:
send_repeatable_notification(admin, f":!marseyparty: /h/{sub} has been created by @{v.username} :marseyparty:")
2022-08-11 13:25:56 +00:00
return redirect(f'/h/{sub}')
2022-02-10 20:35:16 +00:00
@app.post("/kick/<pid>")
2022-02-11 15:02:27 +00:00
@is_not_permabanned
2022-02-10 20:35:16 +00:00
def kick(v, pid):
post = get_post(pid)
if not post.sub: abort(403)
if not v.mods(post.sub): abort(403)
if v.shadowbanned: return {"error": "Internal Server Error"}, 500
2022-02-10 20:35:16 +00:00
old = post.sub
2022-03-06 19:13:11 +00:00
post.sub = None
2022-11-18 19:58:12 +00:00
post.hole_pinned = None
2022-11-03 19:23:37 +00:00
ma = SubAction(
sub=old,
kind='kick_post',
user_id=v.id,
target_submission_id=post.id
)
g.db.add(ma)
2022-09-29 06:05:42 +00:00
if v.id != post.author_id:
message = f"@{v.username} (/h/{old} Mod) has moved [{post.title}]({post.shortlink}) from /h/{old} to the main feed!"
2022-09-29 06:05:42 +00:00
send_repeatable_notification(post.author_id, message)
2022-02-10 20:35:16 +00:00
g.db.add(post)
cache.delete_memoized(frontlist)
return {"message": f"Post kicked from /h/{old} successfully!"}
2022-02-10 20:35:16 +00:00
2022-03-09 02:04:37 +00:00
@app.get('/h/<sub>/settings')
2022-02-11 15:02:27 +00:00
@is_not_permabanned
2022-02-10 20:35:16 +00:00
def sub_settings(v, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
2022-02-10 20:35:16 +00:00
if not v.mods(sub.name): abort(403)
return render_template('sub/settings.html', v=v, sidebar=sub.sidebar, sub=sub)
2022-03-09 02:04:37 +00:00
@app.post('/h/<sub>/sidebar')
@limiter.limit(DEFAULT_RATELIMIT_SLOWER)
2022-02-11 15:02:27 +00:00
@is_not_permabanned
@ratelimit_user()
2022-02-10 20:35:16 +00:00
def post_sub_sidebar(v, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
2022-02-10 20:35:16 +00:00
if not v.mods(sub.name): abort(403)
if v.shadowbanned: return redirect(f'/h/{sub}/settings')
2022-02-10 20:35:16 +00:00
sub.sidebar = request.values.get('sidebar', '').strip()[:10000]
2022-02-10 20:35:16 +00:00
sub.sidebar_html = sanitize(sub.sidebar)
if len(sub.sidebar_html) > 20000: abort(400, "Sidebar is too big!")
2022-02-11 23:32:14 +00:00
2022-02-10 20:35:16 +00:00
g.db.add(sub)
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub.name,
kind='edit_sidebar',
2022-09-29 09:39:37 +00:00
user_id=v.id
)
g.db.add(ma)
2022-02-11 23:32:14 +00:00
return redirect(f'/h/{sub}/settings')
2022-02-11 23:32:14 +00:00
2022-03-09 02:04:37 +00:00
@app.post('/h/<sub>/css')
@limiter.limit(DEFAULT_RATELIMIT_SLOWER)
2022-02-11 23:32:14 +00:00
@is_not_permabanned
@ratelimit_user()
2022-02-11 23:32:14 +00:00
def post_sub_css(v, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
2022-05-03 19:07:15 +00:00
css = request.values.get('css', '').strip()
2022-08-12 23:07:49 +00:00
if not sub: abort(404)
if not v.mods(sub.name): abort(403)
if v.shadowbanned: return redirect(f'/h/{sub}/settings')
2022-08-12 23:07:49 +00:00
if len(css) > 6000:
error = "CSS is too long (max 6000 characters)"
return render_template('sub/settings.html', v=v, sidebar=sub.sidebar, sub=sub, error=error)
2022-05-03 19:07:15 +00:00
valid, error = validate_css(css)
if not valid:
2022-08-12 23:07:49 +00:00
return render_template('sub/settings.html', v=v, sidebar=sub.sidebar, sub=sub, error=error)
2022-05-03 19:07:15 +00:00
sub.css = css
2022-02-11 23:32:14 +00:00
g.db.add(sub)
2022-02-10 20:35:16 +00:00
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub.name,
kind='edit_css',
2022-09-29 09:39:37 +00:00
user_id=v.id
)
g.db.add(ma)
return redirect(f'/h/{sub}/settings')
2022-02-10 20:35:16 +00:00
@app.get("/h/<sub>/css")
def get_sub_css(sub):
2022-06-26 05:26:45 +00:00
sub = g.db.query(Sub.css).filter_by(name=sub.strip().lower()).one_or_none()
if not sub: abort(404)
resp=make_response(sub.css or "")
resp.headers.add("Content-Type", "text/css")
return resp
2022-03-09 02:04:37 +00:00
@app.post("/h/<sub>/banner")
2022-02-12 18:21:40 +00:00
@limiter.limit("1/second;10/day")
2022-02-11 15:02:27 +00:00
@is_not_permabanned
2022-11-25 23:37:04 +00:00
@ratelimit_user("1/second;10/day")
2022-02-10 20:35:16 +00:00
def sub_banner(v, sub):
[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
if g.is_tor: abort(403, "Image uploads are not allowed through TOR.")
2022-02-10 20:35:16 +00:00
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
2022-02-10 20:35:16 +00:00
if not v.mods(sub.name): abort(403)
if v.shadowbanned: return redirect(f'/h/{sub}/settings')
2022-02-10 20:35:16 +00:00
file = request.files["banner"]
2022-03-25 22:30:15 +00:00
name = f'/images/{time.time()}'.replace('.','') + '.webp'
2022-02-10 20:35:16 +00:00
file.save(name)
[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
bannerurl = process_image(name, v, resize=1200)
2022-02-10 20:35:16 +00:00
if bannerurl:
if sub.bannerurl and '/images/' in sub.bannerurl:
fpath = '/images/' + sub.bannerurl.split('/images/')[1]
if path.isfile(fpath): os.remove(fpath)
sub.bannerurl = bannerurl
g.db.add(sub)
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub.name,
2022-09-29 09:39:37 +00:00
kind='change_banner',
user_id=v.id
)
g.db.add(ma)
return redirect(f'/h/{sub}/settings')
2022-02-10 20:35:16 +00:00
2022-03-09 02:04:37 +00:00
@app.post("/h/<sub>/sidebar_image")
2022-02-12 18:21:40 +00:00
@limiter.limit("1/second;10/day")
2022-02-11 15:02:27 +00:00
@is_not_permabanned
2022-11-25 23:37:04 +00:00
@ratelimit_user("1/second;10/day")
2022-02-10 20:35:16 +00:00
def sub_sidebar(v, sub):
[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
if g.is_tor: abort(403, "Image uploads are not allowed through TOR.")
2022-02-10 20:35:16 +00:00
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
2022-02-10 20:35:16 +00:00
if not v.mods(sub.name): abort(403)
if v.shadowbanned: return redirect(f'/h/{sub}/settings')
2022-02-10 20:35:16 +00:00
file = request.files["sidebar"]
2022-03-25 22:30:15 +00:00
name = f'/images/{time.time()}'.replace('.','') + '.webp'
2022-02-10 20:35:16 +00:00
file.save(name)
[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
sidebarurl = process_image(name, v, resize=400)
2022-02-10 20:35:16 +00:00
if sidebarurl:
if sub.sidebarurl and '/images/' in sub.sidebarurl:
fpath = '/images/' + sub.sidebarurl.split('/images/')[1]
if path.isfile(fpath): os.remove(fpath)
sub.sidebarurl = sidebarurl
g.db.add(sub)
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub.name,
2022-09-29 09:39:37 +00:00
kind='change_sidebar_image',
user_id=v.id
)
g.db.add(ma)
return redirect(f'/h/{sub}/settings')
2022-02-24 12:03:28 +00:00
@app.post("/h/<sub>/marsey_image")
@limiter.limit("1/second;10/day")
@is_not_permabanned
2022-11-25 23:37:04 +00:00
@ratelimit_user("1/second;10/day")
def sub_marsey(v, sub):
[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
if g.is_tor: abort(403, "Image uploads are not allowed through TOR.")
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
if not v.mods(sub.name): abort(403)
if v.shadowbanned: return redirect(f'/h/{sub}/settings')
file = request.files["marsey"]
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
[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
marseyurl = process_image(name, v, resize=200)
if marseyurl:
if sub.marseyurl and '/images/' in sub.marseyurl:
fpath = '/images/' + sub.marseyurl.split('/images/')[1]
if path.isfile(fpath): os.remove(fpath)
sub.marseyurl = marseyurl
g.db.add(sub)
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub.name,
2022-09-29 09:39:37 +00:00
kind='change_marsey',
user_id=v.id
)
g.db.add(ma)
return redirect(f'/h/{sub}/settings')
2022-03-09 02:04:37 +00:00
@app.get("/holes")
@auth_required
2022-11-26 21:00:03 +00:00
def subs(v:User):
2022-03-06 01:59:45 +00:00
subs = g.db.query(Sub, func.count(Submission.sub)).outerjoin(Submission, Sub.name == Submission.sub).group_by(Sub.name).order_by(func.count(Submission.sub).desc()).all()
total_users = g.db.query(User).count()
return render_template('sub/subs.html', v=v, subs=subs, total_users=total_users)
2022-07-01 23:11:48 +00:00
@app.post("/hole_pin/<pid>")
@is_not_permabanned
2022-07-01 23:11:48 +00:00
def hole_pin(v, pid):
p = get_post(pid)
if not p.sub: abort(403)
if not v.mods(p.sub): abort(403)
p.hole_pinned = v.username
g.db.add(p)
if v.id != p.author_id:
2022-11-11 17:01:40 +00:00
message = f"@{v.username} (/h/{p.sub} Mod) has pinned [{p.title}]({p.shortlink}) in /h/{p.sub}"
send_repeatable_notification(p.author_id, message)
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=p.sub,
2022-09-29 09:39:37 +00:00
kind='pin_post',
user_id=v.id,
target_submission_id=p.id
)
g.db.add(ma)
return {"message": f"Post pinned to /h/{p.sub} successfully!"}
2022-07-01 23:11:48 +00:00
@app.post("/hole_unpin/<pid>")
@is_not_permabanned
2022-07-01 23:11:48 +00:00
def hole_unpin(v, pid):
p = get_post(pid)
if not p.sub: abort(403)
if not v.mods(p.sub): abort(403)
p.hole_pinned = None
g.db.add(p)
if v.id != p.author_id:
2022-11-11 17:01:40 +00:00
message = f"@{v.username} (/h/{p.sub} Mod) has unpinned [{p.title}]({p.shortlink}) in /h/{p.sub}"
send_repeatable_notification(p.author_id, message)
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=p.sub,
2022-09-29 09:39:37 +00:00
kind='unpin_post',
user_id=v.id,
target_submission_id=p.id
)
g.db.add(ma)
return {"message": f"Post unpinned from /h/{p.sub} successfully!"}
@app.post('/h/<sub>/stealth')
@is_not_permabanned
def sub_stealth(v, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
2022-09-08 15:49:34 +00:00
if sub.name == 'braincels': abort(403)
if not v.mods(sub.name): abort(403)
sub.stealth = not sub.stealth
g.db.add(sub)
cache.delete_memoized(frontlist)
if sub.stealth:
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub.name,
2022-09-29 09:39:37 +00:00
kind='enable_stealth',
user_id=v.id
)
g.db.add(ma)
return {"message": f"Stealth mode has been enabled for /h/{sub} successfully!"}
else:
2022-09-29 09:39:37 +00:00
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=sub.name,
2022-09-29 09:39:37 +00:00
kind='disable_stealth',
user_id=v.id
)
g.db.add(ma)
return {"message": f"Stealth mode has been disabled for /h/{sub} successfully!"}
2022-09-29 09:39:37 +00:00
@app.post("/mod_pin/<cid>")
2022-10-11 07:29:24 +00:00
@feature_required('PINS')
2022-11-14 15:11:05 +00:00
@is_not_permabanned
2022-09-29 09:39:37 +00:00
def mod_pin(cid, v):
2022-10-11 07:29:24 +00:00
2022-09-29 09:39:37 +00:00
comment = get_comment(cid, v=v)
if not comment.stickied:
if not (comment.post.sub and v.mods(comment.post.sub)): abort(403)
comment.stickied = v.username + " (Mod)"
g.db.add(comment)
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=comment.post.sub,
2022-09-29 09:39:37 +00:00
kind="pin_comment",
user_id=v.id,
target_comment_id=comment.id
)
g.db.add(ma)
if v.id != comment.author_id:
message = f"@{v.username} (/h/{comment.post.sub} Mod) has pinned your [comment]({comment.shortlink})"
2022-09-29 09:39:37 +00:00
send_repeatable_notification(comment.author_id, message)
return {"message": "Comment pinned!"}
2022-09-29 10:18:27 +00:00
@app.post("/unmod_pin/<cid>")
2022-09-29 09:39:37 +00:00
@is_not_permabanned
def mod_unpin(cid, v):
comment = get_comment(cid, v=v)
if comment.stickied:
if not (comment.post.sub and v.mods(comment.post.sub)): abort(403)
comment.stickied = None
g.db.add(comment)
ma = SubAction(
2022-09-29 10:18:27 +00:00
sub=comment.post.sub,
2022-09-29 09:39:37 +00:00
kind="unpin_comment",
user_id=v.id,
target_comment_id=comment.id
)
g.db.add(ma)
if v.id != comment.author_id:
message = f"@{v.username} (/h/{comment.post.sub} Mod) has unpinned your [comment]({comment.shortlink})"
2022-09-29 09:39:37 +00:00
send_repeatable_notification(comment.author_id, message)
return {"message": "Comment unpinned!"}
@app.get("/h/<sub>/log")
@app.get("/h/<sub>/modlog")
@auth_required
2022-11-26 21:00:03 +00:00
def hole_log(v:User, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
if not User.can_see(v, sub):
abort(403)
2022-09-29 09:39:37 +00:00
try: page = max(int(request.values.get("page", 1)), 1)
except: page = 1
mod = request.values.get("mod")
if mod: mod_id = get_id(mod)
else: mod_id = 0
kind = request.values.get("kind")
types = ACTIONTYPES
if kind and kind not in types:
kind = None
actions = []
else:
2022-09-29 10:18:27 +00:00
actions = g.db.query(SubAction).filter_by(sub=sub.name)
2022-09-29 09:39:37 +00:00
if mod_id:
actions = actions.filter_by(user_id=mod_id)
kinds = set([x.kind for x in actions])
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(SubAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE+1).all()
2022-09-29 09:39:37 +00:00
next_exists=len(actions)>25
actions=actions[:25]
2022-09-29 10:18:27 +00:00
mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub.name).all()]
2022-09-29 09:39:37 +00:00
mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username).all()]
2022-11-04 23:51:42 +00:00
return render_template("log.html", v=v, admins=mods, types=types, admin=mod, type=kind, actions=actions, next_exists=next_exists, page=page, sub=sub, single_user_url='mod')
2022-09-29 09:39:37 +00:00
@app.get("/h/<sub>/log/<id>")
@auth_required
def hole_log_item(id, v, sub):
2022-10-05 10:30:44 +00:00
sub = get_sub_by_name(sub)
if not User.can_see(v, sub):
abort(403)
2022-09-29 09:39:37 +00:00
try: id = int(id)
except: abort(404)
action=g.db.get(SubAction, id)
if not action: abort(404)
2022-09-29 10:18:27 +00:00
mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub.name).all()]
2022-09-29 09:39:37 +00:00
mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username).all()]
types = ACTIONTYPES
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=mods, types=types, sub=sub, single_user_url='mod')