MarseyWorld/files/routes/front.py

303 lines
8.7 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 or_, not_
2023-05-01 19:50:32 +00:00
from sqlalchemy.orm import load_only
[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
2023-06-07 23:26:32 +00:00
from files.classes.post import Post
[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.votes import Vote
from files.helpers.config.const 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.helpers.get import *
2022-07-09 10:32:49 +00:00
from files.helpers.sorting_and_time import *
2023-05-13 02:04:25 +00:00
from files.helpers.useractions import *
2023-10-05 10:09:58 +00:00
from files.helpers.can_see 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 *
2023-06-27 20:03:14 +00:00
from files.__main__ import app, cache, limiter, redis_instance
2022-05-04 23:09:46 +00:00
@app.get("/")
2023-10-07 17:55:50 +00:00
@app.get("/h/<hole>")
@limiter.limit("30/minute;5000/hour;10000/day", deduct_when=lambda response: response.status_code < 400)
@auth_desired_with_logingate
2023-10-07 17:55:50 +00:00
def front_all(v, hole=None):
if hole:
hole = get_hole(hole, graceful=True)
if hole and not can_see(v, hole):
abort(403)
2023-01-01 11:36:20 +00:00
2023-10-07 17:55:50 +00:00
if request.path.startswith('/h/') and not hole:
2023-09-17 19:29:06 +00:00
abort(404)
2022-05-04 23:09:46 +00:00
2023-05-05 05:23:59 +00:00
page = get_page()
2022-05-04 23:09:46 +00:00
effortposts_only = request.values.get('effortposts_only', False)
if effortposts_only:
defaultsorting = 'new'
defaulttime = 'all'
elif v:
2022-05-04 23:09:46 +00:00
defaultsorting = v.defaultsorting
2024-01-29 03:33:06 +00:00
if hole: defaulttime = 'all'
2022-05-04 23:09:46 +00:00
else: defaulttime = v.defaulttime
else:
defaultsorting = "hot"
2024-01-29 03:33:06 +00:00
if hole: defaulttime = 'all'
2022-07-08 16:21:13 +00:00
else: defaulttime = DEFAULT_TIME_FILTER
2022-05-04 23:09:46 +00:00
2024-01-29 03:33:26 +00:00
if hole:
2024-01-12 01:25:02 +00:00
defaultsorting = "new"
2023-07-18 13:06:00 +00:00
2023-08-23 21:57:39 +00:00
sort = request.values.get("sort", defaultsorting)
t = request.values.get('t', defaulttime)
2023-01-01 11:36:20 +00:00
2023-09-07 15:54:30 +00:00
if SITE == 'rdrama.net' and t == 'all' and sort == 'hot' and page > 1000:
sort = 'top'
2023-08-23 21:57:39 +00:00
try: gt = int(request.values.get("after", 0))
except: gt = 0
2022-05-04 23:09:46 +00:00
2023-08-23 21:57:39 +00:00
try: lt = int(request.values.get("before", 0))
except: lt = 0
2022-05-04 23:09:46 +00:00
if effortposts_only:
pins = False
else:
if sort == 'hot': default = True
else: default = False
pins = session.get(f'{hole}_{sort}', default)
2022-07-13 17:31:35 +00:00
2023-06-27 20:03:14 +00:00
if not v:
result = cache.get(f'frontpage_{sort}_{t}_{page}_{hole}_{pins}_{effortposts_only}')
if result:
calc_users()
2024-02-13 13:34:24 +00:00
resp = make_response(result)
resp.headers["Cache-Control"] = "max-age=900"
return resp
2023-06-27 20:03:14 +00:00
hide_cw = (SITE_NAME == 'WPD' and v and v.hide_cw)
ids, total, size = frontlist(sort=sort,
2022-05-04 23:09:46 +00:00
page=page,
t=t,
v=v,
filter_words=v.filter_words if v else [],
gt=gt,
lt=lt,
2023-10-07 17:55:50 +00:00
hole=hole,
2022-11-07 00:44:31 +00:00
pins=pins,
effortposts_only=effortposts_only,
hide_cw=hide_cw,
2022-05-04 23:09:46 +00:00
)
2023-07-17 14:49:26 +00:00
posts = get_posts(ids, v=v)
2023-01-01 11:36:20 +00:00
2023-05-13 02:00:54 +00:00
if v and v.hidevotedon:
posts = [x for x in posts if not hasattr(x, 'voted') or not x.voted]
2022-05-04 23:09:46 +00:00
if v and v.client: return {"data": [x.json for x in posts], "total": total}
2023-06-27 20:03:14 +00:00
result = render_template("home.html", v=v, listing=posts, total=total, sort=sort, t=t, page=page, hole=hole, home=True, pins=pins, size=size)
2023-06-27 20:03:14 +00:00
if not v:
cache.set(f'frontpage_{sort}_{t}_{page}_{hole}_{pins}_{effortposts_only}', result, timeout=900)
2023-06-27 20:03:14 +00:00
return result
2022-05-04 23:09:46 +00:00
2023-10-08 12:01:40 +00:00
LIMITED_WPD_HOLES = {'aftermath', 'fights', 'gore', 'medical', 'request', 'selfharm',
'discussion', 'meta', 'music', 'pets', 'social',
2023-12-24 23:05:02 +00:00
'countryclub', 'highrollerclub',
'slavshit', 'sandshit'}
2023-01-24 05:43:46 +00:00
@cache.memoize()
def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', gt=0, lt=0, hole=None, pins=True, effortposts_only=False, hide_cw=False):
2023-06-07 23:26:32 +00:00
posts = g.db.query(Post)
2023-01-01 11:36:20 +00:00
if v and v.hidevotedon:
posts = posts.outerjoin(Vote,
2023-06-07 23:26:32 +00:00
and_(Vote.post_id == Post.id, Vote.user_id == v.id)
).filter(Vote.post_id == None)
2023-10-07 17:55:50 +00:00
if hole:
posts = posts.filter(Post.hole == hole.name)
elif v:
2023-10-07 17:55:50 +00:00
posts = posts.filter(or_(Post.hole == None, Post.hole.notin_(v.hole_blocks)))
else:
2023-10-07 17:55:50 +00:00
stealth = [x[0] for x in g.db.query(Hole.name).filter_by(stealth=True)]
posts = posts.filter(or_(Post.hole == None, Post.hole.notin_(stealth)))
2022-05-04 23:09:46 +00:00
2023-06-07 23:26:32 +00:00
if gt: posts = posts.filter(Post.created_utc > gt)
if lt: posts = posts.filter(Post.created_utc < lt)
2022-05-04 23:09:46 +00:00
if effortposts_only:
2024-02-07 23:59:42 +00:00
posts = posts.filter(Post.effortpost == True)
2022-05-04 23:09:46 +00:00
if not gt and not lt:
2023-06-07 23:26:32 +00:00
posts = apply_time_filter(t, posts, Post)
2022-05-04 23:09:46 +00:00
posts = posts.filter(
2023-06-07 23:26:32 +00:00
Post.is_banned == False,
Post.private == False,
Post.deleted_utc == 0,
)
2022-05-04 23:09:46 +00:00
if hide_cw:
posts = posts.filter(
or_(
Post.cw == False,
Post.author_id == v.id,
)
)
2022-11-07 00:44:31 +00:00
if pins and not gt and not lt:
2023-10-07 17:55:50 +00:00
if hole: posts = posts.filter(Post.hole_pinned == None)
2023-06-07 23:26:32 +00:00
else: posts = posts.filter(Post.stickied == None)
2022-05-04 23:09:46 +00:00
2022-05-24 20:43:49 +00:00
if v:
2023-06-07 23:26:32 +00:00
posts = posts.filter(Post.author_id.notin_(v.userblocks))
2022-05-04 23:09:46 +00:00
if v and filter_words:
for word in filter_words:
2023-09-26 22:12:01 +00:00
word = escape_for_search(word)
posts = posts.filter(not_(Post.title.ilike(f'%{word}%')))
2022-05-04 23:09:46 +00:00
2024-01-12 07:40:36 +00:00
if v and v.admin_level < PERMS['USER_SHADOWBAN']:
posts = posts.join(Post.author).filter(or_(User.id == v.id, User.shadowbanned == None))
total = posts.count()
2023-05-04 22:15:13 +00:00
2023-06-07 23:26:32 +00:00
posts = sort_objects(sort, posts, Post)
2022-05-04 23:09:46 +00:00
if v: size = v.frontsize or 0
else: size = PAGE_SIZE
2022-05-04 23:09:46 +00:00
if SITE_NAME == 'WPD' and sort == "hot" and page == 1 and not hole:
2024-01-31 20:01:08 +00:00
posts = posts.filter(Post.hole != 'pets')
2023-06-07 23:26:32 +00:00
posts = posts.options(load_only(Post.id)).offset(size * (page - 1))
2023-05-01 19:50:32 +00:00
2024-01-31 20:01:08 +00:00
if SITE_NAME == 'WPD' and sort == "hot" and hole == None:
2023-05-01 19:50:32 +00:00
posts = posts.limit(200).all()
posts_in_limited_holes = [x for x in posts if x.hole in LIMITED_WPD_HOLES]
captured_holes = set()
for post in posts_in_limited_holes:
if len(captured_holes) < 3 and post.hole not in captured_holes:
captured_holes.add(post.hole)
else:
posts.remove(post)
posts = posts[:size]
2023-10-07 17:55:50 +00:00
elif SITE_NAME == 'WPD' and not v and hole == None:
posts = posts.limit(200).all()
2023-10-07 17:55:50 +00:00
posts = [x for x in posts if x.hole not in {'pets','selfharm'}][:size]
else:
2023-05-01 19:50:32 +00:00
posts = posts.limit(size).all()
2022-05-04 23:09:46 +00:00
2022-11-07 00:44:31 +00:00
if pins and page == 1 and not gt and not lt:
2023-10-07 17:55:50 +00:00
if hole:
pins = g.db.query(Post).options(load_only(Post.id)).filter(Post.hole == hole.name, Post.hole_pinned != None)
2022-07-01 23:18:41 +00:00
else:
2023-06-07 23:26:32 +00:00
pins = g.db.query(Post).options(load_only(Post.id)).filter(Post.stickied != None, Post.is_banned == False)
2023-01-01 11:36:20 +00:00
2022-07-01 23:18:41 +00:00
if v:
2023-10-07 17:55:50 +00:00
pins = pins.filter(or_(Post.hole == None, Post.hole.notin_(v.hole_blocks)))
2022-07-01 23:18:41 +00:00
2023-06-07 23:26:32 +00:00
if v: pins = pins.filter(Post.author_id.notin_(v.userblocks))
pins = pins.order_by(Post.created_utc.desc()).all()
2022-05-04 23:09:46 +00:00
posts = pins + posts
if ids_only: posts = [x.id for x in posts]
return posts, total, size
2022-05-04 23:09:46 +00:00
@app.get("/random_post")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
2023-07-30 00:42:06 +00:00
def random_post(v):
2022-05-04 23:09:46 +00:00
p = g.db.query(Post.id).filter(
Post.deleted_utc == 0,
Post.is_banned == False,
Post.private == False,
2023-10-07 17:55:50 +00:00
or_(Post.hole == None, Post.hole.notin_(v.hole_blocks)),
).order_by(func.random()).first()
2022-05-04 23:09:46 +00:00
if p: p = p[0]
else: abort(404)
return redirect(f"/post/{p}")
@app.get("/random_user")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
2023-07-30 00:42:06 +00:00
def random_user(v):
2023-10-12 21:13:49 +00:00
u = g.db.query(User.username).filter(
User.song != None,
User.shadowbanned == None,
).order_by(func.random()).first()
2023-01-01 11:36:20 +00:00
2022-05-04 23:09:46 +00:00
if u: u = u[0]
else: abort(404, "No users have set a profile anthem so far!")
2022-05-04 23:09:46 +00:00
return redirect(f"/@{u}")
@cache.memoize()
2023-03-25 20:57:27 +00:00
def comment_idlist(v=None, page=1, sort="new", t="day", gt=0, lt=0):
2023-05-04 22:15:13 +00:00
comments = g.db.query(Comment) \
.outerjoin(Comment.post) \
2023-05-04 22:15:13 +00:00
.options(load_only(Comment.id)) \
.filter(
or_(Comment.parent_post != None, Comment.wall_user_id != None),
)
2022-05-04 23:09:46 +00:00
2022-10-06 02:24:37 +00:00
if v.admin_level < PERMS['POST_COMMENT_MODERATION']:
comments = comments.filter(
Comment.is_banned == False,
Comment.deleted_utc == 0,
Comment.author_id.notin_(v.userblocks),
or_(Comment.parent_post == None, Post.private == False),
)
2022-05-04 23:09:46 +00:00
if gt: comments = comments.filter(Comment.created_utc > gt)
if lt: comments = comments.filter(Comment.created_utc < lt)
if not gt and not lt:
2022-07-09 10:32:49 +00:00
comments = apply_time_filter(t, comments, Comment)
2022-05-04 23:09:46 +00:00
2024-01-12 07:20:32 +00:00
if v.admin_level < PERMS['USER_SHADOWBAN']:
comments = comments.join(Comment.author).filter(or_(User.id == v.id, User.shadowbanned == None))
total = comments.count()
comments = sort_objects(sort, comments, Comment)
2023-05-05 21:45:25 +00:00
2023-05-04 22:15:13 +00:00
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
return [x.id for x in comments], total
2023-01-20 21:16:09 +00:00
@app.get("/comments")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
2023-07-30 00:42:06 +00:00
def all_comments(v):
2023-05-05 05:23:59 +00:00
page = get_page()
2023-08-23 21:57:39 +00:00
sort = request.values.get("sort", "new")
t = request.values.get("t", "hour")
try: gt=int(request.values.get("after", 0))
except: gt=0
try: lt=int(request.values.get("before", 0))
except: lt=0
idlist, total = comment_idlist(v=v,
page=page,
sort=sort,
t=t,
gt=gt,
lt=lt,
)
comments = get_comments(idlist, v=v)
if v.client: return {"data": [x.json for x in comments]}
return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, total=total, size = PAGE_SIZE)