Files
max-richter.dev/src/helpers/memorium.ts
Max Richter a27e9046c0
Some checks failed
Deploy to SFTP Server / build (push) Has been cancelled
fix: some stuff
2025-10-22 12:58:18 +02:00

47 lines
949 B
TypeScript

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;
export async function listResource(
id: string,
): Promise<MemoriumEntry | undefined> {
const url = `https://marka.max-richter.dev/${id}`;
console.log("Fetching: ", url);
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;
}
}