2022-10-10 12:50:21 +00:00
|
|
|
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,
|
2022-10-10 12:50:21 +00:00
|
|
|
} from "../../common/spaces/space_primitives.ts";
|
2022-03-28 13:25:05 +00:00
|
|
|
|
2023-01-13 14:41:29 +00:00
|
|
|
import { FileMeta as PlugFileMeta } from "../../plug-api/plugos-syscall/types.ts";
|
|
|
|
|
2022-04-08 15:46:09 +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
|
|
|
},
|
2022-04-03 16:42:12 +00:00
|
|
|
"space.readPage": async (
|
2022-10-14 13:11:33 +00:00
|
|
|
_ctx,
|
2022-10-10 12:50:21 +00:00
|
|
|
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,
|
2022-04-03 16:42:12 +00:00
|
|
|
name: string,
|
2022-10-10 12:50:21 +00:00
|
|
|
text: string,
|
2022-04-03 16:42:12 +00:00
|
|
|
): Promise<PageMeta> => {
|
2022-04-08 15:46:09 +00:00
|
|
|
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) => {
|
2022-04-08 15:46:09 +00:00
|
|
|
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,
|
2022-10-10 12:50:21 +00:00
|
|
|
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,
|
2022-10-10 12:50:21 +00:00
|
|
|
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,
|
2022-10-10 12:50:21 +00:00
|
|
|
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);
|
|
|
|
},
|
2023-01-13 14:41:29 +00:00
|
|
|
|
|
|
|
"space.listFiles": (_ctx, path: string): Promise<PlugFileMeta[]> => {
|
|
|
|
return space.listFiles(path);
|
|
|
|
},
|
2022-03-28 13:25:05 +00:00
|
|
|
};
|
|
|
|
};
|