export type MemoriumFile = { type: "file"; name: string; path: string; modTime: string; mime: string; size: string; content: any; }; export type MemoriumDir = { type: "dir"; name: string; path: string; modTime: string; mime: string; size: string; content: MemoriumEntry[]; }; export type MemoriumEntry = MemoriumFile | MemoriumDir; const SERVER_URL = "https://marka.max-richter.dev"; //const SERVER_URL = "http://localhost:8080"; export async function listResource( id: string, ): Promise { const url = `${SERVER_URL}/resources/${id}`; try { const response = await fetch(url); if (response.ok) { const json = await response.json(); if (json.type == "dir") { return { ...json, content: json.content.filter((res) => res.mime === "application/markdown" ), }; } return json; } } catch (_e) { console.log("Failed to get: ", url); return; } } export function getImageUrl(input: string): string { if (!input) { return; } if (input.startsWith("https://") || input.startsWith("http://")) { return input; } if (input.startsWith("/")) { return `${SERVER_URL}${input}`; } return `${SERVER_URL}/${input}`; }