From 01f671d19a2c504b54e1ffffc70927c1c33cad10 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 3 Mar 2023 03:53:04 +0200 Subject: [PATCH] remove the .json endpoints --- files/routes/users.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/files/routes/users.py b/files/routes/users.py index 37a175bd8..c3a83c581 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -798,7 +798,6 @@ def userpagelisting(user:User, site=None, v=None, page:int=1, sort="new", t="all return [x[0] for x in posts] @app.get("/@") -@app.get("/@.json") @limiter.limit(DEFAULT_RATELIMIT) @auth_desired_with_logingate def u_username_wall(v:Optional[User], username:str): @@ -807,7 +806,7 @@ def u_username_wall(v:Optional[User], username:str): return redirect(f"/@{u.username}") if v and hasattr(u, 'is_blocking') and u.is_blocking: - if g.is_api_or_xhr or request.path.endswith(".json"): + if g.is_api_or_xhr: abort(403, f"You are blocking @{u.username}.") return render_template("userpage/blocking.html", u=u, v=v), 403 @@ -845,14 +844,13 @@ def u_username_wall(v:Optional[User], username:str): next_exists = (len(comments) > PAGE_SIZE) comments = comments[:PAGE_SIZE] - if (v and v.client) or request.path.endswith(".json"): + if v and v.client: return {"data": [c.json(g.db) for c in comments]} return render_template("userpage/wall.html", u=u, v=v, listing=comments, page=page, next_exists=next_exists, is_following=is_following, standalone=True, render_replies=True, wall=True) @app.get("/@/wall/comment/") -@app.get("/@/wall/comment/.json") @limiter.limit(DEFAULT_RATELIMIT) @auth_desired_with_logingate def u_username_wall_comment(v:User, username:str, cid): @@ -863,7 +861,7 @@ def u_username_wall_comment(v:User, username:str, cid): u = comment.wall_user if v and hasattr(u, 'is_blocking') and u.is_blocking: - if g.is_api_or_xhr or request.path.endswith(".json"): + if g.is_api_or_xhr: abort(403, f"You are blocking @{u.username}.") return render_template("userpage/blocking.html", u=u, v=v), 403 @@ -904,7 +902,6 @@ def u_username_wall_comment(v:User, username:str, cid): @app.get("/@/posts") -@app.get("/@/posts.json") @limiter.limit(DEFAULT_RATELIMIT) @auth_desired_with_logingate def u_username(v:Optional[User], username:str): @@ -913,14 +910,14 @@ def u_username(v:Optional[User], username:str): return redirect(SITE_FULL + request.full_path.replace(username, u.username)) if v and hasattr(u, 'is_blocking') and u.is_blocking: - if g.is_api_or_xhr or request.path.endswith(".json"): + if g.is_api_or_xhr: abort(403, f"You are blocking @{u.username}.") return render_template("userpage/blocking.html", u=u, v=v), 403 is_following = v and u.has_follower(v) if not u.is_visible_to(v): - if g.is_api_or_xhr or request.path.endswith(".json"): + if g.is_api_or_xhr: abort(403, f"@{u.username}'s userpage is private") return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403 @@ -953,7 +950,7 @@ def u_username(v:Optional[User], username:str): listing = get_posts(ids, v=v, eager=True) if u.unban_utc: - if (v and v.client) or request.path.endswith(".json"): + if v and v.client: return {"data": [x.json(g.db) for x in listing]} return render_template("userpage/submissions.html", @@ -967,7 +964,7 @@ def u_username(v:Optional[User], username:str): next_exists=next_exists, is_following=is_following) - if (v and v.client) or request.path.endswith(".json"): + if v and v.client: return {"data": [x.json(g.db) for x in listing]} return render_template("userpage/submissions.html", @@ -982,7 +979,6 @@ def u_username(v:Optional[User], username:str): @app.get("/@/comments") -@app.get("/@/comments.json") @limiter.limit(DEFAULT_RATELIMIT) @auth_desired_with_logingate def u_username_comments(username, v=None): @@ -991,14 +987,14 @@ def u_username_comments(username, v=None): return redirect(f"/@{u.username}/comments") if v and hasattr(u, 'is_blocking') and u.is_blocking: - if g.is_api_or_xhr or request.path.endswith(".json"): + if g.is_api_or_xhr: abort(403, f"You are blocking @{u.username}.") return render_template("userpage/blocking.html", u=u, v=v), 403 is_following = v and u.has_follower(v) if not u.is_visible_to(v): - if g.is_api_or_xhr or request.path.endswith(".json"): + if g.is_api_or_xhr: abort(403, f"@{u.username}'s userpage is private") return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403 @@ -1044,7 +1040,7 @@ def u_username_comments(username, v=None): listing = get_comments(ids, v=v) - if (v and v.client) or request.path.endswith(".json"): + if v and v.client: return {"data": [c.json(g.db) for c in listing]} return render_template("userpage/comments.html", u=u, v=v, listing=listing, page=page, sort=sort, t=t,next_exists=next_exists, is_following=is_following, standalone=True)