refactor: use more generic resource system
Some checks failed
Deploy to SFTP Server / build (push) Failing after 7m2s

This commit is contained in:
Max Richter
2025-10-06 00:30:44 +02:00
parent 61251e2c85
commit 06e5126fe0
17 changed files with 1375 additions and 1683 deletions

View File

@@ -1,10 +1,47 @@
export async function listResource(id: string): Promise<any[] | any> {
export type MemoriumFile = {
type: "file";
name: string;
path: string;
modTime: string;
mime: string;
size: string;
content: unknown;
};
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(
`https://marka.max-richter.dev/${id}`,
);
return await response.json();
} catch (error) {
return [];
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);
console.log(_e);
return;
}
}