CRUD syscalls for attachments

This commit is contained in:
Zef Hemel
2022-09-05 13:36:04 +02:00
parent 24be260a34
commit 9415624b93
3 changed files with 80 additions and 7 deletions
+26 -1
View File
@@ -1,6 +1,6 @@
import { Editor } from "../editor";
import { SysCallMapping } from "@plugos/plugos/system";
import { PageMeta } from "@silverbulletmd/common/types";
import { AttachmentMeta, PageMeta } from "@silverbulletmd/common/types";
export function spaceSyscalls(editor: Editor): SysCallMapping {
return {
@@ -33,5 +33,30 @@ export function spaceSyscalls(editor: Editor): SysCallMapping {
console.log("Deleting page");
await editor.space.deletePage(name);
},
"space.listAttachments": async (ctx): Promise<AttachmentMeta[]> => {
return [...(await editor.space.fetchAttachmentList()).attachments];
},
"space.readAttachment": async (
ctx,
name: string
): Promise<{ buffer: ArrayBuffer; meta: AttachmentMeta }> => {
return await editor.space.readAttachment(name);
},
"space.getAttachmentMeta": async (
ctx,
name: string
): Promise<AttachmentMeta> => {
return await editor.space.getAttachmentMeta(name);
},
"space.writeAttachment": async (
ctx,
name: string,
buffer: ArrayBuffer
): Promise<AttachmentMeta> => {
return await editor.space.writeAttachment(name, buffer);
},
"space.deleteAttachment": async (ctx, name: string) => {
await editor.space.deleteAttachment(name);
},
};
}