feat: allow creating articles with marka

This commit is contained in:
Max Richter
2025-10-31 15:26:34 +01:00
parent dfa3826ec5
commit 7e60327940
12 changed files with 332 additions and 210 deletions

View File

@@ -1,3 +1,5 @@
import { MARKA_API_KEY } from "./env.ts";
export const resources = {
"home": {
emoji: "House with Garden.png",
@@ -31,13 +33,37 @@ export const resources = {
},
} 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(
`https://marka.max-richter.dev/resources/${resource}`,
`${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();
}