1
0
silverbullet/server/syscalls/space.ts

64 lines
1.8 KiB
TypeScript
Raw Normal View History

import { AttachmentMeta, PageMeta } from "../../common/types.ts";
import { SysCallMapping } from "../../plugos/system.ts";
import { Space } from "../../common/spaces/space.ts";
2022-09-12 12:50:37 +00:00
import {
FileData,
FileEncoding,
} from "../../common/spaces/space_primitives.ts";
2022-03-28 13:25:05 +00:00
export default (space: Space): SysCallMapping => {
2022-03-28 13:25:05 +00:00
return {
2022-10-14 13:11:33 +00:00
"space.listPages": (): PageMeta[] => {
2022-09-12 12:50:37 +00:00
return [...space.listPages()];
2022-03-28 13:25:05 +00:00
},
"space.readPage": async (
2022-10-14 13:11:33 +00:00
_ctx,
name: string,
2022-10-14 13:11:33 +00:00
): Promise<string> => {
return (await space.readPage(name)).text;
2022-03-28 13:25:05 +00:00
},
2022-10-14 13:11:33 +00:00
"space.getPageMeta": (_ctx, name: string): Promise<PageMeta> => {
2022-08-08 11:33:20 +00:00
return space.getPageMeta(name);
},
2022-10-14 13:11:33 +00:00
"space.writePage": (
_ctx,
name: string,
text: string,
): Promise<PageMeta> => {
return space.writePage(name, text);
2022-03-28 13:25:05 +00:00
},
2022-10-14 13:11:33 +00:00
"space.deletePage": (_ctx, name: string) => {
return space.deletePage(name);
2022-03-28 13:25:05 +00:00
},
2022-10-14 13:11:33 +00:00
"space.listPlugs": (): Promise<string[]> => {
return space.listPlugs();
2022-09-12 12:50:37 +00:00
},
2022-10-14 13:11:33 +00:00
"space.listAttachments": async (): Promise<AttachmentMeta[]> => {
2022-09-12 12:50:37 +00:00
return await space.fetchAttachmentList();
2022-09-05 11:36:04 +00:00
},
"space.readAttachment": async (
2022-10-14 13:11:33 +00:00
_ctx,
name: string,
2022-10-14 13:11:33 +00:00
): Promise<FileData> => {
return (await space.readAttachment(name, "dataurl")).data;
2022-09-05 11:36:04 +00:00
},
"space.getAttachmentMeta": async (
2022-10-14 13:11:33 +00:00
_ctx,
name: string,
2022-09-05 11:36:04 +00:00
): Promise<AttachmentMeta> => {
return await space.getAttachmentMeta(name);
},
"space.writeAttachment": async (
2022-10-14 13:11:33 +00:00
_ctx,
2022-09-05 11:36:04 +00:00
name: string,
2022-09-12 12:50:37 +00:00
encoding: FileEncoding,
data: string,
2022-09-05 11:36:04 +00:00
): Promise<AttachmentMeta> => {
2022-09-12 12:50:37 +00:00
return await space.writeAttachment(name, encoding, data);
2022-09-05 11:36:04 +00:00
},
2022-10-14 13:11:33 +00:00
"space.deleteAttachment": async (_ctx, name: string) => {
2022-09-05 11:36:04 +00:00
await space.deleteAttachment(name);
},
2022-03-28 13:25:05 +00:00
};
};