more intuitive css urls for easier css sharing

pull/200/head
Aevann 2023-09-07 19:16:13 +03:00
parent 71185a94ca
commit 6ee03f143b
4 changed files with 20 additions and 14 deletions

View File

@ -33,7 +33,7 @@ def get_id(username, graceful=False):
return user[0]
def get_user(username, v=None, graceful=False, include_blocks=False, id_only=False):
def get_user(username, v=None, graceful=False, include_blocks=False, attributes=None):
if not username:
if graceful: return None
abort(400, "Empty username.")
@ -42,7 +42,7 @@ def get_user(username, v=None, graceful=False, include_blocks=False, id_only=Fal
if not username:
if graceful: return None
abort(400, "Empty username.")
\
user = g.db.query(
User
).filter(
@ -53,8 +53,8 @@ def get_user(username, v=None, graceful=False, include_blocks=False, id_only=Fal
)
)
if id_only:
user = user.options(load_only(User.id))
if attributes:
user = user.options(load_only(*attributes))
user = user.one_or_none()

View File

@ -156,7 +156,7 @@ def upvoters_downvoters(v, username, username2, cls, vote_cls, vote_dir, templat
if not u.is_visible_to(v): abort(403)
id = u.id
uid = get_user(username2, id_only=True).id
uid = get_user(username2, attributes=[User.id]).id
page = get_page()
@ -219,7 +219,7 @@ def upvoting_downvoting(v, username, username2, cls, vote_cls, vote_dir, templat
if not u.is_visible_to(v): abort(403)
id = u.id
uid = get_user(username2, id_only=True).id
uid = get_user(username2, attributes=[User.id]).id
page = get_page()
@ -522,10 +522,13 @@ def leaderboard_cached(v):
def leaderboard(v):
return render_template("leaderboard.html", v=v, leaderboard_cached=leaderboard_cached(v))
@app.get("/<int:id>/css")
@app.get("/@<username>/css")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
def get_css(id):
css, bg = g.db.query(User.css, User.background).filter_by(id=id).one_or_none()
def get_css(username):
user = get_user(username, attributes=[User.css, User.background])
css = user.css
bg = user.background
if bg:
if not css: css = ''
@ -543,10 +546,13 @@ def get_css(id):
resp.headers["Content-Type"] = "text/css"
return resp
@app.get("/<int:id>/profilecss")
@app.get("/@<username>/profilecss")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
def get_profilecss(id):
css, bg = g.db.query(User.profilecss, User.profile_background).filter_by(id=id).one_or_none()
def get_profilecss(username):
user = get_user(username, attributes=[User.profilecss, User.profile_background])
css = user.profilecss
bg = user.profile_background
if bg:
if not css: css = ''

View File

@ -6,7 +6,7 @@
<link rel="stylesheet" href="{{('css/transparent.css') | asset}}">
{% endif %}
{% if u and (u.profilecss or u.profile_background) and not request.values.get('nocss') and u.can_see_my_shit %}
<link rel="stylesheet" href="/{{u.id}}/profilecss">
<link rel="stylesheet" href="/@{{u.username}}/profilecss">
{% endif %}
{% endblock %}
{% block content %}

View File

@ -109,7 +109,7 @@
{% endif %}
<link rel="stylesheet" href="{{('css/'~v.theme~'.css') | asset}}">
{% if (v.css or v.background) and not request.path.startswith('/settings') %}
<link rel="stylesheet" href="/{{v.id}}/css">
<link rel="stylesheet" href="/@{{v.username}}/css">
{% endif %}
{% if v.themecolor == '30409f' %}
<link rel="stylesheet" href="{{('css/30409f.css') | asset}}">