refactor: use more generic resource system
Some checks failed
Deploy to SFTP Server / build (push) Failing after 7m2s
Some checks failed
Deploy to SFTP Server / build (push) Failing after 7m2s
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user