2022-10-10 20:50:21 +08:00
|
|
|
import { AttachmentMeta, PageMeta } from "../../common/types.ts";
|
|
|
|
import { SysCallMapping } from "../../plugos/system.ts";
|
|
|
|
import { Space } from "../../common/spaces/space.ts";
|
2022-09-12 20:50:37 +08:00
|
|
|
import {
|
|
|
|
FileData,
|
|
|
|
FileEncoding,
|
2022-10-10 20:50:21 +08:00
|
|
|
} from "../../common/spaces/space_primitives.ts";
|
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-09-12 20:50:37 +08:00
|
|
|
"space.listPages": async (): Promise<PageMeta[]> => {
|
|
|
|
return [...space.listPages()];
|
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,
|
2022-10-10 20:50:21 +08:00
|
|
|
name: string,
|
2022-03-28 21:25:05 +08:00
|
|
|
): 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,
|
2022-10-10 20:50:21 +08:00
|
|
|
text: string,
|
2022-04-04 00:42:12 +08:00
|
|
|
): 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-12 20:50:37 +08:00
|
|
|
"space.listPlugs": async (): Promise<string[]> => {
|
|
|
|
return await space.listPlugs();
|
|
|
|
},
|
2022-09-05 19:36:04 +08:00
|
|
|
"space.listAttachments": async (ctx): Promise<AttachmentMeta[]> => {
|
2022-09-12 20:50:37 +08:00
|
|
|
return await space.fetchAttachmentList();
|
2022-09-05 19:36:04 +08:00
|
|
|
},
|
|
|
|
"space.readAttachment": async (
|
|
|
|
ctx,
|
2022-10-10 20:50:21 +08:00
|
|
|
name: string,
|
2022-09-12 20:50:37 +08:00
|
|
|
): Promise<{ data: FileData; meta: AttachmentMeta }> => {
|
2022-09-05 22:15:01 +08:00
|
|
|
return await space.readAttachment(name, "dataurl");
|
2022-09-05 19:36:04 +08:00
|
|
|
},
|
|
|
|
"space.getAttachmentMeta": async (
|
|
|
|
ctx,
|
2022-10-10 20:50:21 +08:00
|
|
|
name: string,
|
2022-09-05 19:36:04 +08:00
|
|
|
): Promise<AttachmentMeta> => {
|
|
|
|
return await space.getAttachmentMeta(name);
|
|
|
|
},
|
|
|
|
"space.writeAttachment": async (
|
|
|
|
ctx,
|
|
|
|
name: string,
|
2022-09-12 20:50:37 +08:00
|
|
|
encoding: FileEncoding,
|
2022-10-10 20:50:21 +08:00
|
|
|
data: string,
|
2022-09-05 19:36:04 +08:00
|
|
|
): Promise<AttachmentMeta> => {
|
2022-09-12 20:50:37 +08:00
|
|
|
return await space.writeAttachment(name, encoding, 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
|
|
|
};
|
|
|
|
};
|