2022-09-05 19:36:04 +08:00
|
|
|
import { AttachmentMeta, PageMeta } from "@silverbulletmd/common/types";
|
2022-04-25 16:33:38 +08:00
|
|
|
import { SysCallMapping } from "@plugos/plugos/system";
|
2022-04-21 20:16:40 +08:00
|
|
|
import { Space } from "@silverbulletmd/common/spaces/space";
|
2022-09-05 22:15:01 +08:00
|
|
|
import { AttachmentData } from "@silverbulletmd/common/spaces/space_primitives";
|
2022-03-28 21:25:05 +08:00
|
|
|
|
2022-04-08 23:46:09 +08:00
|
|
|
export default (space: Space): SysCallMapping => {
|
2022-03-28 21:25:05 +08:00
|
|
|
return {
|
2022-04-27 01:04:36 +08:00
|
|
|
"space.listPages": async (ctx, unfiltered = false): Promise<PageMeta[]> => {
|
|
|
|
return [...space.listPages(unfiltered)];
|
2022-03-28 21:25:05 +08:00
|
|
|
},
|
2022-04-04 00:42:12 +08:00
|
|
|
"space.readPage": async (
|
2022-03-28 21:25:05 +08:00
|
|
|
ctx,
|
|
|
|
name: string
|
|
|
|
): Promise<{ text: string; meta: PageMeta }> => {
|
2022-04-08 23:46:09 +08:00
|
|
|
return space.readPage(name);
|
2022-03-28 21:25:05 +08:00
|
|
|
},
|
2022-08-08 19:33:20 +08:00
|
|
|
"space.getPageMeta": async (ctx, name: string): Promise<PageMeta> => {
|
|
|
|
return space.getPageMeta(name);
|
|
|
|
},
|
2022-04-04 00:42:12 +08:00
|
|
|
"space.writePage": async (
|
|
|
|
ctx,
|
|
|
|
name: string,
|
|
|
|
text: string
|
|
|
|
): Promise<PageMeta> => {
|
2022-04-08 23:46:09 +08:00
|
|
|
return space.writePage(name, text);
|
2022-03-28 21:25:05 +08:00
|
|
|
},
|
2022-04-04 00:42:12 +08:00
|
|
|
"space.deletePage": async (ctx, name: string) => {
|
2022-04-08 23:46:09 +08:00
|
|
|
return space.deletePage(name);
|
2022-03-28 21:25:05 +08:00
|
|
|
},
|
2022-09-05 19:36:04 +08:00
|
|
|
"space.listAttachments": async (ctx): Promise<AttachmentMeta[]> => {
|
|
|
|
return [...(await space.fetchAttachmentList()).attachments];
|
|
|
|
},
|
|
|
|
"space.readAttachment": async (
|
|
|
|
ctx,
|
|
|
|
name: string
|
2022-09-05 22:15:01 +08:00
|
|
|
): Promise<{ data: AttachmentData; meta: AttachmentMeta }> => {
|
|
|
|
return await space.readAttachment(name, "dataurl");
|
2022-09-05 19:36:04 +08:00
|
|
|
},
|
|
|
|
"space.getAttachmentMeta": async (
|
|
|
|
ctx,
|
|
|
|
name: string
|
|
|
|
): Promise<AttachmentMeta> => {
|
|
|
|
return await space.getAttachmentMeta(name);
|
|
|
|
},
|
|
|
|
"space.writeAttachment": async (
|
|
|
|
ctx,
|
|
|
|
name: string,
|
2022-09-05 22:15:01 +08:00
|
|
|
data: string
|
2022-09-05 19:36:04 +08:00
|
|
|
): Promise<AttachmentMeta> => {
|
2022-09-05 22:15:01 +08:00
|
|
|
return await space.writeAttachment(name, data);
|
2022-09-05 19:36:04 +08:00
|
|
|
},
|
|
|
|
"space.deleteAttachment": async (ctx, name: string) => {
|
|
|
|
await space.deleteAttachment(name);
|
|
|
|
},
|
2022-03-28 21:25:05 +08:00
|
|
|
};
|
|
|
|
};
|