pull/146/head
Aevann 2023-05-04 22:55:08 +03:00
parent 0a7a56e056
commit d0cc9a4822
3 changed files with 13 additions and 22 deletions

View File

@ -61,7 +61,6 @@ def after_request(response:Response):
if response.status_code < 400:
if hasattr(g, 'v') and g.v:
user_id = g.v.id
_set_cloudflare_cookie(response)
_commit_and_close_db()
if request.method == "POST" and not request.path.startswith('/casino/twentyone/'):
@ -77,26 +76,6 @@ def teardown_request(error):
_rollback_and_close_db()
stdout.flush()
def _set_cloudflare_cookie(response:Response) -> None:
if not g.desires_auth: return
if IS_LOCALHOST: return
logged_in = bool(getattr(g, 'v', None))
if not logged_in and request.cookies.get("logged_in"):
response.delete_cookie(
"logged_in",
domain=f'.{SITE}',
samesite="Lax",
)
elif logged_in and not request.cookies.get("logged_in"):
response.set_cookie(
"logged_in",
"True",
max_age=SESSION_LIFETIME,
samesite="Lax",
domain=f'.{SITE}',
)
def _commit_and_close_db() -> bool:
if not getattr(g, 'db', None): return False
g.db.commit()

View File

@ -387,6 +387,9 @@ def comment(v:User):
g.db.flush()
if c.parent_submission:
cache.delete(f'post_{c.parent_submission}')
if v.client: return c.json(db=g.db)
return {"comment": render_template("comments.html", v=v, comments=[c])}

View File

@ -95,6 +95,10 @@ def post_id(pid, anything=None, v=None, sub=None):
if g.is_api_or_xhr: abort(451, "Must be 18+ to view")
return render_template("errors/nsfw.html", v=v)
if not v and not request.values.get("sort"):
result = cache.get(f'post_{p.id}')
if result: return result
if p.new: defaultsortingcomments = 'new'
elif v: defaultsortingcomments = v.defaultsortingcomments
else: defaultsortingcomments = "hot"
@ -173,10 +177,15 @@ def post_id(pid, anything=None, v=None, sub=None):
and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or p.author_id == v.id)):
template = "submission_banned.html"
return render_template(template, v=v, p=p, ids=list(ids),
result = render_template(template, v=v, p=p, ids=list(ids),
sort=sort, render_replies=True, offset=offset, sub=p.subr,
fart=get_setting('fart_mode'))
if not v and not request.values.get("sort"):
cache.set(f'post_{p.id}', result)
return result
@app.get("/view_more/<int:pid>/<sort>/<offset>")
@limiter.limit(DEFAULT_RATELIMIT)
@auth_desired_with_logingate