rDrama/files/routes/posts.py

1199 lines
36 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
import os
2022-05-04 23:09:46 +00:00
import time
import html
[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 io import BytesIO
from os import path
from shutil import copyfile
from sys import stdout
2023-08-05 18:51:05 +00:00
from urllib.parse import urlparse
import random
2023-09-26 16:59:58 +00:00
import subprocess
[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
2022-05-04 23:09:46 +00:00
import gevent
import requests
[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 PIL import Image
from files.__main__ import app, cache, limiter
from files.classes import *
from files.helpers.actions import *
2022-05-04 23:09:46 +00:00
from files.helpers.alerts import *
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 *
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.helpers.sanitize import *
from files.helpers.settings import get_setting
2022-05-04 23:09:46 +00:00
from files.helpers.slots import *
2022-07-09 10:32:49 +00:00
from files.helpers.sorting_and_time 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.routehelpers import execute_shadowban_viewers_and_voters
from files.routes.wrappers import *
2022-07-13 21:03:11 +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 .users import userpagelisting
2022-05-04 23:09:46 +00:00
2023-06-27 20:03:14 +00:00
from files.__main__ import app, limiter, redis_instance
2022-05-04 23:09:46 +00:00
def _add_post_view(pid):
db = db_session()
2023-07-26 12:31:44 +00:00
p = db.query(Post).filter_by(id=pid).options(load_only(Post.views)).one()
p.views += 1
db.add(p)
2023-07-26 12:12:37 +00:00
try: db.commit()
except: db.rollback()
db.close()
stdout.flush()
@app.post("/publish/<int:pid>")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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)
@is_not_banned
2022-05-04 23:09:46 +00:00
def publish(pid, v):
p = get_post(pid)
2024-02-15 17:25:57 +00:00
2024-02-18 15:29:53 +00:00
if not p.draft:
return {"message": "Post published!"}
2022-05-04 23:09:46 +00:00
if p.author_id != v.id: abort(403)
2024-02-15 17:25:57 +00:00
2024-02-18 15:29:53 +00:00
p.draft = False
p.created_utc = int(time.time())
2023-03-16 06:27:58 +00:00
g.db.add(p)
2023-01-01 11:36:20 +00:00
p.chudded = v.chud and p.hole != 'chudrama' and not (p.is_longpost and not v.chudded_by)
2024-02-15 22:05:33 +00:00
p.queened = v.queen and not p.is_longpost
p.sharpened = v.sharpen and not p.is_longpost
p.rainbowed = v.rainbow and not p.is_longpost
p.title_html = filter_emojis_only(p.title, golden=False, obj=p, author=p.author)
p.body_html = sanitize(p.body, golden=False, limit_pings=100, obj=p, author=p.author)
2024-02-18 15:29:53 +00:00
if p.draft or not complies_with_chud(p):
abort(403, f'You have to include "{p.author.chud_phrase}" in your post!')
notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v, ghost=p.ghost, obj=p, followers_ping=False)
2022-05-04 23:09:46 +00:00
2023-03-01 19:28:19 +00:00
if notify_users:
2024-01-14 08:54:01 +00:00
cid, text = notif_comment_mention(p)
2023-03-02 00:32:51 +00:00
if notify_users == 'everyone':
alert_everyone(cid)
else:
for x in notify_users:
add_notif(cid, x, text, pushnotif_url=p.permalink)
2022-05-04 23:09:46 +00:00
cache.delete_memoized(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
cache.delete_memoized(userpagelisting)
2022-05-04 23:09:46 +00:00
execute_snappy(p, v)
return {"message": "Post has been published successfully!"}
2022-05-04 23:09:46 +00:00
@app.get("/submit")
2023-10-07 17:55:50 +00:00
@app.get("/h/<hole>/submit")
@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-10-07 17:55:50 +00:00
def submit_get(v, hole=None):
hole = get_hole(hole, graceful=True)
2022-05-04 23:09:46 +00:00
2024-02-14 12:49:29 +00:00
if request.path.startswith('/h/') and not hole: abort(404)
2023-10-08 18:45:45 +00:00
2024-02-14 12:49:29 +00:00
return render_template("submit.html", v=v, hole=hole)
2022-05-04 23:09:46 +00:00
@app.get("/post/<int:pid>")
@app.get("/post/<int:pid>/<anything>")
2023-10-07 17:55:50 +00:00
@app.get("/h/<hole>/post/<int:pid>")
@app.get("/h/<hole>/post/<int:pid>/<anything>")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@auth_desired_with_logingate
2023-10-07 17:55:50 +00:00
def post_id(pid, v, anything=None, hole=None):
p = get_post(pid, v=v)
2023-10-05 10:09:58 +00:00
if not can_see(v, p): abort(403)
2022-08-19 22:36:28 +00:00
2023-10-05 10:19:50 +00:00
if not g.is_api_or_xhr and p.nsfw and not g.show_nsfw:
2022-05-04 23:09:46 +00:00
return render_template("errors/nsfw.html", v=v)
gevent.spawn(_add_post_view, pid)
if p.new: defaultsortingcomments = 'new'
2022-05-04 23:09:46 +00:00
elif v: defaultsortingcomments = v.defaultsortingcomments
2022-10-11 16:41:09 +00:00
else: defaultsortingcomments = "hot"
2022-05-04 23:09:46 +00:00
sort = request.values.get("sort", defaultsortingcomments)
if sort == 'saves':
sort = defaultsortingcomments
2023-06-27 20:08:52 +00:00
if not v:
result = cache.get(f'post_{p.id}_{sort}')
if result:
calc_users()
return result
2023-06-27 20:08:52 +00:00
2022-05-04 23:09:46 +00:00
if v:
execute_shadowban_viewers_and_voters(v, p)
2023-02-10 13:48:31 +00:00
# output is needed: see comments.py
comments, output = get_comments_v_properties(v, None, Comment.parent_post == p.id, Comment.level < 10)
if sort == "hot":
2024-02-18 15:29:53 +00:00
pinned = [c[0] for c in comments.filter(Comment.pinned != None).order_by(Comment.created_utc.desc())]
comments = comments.filter(Comment.pinned == None)
comments = comments.filter(Comment.level == 1)
comments = sort_objects(sort, comments, Comment)
2023-08-11 13:15:34 +00:00
comments = [c[0] for c in comments]
2022-05-04 23:09:46 +00:00
else:
comments = g.db.query(Comment).filter(Comment.parent_post == p.id)
2022-05-04 23:09:46 +00:00
if sort == "hot":
2024-02-18 15:29:53 +00:00
pinned = comments.filter(Comment.pinned != None).order_by(Comment.created_utc.desc()).all()
comments = comments.filter(Comment.pinned == None)
2022-05-04 23:09:46 +00:00
comments = comments.filter(Comment.level == 1)
comments = sort_objects(sort, comments, Comment)
comments = comments.all()
2022-05-04 23:09:46 +00:00
offset = 0
ids = set()
2022-10-25 18:20:43 +00:00
threshold = 100
if p.comment_count > threshold+25 and not (v and v.client):
2022-05-04 23:09:46 +00:00
comments2 = []
count = 0
2023-09-29 03:19:51 +00:00
if p.created_utc > 1638672040:
for comment in comments:
comments2.append(comment)
ids.add(comment.id)
count += g.db.query(Comment).filter_by(parent_post=p.id, top_comment_id=comment.id).count() + 1
if count > threshold: break
else:
for comment in comments:
comments2.append(comment)
ids.add(comment.id)
count += g.db.query(Comment).filter_by(parent_post=p.id, parent_comment_id=comment.id).count() + 1
if count > 20: break
if len(comments) == len(comments2): offset = 0
else: offset = 1
2022-05-04 23:09:46 +00:00
comments = comments2
p.replies = comments
if sort == "hot":
pinned2 = {}
for pin in pinned:
if pin.level > 1:
pinned2[pin.top_comment] = ''
if pin.top_comment in comments:
comments.remove(pin.top_comment)
else:
pinned2[pin] = ''
p.replies = list(pinned2.keys()) + p.replies
2022-05-04 23:09:46 +00:00
if v and v.client:
return p.json
2023-06-07 23:26:32 +00:00
template = "post.html"
2024-01-12 07:24:44 +00:00
if p.is_banned and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or p.author_id == v.id)):
2023-06-07 23:26:32 +00:00
template = "post_banned.html"
result = render_template(template, v=v, p=p, ids=list(ids),
2023-10-07 17:55:50 +00:00
sort=sort, render_replies=True, offset=offset, hole=p.hole_obj,
2022-11-30 18:26:07 +00:00
fart=get_setting('fart_mode'))
2023-06-27 20:08:52 +00:00
if not v:
cache.set(f'post_{p.id}_{sort}', result, timeout=3600)
return result
@app.get("/view_more/<int:pid>/<sort>/<int:offset>")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@auth_desired_with_logingate
def view_more(v, pid, sort, offset):
p = get_post(pid, v=v)
try: ids = set(int(x) for x in request.values.get("ids").split(','))
except: abort(400)
2023-01-01 11:36:20 +00:00
if v:
# output is needed: see comments.py
comments, output = get_comments_v_properties(v, None, Comment.parent_post == pid, Comment.id.notin_(ids), Comment.level < 10)
if sort == "hot":
2024-02-18 15:29:53 +00:00
comments = comments.filter(Comment.pinned == None)
comments = comments.filter(Comment.level == 1)
comments = sort_objects(sort, comments, Comment)
2023-08-11 13:15:34 +00:00
comments = [c[0] for c in comments]
else:
2023-03-16 06:27:58 +00:00
comments = g.db.query(Comment).filter(
Comment.parent_post == pid,
2022-10-13 10:47:55 +00:00
Comment.level == 1,
Comment.id.notin_(ids)
)
if sort == "hot":
2024-02-18 15:29:53 +00:00
comments = comments.filter(Comment.pinned == None)
comments = sort_objects(sort, comments, Comment)
2023-01-01 11:36:20 +00:00
comments = comments.offset(offset).all()
comments2 = []
count = 0
2023-09-29 03:19:51 +00:00
if p.created_utc > 1638672040:
for comment in comments:
comments2.append(comment)
ids.add(comment.id)
count += g.db.query(Comment).filter_by(parent_post=p.id, top_comment_id=comment.id).count() + 1
if count > 100: break
else:
for comment in comments:
comments2.append(comment)
ids.add(comment.id)
count += g.db.query(Comment).filter_by(parent_post=p.id, parent_comment_id=comment.id).count() + 1
if count > 20: break
2023-01-01 11:36:20 +00:00
if len(comments) == len(comments2): offset = 0
else: offset += 1
comments = comments2
return render_template("comments.html", v=v, comments=comments, p=p, ids=list(ids), render_replies=True, pid=pid, sort=sort, offset=offset)
2022-05-04 23:09:46 +00:00
@app.get("/more_comments/<int:cid>")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@auth_desired_with_logingate
def more_comments(v, cid):
2023-03-16 06:27:58 +00:00
tcid = g.db.query(Comment.top_comment_id).filter_by(id=cid).one_or_none()[0]
2022-05-04 23:09:46 +00:00
if v:
# output is needed: see comments.py
2023-02-27 16:16:12 +00:00
comments, output = get_comments_v_properties(v, None, Comment.top_comment_id == tcid, Comment.level > 9)
2022-12-14 18:24:14 +00:00
comments = comments.filter(Comment.parent_comment_id == cid)
2023-08-11 13:15:34 +00:00
comments = [c[0] for c in comments]
2022-05-04 23:09:46 +00:00
else:
2022-06-24 13:19:53 +00:00
c = get_comment(cid)
2023-07-08 13:32:14 +00:00
comments = c.replies(sort=request.values.get('sort'))
2022-05-04 23:09:46 +00:00
if comments: p = comments[0].post
else: p = None
2023-01-01 11:36:20 +00:00
return render_template("comments.html", v=v, comments=comments, p=p, render_replies=True)
2022-05-04 23:09:46 +00:00
def expand_url(post_url, fragment_url):
if fragment_url.startswith("https://"):
return fragment_url
elif fragment_url.startswith("https://"):
return f"https://{fragment_url.split('https://')[1]}"
elif fragment_url.startswith('//'):
return f"https:{fragment_url}"
elif fragment_url.startswith('/') and '\\' not in fragment_url:
parsed_url = urlparse(post_url)
return f"https://{parsed_url.netloc}{fragment_url}"
else:
return f"{post_url}/{fragment_url}"
2022-05-04 23:09:46 +00:00
def postprocess_post(post_url, post_body, post_body_html, pid, generate_thumb, edit):
with app.app_context():
if post_url and (reddit_s_url_regex.fullmatch(post_url) or tiktok_t_url_regex.fullmatch(post_url)):
post_url = normalize_url_gevent(post_url)
if post_body:
li = list(reddit_s_url_regex.finditer(post_body)) + list(tiktok_t_url_regex.finditer(post_body))
for i in li:
old = i.group(0)
new = normalize_url_gevent(old)
post_body = post_body.replace(old, new)
post_body_html = post_body_html.replace(old, new)
g.db = db_session()
p = g.db.query(Post).filter_by(id=pid).options(load_only(Post.id)).one_or_none()
p.url = post_url
p.body = post_body
p.body_html = post_body_html
g.db.add(p)
2024-02-18 15:29:53 +00:00
if not p.draft and not edit:
execute_snappy(p, p.author)
g.db.commit()
g.db.close()
stdout.flush()
#thumbnail
if not generate_thumb: return
2022-05-04 23:09:46 +00:00
if post_url.startswith('/') and '\\' not in post_url:
post_url = f"{SITE_FULL}{post_url}"
try:
x = requests.get(post_url, headers=HEADERS, timeout=5, proxies=proxies)
except:
return
2022-05-04 23:09:46 +00:00
if x.status_code != 200:
return
2022-05-04 23:09:46 +00:00
if x.headers.get("Content-Type","").startswith("text/html"):
soup = BeautifulSoup(x.content, 'lxml')
2022-05-04 23:09:46 +00:00
thumb_candidate_urls = []
2022-05-04 23:09:46 +00:00
for tag_name in ("twitter:image", "og:image", "thumbnail"):
tag = soup.find('meta', attrs={"name": tag_name, "content": True})
if not tag:
tag = soup.find('meta', attrs={"property": tag_name, "content": True})
if tag:
thumb_candidate_urls.append(expand_url(post_url, tag['content']))
2022-05-04 23:09:46 +00:00
for tag in soup.find_all("img", attrs={'src': True}):
thumb_candidate_urls.append(expand_url(post_url, tag['src']))
2022-05-04 23:09:46 +00:00
for url in thumb_candidate_urls:
try:
image_req = requests.get(url, headers=HEADERS, timeout=5, proxies=proxies)
except:
continue
2022-05-04 23:09:46 +00:00
if image_req.status_code >= 400:
continue
2022-05-04 23:09:46 +00:00
if not image_req.headers.get("Content-Type","").startswith("image/"):
continue
2022-05-04 23:09:46 +00:00
if image_req.headers.get("Content-Type","").startswith("image/svg"):
2022-10-25 15:39:57 +00:00
continue
with Image.open(BytesIO(image_req.content)) as i:
if i.width < 30 or i.height < 30:
continue
break
else:
return
elif x.headers.get("Content-Type","").startswith("image/"):
image_req = x
with Image.open(BytesIO(x.content)) as i:
size = len(i.fp.read())
if size > 8 * 1024 * 1024:
return
else:
return
2022-05-04 23:09:46 +00:00
name = f'/images/{time.time()}'.replace('.','') + '.webp'
2022-05-04 23:09:46 +00:00
with open(name, "wb") as file:
for chunk in image_req.iter_content(1024):
file.write(chunk)
2022-05-04 23:09:46 +00:00
g.db = db_session()
2023-07-26 12:31:44 +00:00
p = g.db.query(Post).filter_by(id=pid).options(load_only(Post.author_id)).one_or_none()
thumburl = process_image(name, None, resize=99, uploader_id=p.author_id)
if thumburl:
p.thumburl = thumburl
g.db.add(p)
g.db.commit()
g.db.close()
stdout.flush()
2022-05-04 23:09:46 +00:00
@app.post("/is_repost")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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)
2023-04-02 08:04:32 +00:00
@auth_required
def is_repost(v):
not_a_repost = {'permalink': ''}
2022-08-04 04:07:17 +00:00
if not FEATURES['REPOST_DETECTION']:
return not_a_repost
2022-05-04 23:09:46 +00:00
url = request.values.get('url')
2023-06-30 21:30:24 +00:00
if not url or len(url) < MIN_REPOST_CHECK_URL_LENGTH:
abort(400)
2022-05-04 23:09:46 +00:00
if reddit_s_url_regex.fullmatch(url) or tiktok_t_url_regex.fullmatch(url):
url = normalize_url_gevent(url)
url = normalize_url(url)
2022-05-04 23:09:46 +00:00
2023-09-26 22:12:01 +00:00
url = escape_for_search(url)
2023-06-07 23:26:32 +00:00
repost = g.db.query(Post).filter(
2023-09-26 22:12:01 +00:00
Post.url.ilike(url),
2023-06-07 23:26:32 +00:00
Post.deleted_utc == 0,
Post.is_banned == False
2022-05-04 23:09:46 +00:00
).first()
2023-09-26 22:12:01 +00:00
2022-05-04 23:09:46 +00:00
if repost: return {'permalink': repost.permalink}
else: return not_a_repost
2022-05-04 23:09:46 +00:00
@app.post("/submit")
2023-10-07 17:55:50 +00:00
@app.post("/h/<hole>/submit")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit('20/day', deduct_when=lambda response: response.status_code < 400)
@limiter.limit('20/day', deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
2023-10-07 17:55:50 +00:00
def submit_post(v, hole=None):
flag_private = request.values.get("private", False, bool)
if v.is_permabanned or (v.is_banned and not flag_private):
abort(403, "You can't perform this action while banned!")
2022-05-04 23:09:46 +00:00
url = request.values.get("url", "").strip()
2022-05-25 18:29:22 +00:00
if '\\' in url: abort(400)
2024-02-14 09:27:00 +00:00
title = request.values.get("title", "").strip()
if len(title) > POST_TITLE_LENGTH_LIMIT:
2024-02-14 09:34:49 +00:00
abort(400, f'Post title is too long (max {POST_TITLE_LENGTH_LIMIT} characters)')
2024-02-14 09:27:00 +00:00
body = request.values.get("body", "").strip()
if len(body) > POST_BODY_LENGTH_LIMIT(g.v):
2024-02-14 09:34:49 +00:00
abort(400, f'Post body is too long (max {POST_BODY_LENGTH_LIMIT(g.v)} characters)')
if not title:
2023-02-17 23:25:01 +00:00
abort(400, "Please enter a better title!")
2023-10-07 17:55:50 +00:00
hole = request.values.get("hole", "").lower().replace('/h/','').strip()
if SITE == 'rdrama.net' and (v.chud == 1 or v.id == 253):
2023-10-07 17:55:50 +00:00
hole = 'chudrama'
2023-09-07 15:26:31 +00:00
2023-08-12 10:19:12 +00:00
if SITE == 'rdrama.net' and v.id == 10947:
2023-10-07 17:55:50 +00:00
hole = 'mnn'
2023-06-27 12:02:34 +00:00
2023-10-07 17:55:50 +00:00
if hole == 'changelog':
2023-04-29 16:31:51 +00:00
abort(400, "/h/changelog is archived")
2022-05-04 23:09:46 +00:00
2023-10-07 17:55:50 +00:00
if hole in {'furry','vampire','racist','femboy','edgy'} and not v.client and not v.house.lower().startswith(hole):
abort(400, f"You need to be a member of House {hole.capitalize()} to post in /h/{hole}")
2022-08-21 15:24:16 +00:00
2023-10-07 17:55:50 +00:00
if hole and hole != 'none':
hole_name = hole.strip().lower()
hole = g.db.query(Hole).options(load_only(Hole.name)).filter_by(name=hole_name).one_or_none()
if not hole: abort(400, f"/h/{hole_name} not found!")
2023-10-07 17:55:50 +00:00
if not can_see(v, hole):
if hole.name == 'highrollerclub':
abort(403, f"Only {patron}s can post in /h/{hole}")
abort(403, f"You're not allowed to post in /h/{hole}")
2023-10-07 17:55:50 +00:00
hole = hole.name
if v.exiler_username(hole): abort(400, f"You're exiled from /h/{hole}")
else: hole = None
2022-05-04 23:09:46 +00:00
2023-10-07 17:55:50 +00:00
if not hole and HOLE_REQUIRED:
abort(400, f"You must choose a hole for your post!")
2022-06-26 01:01:21 +00:00
2022-05-04 23:09:46 +00:00
if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')):
2023-02-17 23:25:01 +00:00
abort(400, "You have to type more than 280 characters!")
2022-05-04 23:09:46 +00:00
elif v.bird and len(body) > 140:
2023-02-17 23:25:01 +00:00
abort(400, "You have to type less than 140 characters!")
2022-05-04 23:09:46 +00:00
embed = None
if url:
url = normalize_url(url)
2024-02-14 15:41:11 +00:00
domain = tldextract.extract(url).registered_domain
2023-06-02 13:48:58 +00:00
if v.admin_level < PERMS["IGNORE_DOMAIN_BAN"]:
2024-02-14 15:39:26 +00:00
combined = (domain + urlparse(url).path).lower()
2023-08-05 19:26:42 +00:00
for x in g.db.query(BannedDomain):
2024-02-14 15:39:26 +00:00
if combined.startswith(x.domain):
2023-06-02 13:48:58 +00:00
abort(400, f'Remove the banned link "{x.domain}" and try again!\nReason for link ban: "{x.reason}"')
2022-10-27 22:37:24 +00:00
2023-08-05 19:26:17 +00:00
if domain == "twitter.com":
try:
2023-09-09 17:06:26 +00:00
embed = requests.get("https://publish.twitter.com/oembed", params={"url":url, "omit_script":"t"}, headers=HEADERS, timeout=5).json()["html"]
2022-10-29 21:46:30 +00:00
embed = embed.replace('<a href', '<a rel="nofollow noopener" href')
2022-05-04 23:09:46 +00:00
except: pass
2023-01-23 02:06:56 +00:00
elif url.startswith('https://youtube.com/watch?'):
embed = handle_youtube_links(url)
2022-07-11 11:55:15 +00:00
elif SITE in domain and "/post/" in url and "context" not in url and url.count('/') < 6:
2022-05-04 23:09:46 +00:00
id = url.split("/post/")[1]
if "/" in id: id = id.split("/")[0]
embed = str(int(id))
2022-10-05 08:16:56 +00:00
if not url and not body and not request.files.get("file") and not request.files.get("file-url"):
2023-02-17 23:25:01 +00:00
abort(400, "Please enter a url or some text!")
2022-05-04 23:09:46 +00:00
2023-01-01 11:36:20 +00:00
if not IS_LOCALHOST:
2023-06-07 23:26:32 +00:00
dup = g.db.query(Post).filter(
Post.author_id == v.id,
Post.deleted_utc == 0,
Post.title == title,
Post.url == url,
Post.body == body
).one_or_none()
2023-03-06 00:00:01 +00:00
if dup:
return {"post_id": dup.id, "success": False}
2022-05-04 23:09:46 +00:00
if not execute_antispam_post_check(title, v, url):
2023-08-08 12:04:04 +00:00
abort(403, "You have been banned for 1 day for spamming!")
2022-05-04 23:09:46 +00:00
if len(url) > 2048:
2023-02-17 23:25:01 +00:00
abort(400, "There's a 2048 character limit for URLs!")
2022-05-04 23:09:46 +00:00
2024-02-14 09:27:00 +00:00
body = process_files(request.files, v, body).strip()
if len(body) > POST_BODY_LENGTH_LIMIT(g.v):
2024-02-14 09:34:49 +00:00
abort(400, f'Post body is too long (max {POST_BODY_LENGTH_LIMIT(g.v)} characters)')
2022-05-22 10:26:59 +00:00
flag_notify = (request.values.get("notify", "on") == "on")
2022-12-03 22:01:08 +00:00
flag_new = request.values.get("new", False, bool) or 'megathread' in title.lower()
2023-10-05 10:19:50 +00:00
flag_nsfw = FEATURES['NSFW_MARKING'] and request.values.get("nsfw", False, bool)
2024-02-06 22:04:43 +00:00
flag_effortpost = request.values.get("effortpost", False, bool)
2022-11-14 17:17:29 +00:00
flag_ghost = request.values.get("ghost", False, bool) and v.can_post_in_ghost_threads
2022-05-04 23:09:46 +00:00
2023-10-07 17:55:50 +00:00
if flag_ghost: hole = None
if embed and len(embed) > 1500: embed = None
2022-07-09 07:41:05 +00:00
if embed: embed = embed.strip()
if url and url.startswith(f'{SITE_FULL}/'):
2022-10-18 11:09:53 +00:00
url = url.split(SITE_FULL)[1]
2023-05-15 09:27:24 +00:00
if url == '': url = None
2023-06-07 23:26:32 +00:00
p = Post(
private=flag_private,
notify=flag_notify,
2022-05-04 23:09:46 +00:00
author_id=v.id,
2023-10-05 10:19:50 +00:00
nsfw=flag_nsfw,
new=flag_new,
2022-05-04 23:09:46 +00:00
app_id=v.client.application.id if v.client else None,
is_bot=(v.client is not None),
2022-05-04 23:09:46 +00:00
url=url,
2022-10-05 08:16:56 +00:00
body=body,
2023-02-18 16:33:19 +00:00
embed=embed,
title=title,
2023-10-07 17:55:50 +00:00
hole=hole,
2023-06-23 13:14:23 +00:00
ghost=flag_ghost,
2022-05-04 23:09:46 +00:00
)
2024-02-12 18:56:36 +00:00
if SITE_NAME == 'WPD':
p.cw = request.values.get("cw", False, bool)
2023-11-04 16:16:23 +00:00
2024-02-18 15:29:53 +00:00
if not p.draft:
p.chudded = v.chud and hole != 'chudrama' and not (p.is_longpost and not v.chudded_by)
p.queened = v.queen and not p.is_longpost
p.sharpened = v.sharpen and not p.is_longpost
p.rainbowed = v.rainbow and not p.is_longpost
title_html = filter_emojis_only(title, count_emojis=True, obj=p, author=v)
2023-09-29 07:15:29 +00:00
2023-10-13 19:04:45 +00:00
if v.hieroglyphs and not marseyaward_title_regex.fullmatch(title_html):
2023-09-29 07:15:29 +00:00
abort(400, "You can only type marseys!")
p.title_html = title_html
body_html = sanitize(body, count_emojis=True, limit_pings=100, obj=p, author=v)
2023-09-29 07:15:29 +00:00
2023-10-13 19:04:45 +00:00
if v.hieroglyphs and marseyaward_body_regex.search(body_html):
2023-09-29 07:15:29 +00:00
abort(400, "You can only type marseys!")
if len(body_html) > POST_BODY_HTML_LENGTH_LIMIT:
2024-02-14 09:34:49 +00:00
abort(400, "Rendered post body is too long!")
2023-09-29 07:15:29 +00:00
p.body_html = body_html
2023-03-16 06:27:58 +00:00
g.db.add(p)
g.db.flush()
2022-05-04 23:09:46 +00:00
execute_under_siege(v, p, p.body, 'post')
2023-03-13 19:18:08 +00:00
process_options(v, p)
for text in {p.body, p.title, p.url}:
if execute_blackjack(v, p, text, 'post'): break
2022-05-04 23:09:46 +00:00
vote = Vote(user_id=v.id,
vote_type=1,
2023-06-07 23:26:32 +00:00
post_id=p.id,
coins=0
2022-05-04 23:09:46 +00:00
)
2023-03-16 06:27:58 +00:00
g.db.add(vote)
2023-01-01 11:36:20 +00:00
[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 request.files.get('file-url') and not g.is_tor:
file = request.files['file-url']
2022-05-04 23:09:46 +00:00
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
p.url = process_image(name, v)
2022-05-04 23:09:46 +00:00
name2 = name.replace('.webp', 'r.webp')
copyfile(name, name2)
p.thumburl = process_image(name2, v, resize=99)
2022-05-04 23:09:46 +00:00
elif file.content_type.startswith('video/'):
p.url = process_video(file, v)
name = f'/images/{time.time()}'.replace('.','') + '.webp'
2023-07-23 15:14:06 +00:00
try:
subprocess.run(["ffmpeg", "-loglevel", "quiet", "-y", "-i", p.url, "-vf", "scale='iw':-2", "-q:v", "3", "-frames:v", "1", name], check=True, timeout=30)
2023-07-23 15:14:06 +00:00
except:
if os.path.isfile(name):
os.remove(name)
else:
2023-10-17 18:19:41 +00:00
p.posterurl = SITE_FULL_IMAGES + name
2023-07-23 15:14:06 +00:00
name2 = name.replace('.webp', 'r.webp')
copyfile(name, name2)
p.thumburl = process_image(name2, v, resize=99)
2022-05-22 22:15:29 +00:00
elif file.content_type.startswith('audio/'):
p.url = process_audio(file, v)
2022-05-04 23:09:46 +00:00
else:
abort(415)
2023-01-01 11:36:20 +00:00
2024-02-18 15:29:53 +00:00
if not p.draft and not complies_with_chud(p):
p.is_banned = True
p.ban_reason = "AutoJanny"
2022-05-04 23:09:46 +00:00
body = random.choice(CHUD_MSGS).format(username=v.username, type='post', CHUD_PHRASE=v.chud_phrase)
2023-03-25 16:46:50 +00:00
body_jannied_html = sanitize(body)
2022-05-04 23:09:46 +00:00
c_jannied = Comment(author_id=AUTOJANNY_ID,
parent_post=p.id,
2022-05-04 23:09:46 +00:00
level=1,
2023-10-05 10:19:50 +00:00
nsfw=False,
2022-05-04 23:09:46 +00:00
is_bot=True,
app_id=None,
distinguished=True,
body=body,
2022-05-04 23:09:46 +00:00
body_html=body_jannied_html,
ghost=p.ghost
2022-05-04 23:09:46 +00:00
)
2023-03-16 06:27:58 +00:00
g.db.add(c_jannied)
g.db.flush()
2022-05-04 23:09:46 +00:00
p.comment_count += 1
2023-03-16 06:27:58 +00:00
g.db.add(p)
2022-05-04 23:09:46 +00:00
c_jannied.top_comment_id = c_jannied.id
n = Notification(comment_id=c_jannied.id, user_id=v.id)
2023-03-16 06:27:58 +00:00
g.db.add(n)
2022-05-04 23:09:46 +00:00
2023-06-23 17:47:08 +00:00
autojanny = g.db.get(User, AUTOJANNY_ID)
autojanny.comment_count += 1
g.db.add(autojanny)
2024-02-18 15:29:53 +00:00
if not p.draft:
notify_users = NOTIFY_USERS(f'{title} {body}', v, ghost=p.ghost, obj=p, followers_ping=False)
if notify_users:
2024-01-14 08:54:01 +00:00
cid, text = notif_comment_mention(p)
if notify_users == 'everyone':
alert_everyone(cid)
else:
for x in notify_users:
add_notif(cid, x, text, pushnotif_url=p.permalink)
v.post_count += 1
g.db.add(v)
2022-05-04 23:09:46 +00:00
if v.id in PINNED_POSTS_IDS and not p.ghost and not (p.hole and p.hole_obj.stealth):
2024-02-18 15:29:53 +00:00
p.pinned_utc = time.time() + PINNED_POSTS_IDS[v.id] * 3600
p.pinned = "AutoJanny"
2023-04-24 15:17:12 +00:00
2022-05-04 23:09:46 +00:00
cache.delete_memoized(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
cache.delete_memoized(userpagelisting)
2022-05-04 23:09:46 +00:00
2023-08-20 03:04:25 +00:00
g.db.flush() #Necessary, do NOT remove
generate_thumb = (not p.thumburl and p.url and p.domain != SITE)
gevent.spawn(postprocess_post, p.url, p.body, p.body_html, p.id, generate_thumb, False)
2023-07-25 22:08:29 +00:00
2024-02-08 00:19:04 +00:00
if flag_effortpost and not (SITE_NAME == 'WPD' and v.truescore < 500):
2024-02-06 22:04:43 +00:00
body = f"@{v.username} has requested that [{p.title}](/post/{p.id}) be marked as an effortpost!"
2024-02-17 17:54:18 +00:00
if SITE == 'rdrama.net':
send_repeatable_notification(AEVANN_ID, body)
else:
body_html = sanitize(body, blackjack="admin alert")
new_comment = Comment(author_id=AUTOJANNY_ID,
parent_post=None,
level=1,
body_html=body_html,
sentto=MODMAIL_ID,
distinguished=True,
is_bot=True
)
g.db.add(new_comment)
g.db.flush()
new_comment.top_comment_id = new_comment.id
2024-02-06 22:04:43 +00:00
if v.client: return p.json
2022-05-04 23:09:46 +00:00
else:
p.voted = 1
return {"post_id": p.id, "success": True}
2022-05-04 23:09:46 +00:00
@app.post("/delete/post/<int:pid>")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DELETE_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DELETE_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def delete_post_pid(pid, v):
p = get_post(pid)
if p.author_id != v.id: abort(403)
2022-05-04 23:09:46 +00:00
if not p.deleted_utc:
p.deleted_utc = int(time.time())
2024-02-18 15:29:53 +00:00
p.profile_pinned = False
p.pinned = None
p.pinned_utc = None
2022-05-04 23:09:46 +00:00
2023-03-16 06:27:58 +00:00
g.db.add(p)
2022-05-04 23:09:46 +00:00
2022-07-08 11:07:27 +00:00
cache.delete_memoized(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
cache.delete_memoized(userpagelisting)
2022-05-04 23:09:46 +00:00
v.post_count -= 1
2023-03-16 06:27:58 +00:00
g.db.add(v)
2022-05-04 23:09:46 +00:00
2023-09-05 14:32:36 +00:00
for sort in COMMENT_SORTS.keys():
cache.delete(f'post_{p.id}_{sort}')
2022-05-04 23:09:46 +00:00
return {"message": "Post deleted!"}
@app.post("/undelete_post/<int:pid>")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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
def undelete_post_pid(pid, v):
p = get_post(pid)
if p.author_id != v.id: abort(403)
2022-05-04 23:09:46 +00:00
if p.deleted_utc:
p.deleted_utc = 0
2023-03-16 06:27:58 +00:00
g.db.add(p)
2022-07-08 11:07:27 +00:00
cache.delete_memoized(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
cache.delete_memoized(userpagelisting)
2022-05-04 23:09:46 +00:00
v.post_count += 1
2023-03-16 06:27:58 +00:00
g.db.add(v)
2022-05-04 23:09:46 +00:00
2023-09-05 14:32:36 +00:00
for sort in COMMENT_SORTS.keys():
cache.delete(f'post_{p.id}_{sort}')
2022-05-04 23:09:46 +00:00
return {"message": "Post undeleted!"}
@app.post("/mark_post_nsfw/<int:pid>")
2023-02-01 18:52:34 +00:00
@feature_required('NSFW_MARKING')
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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
def mark_post_nsfw(pid, v):
p = get_post(pid)
2022-05-04 23:09:46 +00:00
2024-02-16 12:36:45 +00:00
if p.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION'] and not v.mods_hole(p.hole):
2022-05-04 23:09:46 +00:00
abort(403)
2023-01-01 11:36:20 +00:00
2023-10-05 10:19:50 +00:00
p.nsfw = True
2023-03-16 06:27:58 +00:00
g.db.add(p)
2022-05-04 23:09:46 +00:00
if p.author_id != v.id:
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']:
ma = ModAction(
kind = "set_nsfw",
user_id = v.id,
2023-06-07 23:26:32 +00:00
target_post_id = p.id,
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
2024-02-18 14:04:32 +00:00
actor_str = admin_str(v)
else:
2023-10-07 17:55:50 +00:00
ma = HoleAction(
hole = p.hole,
kind = "set_nsfw",
user_id = v.id,
2023-06-07 23:26:32 +00:00
target_post_id = p.id,
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
2024-02-18 14:04:32 +00:00
actor_str = f'@{v.username} (a /h/{hole_from} mod)'
2024-02-06 21:45:41 +00:00
2024-02-18 14:04:32 +00:00
send_repeatable_notification(p.author_id, f"{actor_str} marked [{p.title}](/post/{p.id}) as NSFW")
2022-05-04 23:09:46 +00:00
2023-10-04 14:04:06 +00:00
return {"message": "Post has been marked as NSFW!"}
@app.post("/unmark_post_nsfw/<int:pid>")
2023-02-01 18:52:34 +00:00
@feature_required('NSFW_MARKING')
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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
def unmark_post_nsfw(pid, v):
p = get_post(pid)
2024-02-16 12:36:45 +00:00
if p.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION'] and not v.mods_hole(p.hole):
abort(403)
2023-01-01 11:36:20 +00:00
2023-10-05 10:19:50 +00:00
if p.nsfw and v.is_permabanned:
abort(403)
2023-10-05 10:19:50 +00:00
p.nsfw = False
2023-03-16 06:27:58 +00:00
g.db.add(p)
if p.author_id != v.id:
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']:
ma = ModAction(
kind = "unset_nsfw",
user_id = v.id,
2023-06-07 23:26:32 +00:00
target_post_id = p.id,
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
2024-02-18 14:04:32 +00:00
actor_str = admin_str(v)
else:
2023-10-07 17:55:50 +00:00
ma = HoleAction(
hole = p.hole,
kind = "unset_nsfw",
user_id = v.id,
2023-06-07 23:26:32 +00:00
target_post_id = p.id,
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
2024-02-18 14:04:32 +00:00
actor_str = f'@{v.username} (a /h/{hole_from} mod)'
2024-02-06 21:45:41 +00:00
2024-02-18 14:04:32 +00:00
send_repeatable_notification(p.author_id, f"{actor_str} unmarked [{p.title}](/post/{p.id}) as NSFW")
2023-10-04 14:04:06 +00:00
return {"message": "Post has been unmarked as NSFW!"}
2022-05-04 23:09:46 +00:00
@app.post("/save_post/<int:pid>")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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
def save_post(pid, v):
p = get_post(pid)
2022-05-04 23:09:46 +00:00
2023-06-07 23:26:32 +00:00
save = g.db.query(SaveRelationship).filter_by(user_id=v.id, post_id=p.id).one_or_none()
2022-05-04 23:09:46 +00:00
if not save:
2023-06-07 23:26:32 +00:00
new_save=SaveRelationship(user_id=v.id, post_id=p.id)
2023-03-16 06:27:58 +00:00
g.db.add(new_save)
cache.delete_memoized(userpagelisting)
2022-05-04 23:09:46 +00:00
return {"message": "Post saved!"}
@app.post("/unsave_post/<int:pid>")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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
def unsave_post(pid, v):
p = get_post(pid)
2022-05-04 23:09:46 +00:00
2023-06-07 23:26:32 +00:00
save = g.db.query(SaveRelationship).filter_by(user_id=v.id, post_id=p.id).one_or_none()
2022-05-04 23:09:46 +00:00
if save:
2023-03-16 06:27:58 +00:00
g.db.delete(save)
cache.delete_memoized(userpagelisting)
2022-05-04 23:09:46 +00:00
return {"message": "Post unsaved!"}
2024-02-18 15:29:53 +00:00
@app.post("/profile_pin/<int:post_id>")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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
2022-08-11 04:05:23 +00:00
def pin_post(post_id, v):
p = get_post(post_id)
if p:
if v.id != p.author_id: abort(403, "Only the post author can do that!")
2024-02-18 15:29:53 +00:00
p.profile_pinned = not p.profile_pinned
2023-03-16 06:27:58 +00:00
g.db.add(p)
[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
cache.delete_memoized(userpagelisting)
2024-02-18 15:29:53 +00:00
if p.profile_pinned: return {"message": "Post pinned!"}
2022-05-04 23:09:46 +00:00
else: return {"message": "Post unpinned!"}
return abort(404, "Post not found!")
2022-05-04 23:09:46 +00:00
@app.post("/post/<int:post_id>/new")
@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 set_new_sort(post_id, v):
p = get_post(post_id)
if not v.can_edit(p): abort(403, "Only the post author can do that!")
p.new = True
2023-03-16 06:27:58 +00:00
g.db.add(p)
2022-12-10 14:57:19 +00:00
if v.id != p.author_id:
2022-12-10 14:57:19 +00:00
ma = ModAction(
kind = "set_new",
user_id = v.id,
2023-06-07 23:26:32 +00:00
target_post_id = p.id,
2022-12-10 14:57:19 +00:00
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
2024-02-18 14:04:32 +00:00
send_repeatable_notification(p.author_id, f"{admin_str(v)} changed the the default sorting of comments on [{p.title}](/post/{p.id}) to `new`")
2022-12-10 14:57:19 +00:00
2023-02-24 02:54:31 +00:00
return {"message": "Changed the the default sorting of comments on this post to 'new'"}
2022-12-10 14:57:19 +00:00
@app.post("/post/<int:post_id>/hot")
@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-12-10 14:57:19 +00:00
@auth_required
2023-07-30 00:42:06 +00:00
def unset_new_sort(post_id, v):
p = get_post(post_id)
if not v.can_edit(p): abort(403, "Only the post author can do that!")
p.new = None
2023-03-16 06:27:58 +00:00
g.db.add(p)
2022-12-10 14:57:19 +00:00
if v.id != p.author_id:
2022-12-10 14:57:19 +00:00
ma = ModAction(
kind = "set_hot",
user_id = v.id,
2023-06-07 23:26:32 +00:00
target_post_id = p.id,
2022-12-10 14:57:19 +00:00
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
2024-02-18 14:04:32 +00:00
send_repeatable_notification(p.author_id, f"{admin_str(v)} changed the the default sorting of comments on [{p.title}](/post/{p.id}) to `hot`")
2022-12-10 14:57:19 +00:00
2023-02-24 02:54:31 +00:00
return {"message": "Changed the the default sorting of comments on this post to 'hot'"}
2022-05-04 23:09:46 +00:00
2022-10-30 14:55:43 +00:00
extensions = IMAGE_FORMATS + VIDEO_FORMATS + AUDIO_FORMATS
2022-05-04 23:09:46 +00:00
@app.get("/submit/title")
@limiter.limit("3/minute", deduct_when=lambda response: response.status_code < 400)
@limiter.limit("3/minute", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def get_post_title(v):
POST_TITLE_TIMEOUT = 5
2022-05-04 23:09:46 +00:00
url = request.values.get("url")
if not url or '\\' in url: abort(400)
2022-11-12 05:40:17 +00:00
url = url.strip()
if not url.startswith('http'): abort(400)
2022-10-30 14:55:43 +00:00
checking_url = url.lower().split('?')[0].split('%3F')[0]
if any((checking_url.endswith(f'.{x}') for x in extensions)):
abort(400)
2022-05-04 23:09:46 +00:00
try:
x = gevent.with_timeout(POST_TITLE_TIMEOUT, requests.get, url, headers=HEADERS, timeout=POST_TITLE_TIMEOUT, proxies=proxies)
2022-05-04 23:09:46 +00:00
except: abort(400)
2023-01-01 11:36:20 +00:00
content_type = x.headers.get("Content-Type")
if not content_type or "text/html" not in content_type: abort(400)
2022-05-04 23:09:46 +00:00
# no you can't just parse html with reeeeeeeegex
2022-11-11 10:17:59 +00:00
match = html_title_regex.search(x.text)
if match and match.lastindex >= 1:
title = match.group(1)
2022-11-11 09:49:43 +00:00
else: abort(400)
2022-05-04 23:09:46 +00:00
title = html.unescape(title)
2022-11-11 10:17:59 +00:00
return {"url": url, "title": title}
@app.post("/edit_post/<int:pid>")
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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
def edit_post(pid, v):
p = get_post(pid)
if not v.can_edit(p): abort(403)
# Disable edits on things older than 1wk unless it's a draft or editor is a jannie
2024-02-18 15:29:53 +00:00
if time.time() - p.created_utc > 31*24*60*60 and not p.draft \
and v.admin_level < PERMS["IGNORE_1MONTH_EDITING_LIMIT"] and v.id not in EXEMPT_FROM_1MONTH_EDITING_LIMIT:
abort(403, "You can't edit posts older than 1 month!")
2024-02-14 09:27:00 +00:00
title = request.values.get("title", "").strip()
if len(title) > POST_TITLE_LENGTH_LIMIT:
2024-02-14 09:34:49 +00:00
abort(400, f'Post title is too long (max {POST_TITLE_LENGTH_LIMIT} characters)')
2024-02-14 09:27:00 +00:00
body = request.values.get("body", "").strip()
if len(body) > POST_BODY_LENGTH_LIMIT(g.v):
2024-02-14 09:34:49 +00:00
abort(400, f'Post body is too long (max {POST_BODY_LENGTH_LIMIT(g.v)} characters)')
if p.author.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')):
abort(403, "You have to type more than 280 characters!")
elif p.author.bird and len(body) > 140:
abort(403, "You have to type less than 140 characters!")
if not title:
abort(400, "Please enter a better title!")
2024-02-18 15:29:53 +00:00
if not p.draft:
notify_users = NOTIFY_USERS(f'{title} {body}', v, oldtext=f'{p.title} {p.body}', ghost=p.ghost, obj=p, followers_ping=False)
if notify_users:
2024-01-14 08:54:01 +00:00
cid, text = notif_comment_mention(p)
if notify_users == 'everyone':
alert_everyone(cid)
else:
for x in notify_users:
add_notif(cid, x, text, pushnotif_url=p.permalink)
if title != p.title:
title_html = filter_emojis_only(title, golden=False, obj=p, author=p.author)
2023-10-13 19:04:45 +00:00
if p.author.hieroglyphs and not marseyaward_title_regex.fullmatch(title_html):
abort(403, "You can only type marseys!")
if 'megathread' in title.lower() and 'megathread' not in p.title.lower():
p.new = True
p.title = title
p.title_html = title_html
2024-02-14 09:27:00 +00:00
body = process_files(request.files, v, body).strip()
if len(body) > POST_BODY_LENGTH_LIMIT(g.v):
2024-02-14 09:34:49 +00:00
abort(400, f'Post body is too long (max {POST_BODY_LENGTH_LIMIT(g.v)} characters)')
if body != p.body or p.chudded:
body_html = sanitize(body, golden=False, limit_pings=100, obj=p, author=p.author)
2023-10-13 19:04:45 +00:00
if p.author.hieroglyphs and marseyaward_body_regex.search(body_html):
abort(403, "You can only type marseys!")
p.body = body
for text in [p.body, p.title, p.url]:
if execute_blackjack(v, p, text, 'post'): break
if len(body_html) > POST_BODY_HTML_LENGTH_LIMIT:
2024-02-14 09:34:49 +00:00
abort(400, "Rendered post body is too long!")
p.body_html = body_html
process_options(v, p)
gevent.spawn(postprocess_post, p.url, p.body, p.body_html, p.id, False, True)
2023-03-25 18:18:12 +00:00
2024-02-18 15:29:53 +00:00
if not p.draft and not complies_with_chud(p):
abort(403, f'You have to include "{p.author.chud_phrase}" in your post!')
if v.id == p.author_id:
2023-08-15 20:34:06 +00:00
if int(time.time()) - p.created_utc > 60 * 3:
p.edited_utc = int(time.time())
else:
2024-01-31 21:56:32 +00:00
ma = ModAction(
kind="edit_post",
user_id=v.id,
2023-06-07 23:26:32 +00:00
target_post_id=p.id
)
2023-03-16 06:27:58 +00:00
g.db.add(ma)
2023-07-14 17:07:58 +00:00
return {"message": "Post edited successfully!"}
if SITE_NAME == 'WPD':
@app.post("/mark_post_cw/<int:pid>")
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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
def mark_post_cw(pid, v):
p = get_post(pid)
if p.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION']:
abort(403)
p.cw = True
g.db.add(p)
if p.author_id != v.id:
ma = ModAction(
kind = "set_cw",
user_id = v.id,
target_post_id = p.id,
)
g.db.add(ma)
2024-02-18 14:04:32 +00:00
send_repeatable_notification(p.author_id, f"{admin_str(v)} added a child warning to [{p.title}](/post/{p.id})")
return {"message": "A child warning has been added to the post!"}
@app.post("/unmark_post_cw/<int:pid>")
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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
def unmark_post_cw(pid, v):
p = get_post(pid)
if p.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION']:
abort(403)
p.cw = False
g.db.add(p)
if p.author_id != v.id:
ma = ModAction(
kind = "unset_cw",
user_id = v.id,
target_post_id = p.id,
)
g.db.add(ma)
2024-02-18 14:04:32 +00:00
send_repeatable_notification(p.author_id, f"{admin_str(v)} removed the child warning from [{p.title}](/post/{p.id})")
return {"message": "The child warning has been removed from the post!"}
@app.post("/distinguish/<int:post_id>")
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@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
def distinguish_post(post_id, v):
post = get_post(post_id)
if v.admin_level < PERMS['POST_COMMENT_DISTINGUISH'] and not v.mods_hole(post.hole):
abort(403, "You can't distinguish this post")
if post.distinguished:
post.distinguished = False
kind = 'undistinguish_post'
else:
post.distinguished = True
kind = 'distinguish_post'
g.db.add(post)
ma = ModAction(
kind=kind,
user_id=v.id,
target_post_id=post.id
)
g.db.add(ma)
if post.distinguished: return {"message": "Post distinguished!"}
else: return {"message": "Post undistinguished!"}