fix: normalize unicode escape sequences and reformat multi-line expressions across codebase

This commit is contained in:
2026-06-09 16:48:08 +00:00
parent 66dfda88bc
commit c4f2937415
175 changed files with 12660 additions and 4175 deletions
+56 -26
View File
@@ -15,9 +15,19 @@ router = APIRouter()
BOOKMARKABLE: set[str] = {"post", "gist", "project", "news"}
TABLE_BY_TYPE: dict[str, str] = {"post": "posts", "gist": "gists", "project": "projects", "news": "news"}
TABLE_BY_TYPE: dict[str, str] = {
"post": "posts",
"gist": "gists",
"project": "projects",
"news": "news",
}
LABEL_BY_TYPE: dict[str, str] = {"post": "Post", "gist": "Gist", "project": "Project", "news": "Article"}
LABEL_BY_TYPE: dict[str, str] = {
"post": "Post",
"gist": "Gist",
"project": "Project",
"news": "Article",
}
@router.get("/saved", response_class=HTMLResponse)
@@ -45,22 +55,36 @@ async def saved_page(request: Request, before: str = None):
if not obj:
continue
title = obj.get("title") or (obj.get("content", "") or "")[:80] or "Untitled"
items.append({
"target_type": row["target_type"],
"type_label": LABEL_BY_TYPE.get(row["target_type"], row["target_type"].title()),
"title": title,
"url": resolve_object_url(row["target_type"], row["target_uid"]),
"time_ago": time_ago(row["created_at"]),
})
items.append(
{
"target_type": row["target_type"],
"type_label": LABEL_BY_TYPE.get(
row["target_type"], row["target_type"].title()
),
"title": title,
"url": resolve_object_url(row["target_type"], row["target_uid"]),
"time_ago": time_ago(row["created_at"]),
}
)
seo_ctx = base_seo_context(request, title="Saved", description="Your saved content on DevPlace.", robots="noindex,nofollow")
return respond(request, "saved.html", {
**seo_ctx,
"request": request,
"user": user,
"items": items,
"next_cursor": next_cursor,
}, model=SavedOut)
seo_ctx = base_seo_context(
request,
title="Saved",
description="Your saved content on DevPlace.",
robots="noindex,nofollow",
)
return respond(
request,
"saved.html",
{
**seo_ctx,
"request": request,
"user": user,
"items": items,
"next_cursor": next_cursor,
},
model=SavedOut,
)
@router.post("/{target_type}/{target_uid}")
@@ -70,20 +94,26 @@ async def toggle_bookmark(request: Request, target_type: str, target_uid: str):
return JSONResponse({"error": "Invalid target"}, status_code=400)
bookmarks = get_table("bookmarks")
existing = bookmarks.find_one(user_uid=user["uid"], target_uid=target_uid, target_type=target_type)
existing = bookmarks.find_one(
user_uid=user["uid"], target_uid=target_uid, target_type=target_type
)
if existing:
bookmarks.delete(id=existing["id"])
saved = False
else:
bookmarks.insert({
"uid": generate_uid(),
"user_uid": user["uid"],
"target_uid": target_uid,
"target_type": target_type,
"created_at": datetime.now(timezone.utc).isoformat(),
})
bookmarks.insert(
{
"uid": generate_uid(),
"user_uid": user["uid"],
"target_uid": target_uid,
"target_type": target_type,
"created_at": datetime.now(timezone.utc).isoformat(),
}
)
saved = True
if request.headers.get("x-requested-with") == "fetch":
return JSONResponse({"saved": saved})
return RedirectResponse(url=request.headers.get("Referer", "/feed"), status_code=302)
return RedirectResponse(
url=request.headers.get("Referer", "/feed"), status_code=302
)