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