import { MARKA_API_KEY } from "./env.ts"; export const resources = { "home": { emoji: "House with Garden.png", name: "Home", link: "/", prefix: "", }, "recipe": { emoji: "Fork and Knife with Plate.png", name: "Recipes", link: "/recipes", prefix: "Recipes/", }, "movie": { emoji: "Popcorn.png", name: "Movies", link: "/movies", prefix: "Media/movies/", }, "article": { emoji: "Writing Hand Medium-Light Skin Tone.png", name: "Articles", link: "/articles", prefix: "Media/articles/", }, "series": { emoji: "Television.png", name: "Series", link: "/series", prefix: "Media/series/", }, } as const; const url = `https://marka.max-richter.dev/resources`; //const url = "http://localhost:8080/resources"; export async function fetchResource(resource: string) { try { const response = await fetch( `${url}/${resource}`, ); return response.json(); } catch (_e) { return []; } } export async function createResource( path: string, content: string | object | ArrayBuffer, ) { const isJson = typeof content === "object"; const fetchUrl = `${url}/${path}`; console.log("Creating resource", { fetchUrl, content, isJson }); const response = await fetch(fetchUrl, { method: "POST", headers: { "Content-Type": isJson ? "application/json" : "", "Authentication": MARKA_API_KEY, }, body: isJson ? JSON.stringify(content) : content, }); if (!response.ok) { throw new Error(`Failed to create resource: ${response.status}`); } return response.json(); }