import { getCookie } from "@lib/string.ts"; import { MenuEntry } from "../types.ts"; import { BookResource } from "@lib/marka/schema.ts"; import { fetchStream } from "@lib/helpers.ts"; export const enhanceBookInfo: MenuEntry = { title: "Enhance Book Info", meta: "Update metadata and content from Hardcover", icon: "IconWand", cb: (state, context) => { state.activeState.value = "loading"; const book = context as BookResource; fetchStream( `/api/books/enhance/${book.name}/`, (chunk) => { if (chunk.type === "error") { state.activeState.value = "error"; state.loadingText.value = chunk.message; } else if (chunk.type == "finished") { state.loadingText.value = "Finished"; setTimeout(() => { state.visible.value = false; state.activeState.value = "normal"; globalThis.location.reload(); }, 500); } else { state.loadingText.value = chunk.message; } }, { method: "POST" }, ); }, visible: () => { const loc = globalThis["location"]; if (!getCookie("session_cookie")) return false; return (loc?.pathname?.includes("book") && !loc.pathname.endsWith("books")); }, };