import { MARKA_API_KEY } from "./env.ts"; 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(); }