Files
memorium/islands/KMenu/commands/enhance_book_infos.ts
Max Richter c232794cc0 feat: add Book type to schema and sidebar
- Add BookContentSchema with headline, subtitle, bookBody, reviewBody fields
- Add BookResource type and update GenericResourceSchema
- Add books to sidebar navigation with Bookmark Tabs icon
2026-02-10 18:17:32 +01:00

42 lines
1.2 KiB
TypeScript

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"));
},
};