47 lines
949 B
TypeScript
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;
|
|
}
|
|
}
|