add auth token cleanup logic

This commit is contained in:
2025-05-21 23:27:17 +01:00
parent 2c292db0fc
commit 255acfcb32
5 changed files with 69 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
import type { Bookmark, BookmarkTag } from "@markone/core/bookmark"
import type { Bookmark, BookmarkId, BookmarkTag } from "@markone/core/bookmark"
import type { User } from "@markone/core/user"
import { Readability } from "@mozilla/readability"
import { JSDOM } from "jsdom"
@@ -72,6 +72,14 @@ function findBookmark(id: string, user: User): Bookmark | null {
return bookmark
}
function deleteBookmark(id: BookmarkId, user: User) {
db.query("DELETE FROM bookmarks WHERE user_id = $userId AND id = $id").run({
id,
userId: user.id,
})
db.query("DELETE FROM bookmark_tags WHERE bookmark_id = ?").run(id)
}
async function cacheContent(url: string): Promise<CachedContent | null> {
const res = await fetch(url).catch(() => {
throw new LinkUnreachable()
@@ -162,6 +170,7 @@ function findBookmarkTags(bookmark: Bookmark): BookmarkTag[] {
export {
insertDemoBookmarks,
insertBookmark,
deleteBookmark,
findBookmark,
findBookmarkCachedContent,
cacheContent,