implement nav chrome for bookmark previewer

This commit is contained in:
2025-05-14 18:27:41 +01:00
parent c73082b9c9
commit 37cdf30159
14 changed files with 260 additions and 134 deletions

View File

@@ -5,7 +5,7 @@ import { ulid } from "ulid"
import { db } from "~/database.ts"
import { HttpError } from "~/error.ts"
import type { User } from "~/user/user.ts"
import { LinkUnreachable, UnsupportedLink, findBookmarkHtml, cacheWebsite } from "./bookmark.ts"
import { LinkUnreachable, UnsupportedLink, findBookmarkHtml, cacheWebsite, findBookmark } from "./bookmark.ts"
const BOOKMARK_PAGINATION_LIMIT = 100
@@ -46,7 +46,7 @@ LIMIT $limit OFFSET $skip
return Response.json(results, { status: 200 })
}
async function deleteUserBookmark(request: Bun.BunRequest<"/api/bookmark/:id">, user: User) {
async function deleteUserBookmark(request: Bun.BunRequest<"/api/bookmarks/:id">, user: User) {
if (user.id !== DEMO_USER.id) {
const deleteBookmarkQuery = db.query("DELETE FROM bookmarks WHERE user_id = $userId AND id = $id")
const tx = db.transaction(() => {
@@ -127,7 +127,7 @@ VALUES ($id, $bookmarkId, $name)
return Response.json(undefined, { status: 204 })
}
async function fetchBookmark(request: Bun.BunRequest<"/api/bookmark/:id">, user: User) {
async function fetchBookmark(request: Bun.BunRequest<"/api/bookmarks/:id">, user: User) {
switch (request.headers.get("Accept")) {
case "text/html": {
const html = findBookmarkHtml(request.params.id, user)
@@ -141,6 +141,15 @@ async function fetchBookmark(request: Bun.BunRequest<"/api/bookmark/:id">, user:
},
})
}
case "application/json": {
const bookmark = findBookmark(request.params.id, user)
if (bookmark === null) {
throw new HttpError(404)
}
return Response.json(bookmark, { status: 200 })
}
default:
throw new HttpError(400, "UnsupportedAcceptHeader")
}