1
0
silverbullet/server/syscalls/space.ts

64 lines
1.9 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-09-12 12:50:37 +00:00
"space.listPages": async (): Promise<PageMeta[]> => {
return [...space.listPages()];
2022-03-28 13:25:05 +00:00
},
"space.readPage": async (
2022-03-28 13:25:05 +00:00
ctx,
name: string,
2022-03-28 13:25:05 +00:00
): Promise<{ text: string; meta: PageMeta }> => {
return space.readPage(name);
2022-03-28 13:25:05 +00:00
},
2022-08-08 11:33:20 +00:00
"space.getPageMeta": async (ctx, name: string): Promise<PageMeta> => {
return space.getPageMeta(name);
},
"space.writePage": async (
ctx,
name: string,
text: string,
): Promise<PageMeta> => {
return space.writePage(name, text);
2022-03-28 13:25:05 +00:00
},
"space.deletePage": async (ctx, name: string) => {
return space.deletePage(name);
2022-03-28 13:25:05 +00:00
},
2022-09-12 12:50:37 +00:00
"space.listPlugs": async (): Promise<string[]> => {
return await space.listPlugs();
},
2022-09-05 11:36:04 +00:00
"space.listAttachments": async (ctx): 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 (
ctx,
name: string,
2022-09-12 12:50:37 +00:00
): Promise<{ data: FileData; meta: AttachmentMeta }> => {
2022-09-05 14:15:01 +00:00
return await space.readAttachment(name, "dataurl");
2022-09-05 11:36:04 +00:00
},
"space.getAttachmentMeta": async (
ctx,
name: string,
2022-09-05 11:36:04 +00:00
): Promise<AttachmentMeta> => {
return await space.getAttachmentMeta(name);
},
"space.writeAttachment": async (
ctx,
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
},
"space.deleteAttachment": async (ctx, name: string) => {
await space.deleteAttachment(name);
},
2022-03-28 13:25:05 +00:00
};
};