From 9415624b93bfd9256431f9c1df391f85a14e00a1 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 5 Sep 2022 13:36:04 +0200 Subject: [PATCH] CRUD syscalls for attachments --- packages/plugos-silverbullet-syscall/space.ts | 33 ++++++++++++++++--- packages/server/syscalls/space.ts | 27 ++++++++++++++- packages/web/syscalls/space.ts | 27 ++++++++++++++- 3 files changed, 80 insertions(+), 7 deletions(-) diff --git a/packages/plugos-silverbullet-syscall/space.ts b/packages/plugos-silverbullet-syscall/space.ts index 16d0a68..e67ae7f 100644 --- a/packages/plugos-silverbullet-syscall/space.ts +++ b/packages/plugos-silverbullet-syscall/space.ts @@ -1,13 +1,11 @@ import { syscall } from "./syscall"; -import { PageMeta } from "../common/types"; +import { AttachmentMeta, PageMeta } from "../common/types"; export async function listPages(unfiltered = false): Promise { return syscall("space.listPages", unfiltered); } -export async function getPageMeta( - name: string -): Promise<{ text: string; meta: PageMeta }> { +export async function getPageMeta(name: string): Promise { return syscall("space.getPageMeta", name); } @@ -21,6 +19,31 @@ export async function writePage(name: string, text: string): Promise { return syscall("space.writePage", name, text); } -export async function deletePage(name: string): Promise { +export async function deletePage(name: string): Promise { return syscall("space.deletePage", name); } + +export async function listAttachments(): Promise { + return syscall("space.listAttachments"); +} + +export async function getAttachmentMeta(name: string): Promise { + return syscall("space.getAttachmentMeta", name); +} + +export async function readAttachment( + name: string +): Promise<{ buffer: ArrayBuffer; meta: AttachmentMeta }> { + return syscall("space.readAttachment", name); +} + +export async function writeAttachment( + name: string, + buffer: ArrayBuffer +): Promise { + return syscall("space.writeAttachment", name, buffer); +} + +export async function deleteAttachment(name: string): Promise { + return syscall("space.deleteAttachment", name); +} diff --git a/packages/server/syscalls/space.ts b/packages/server/syscalls/space.ts index 2ad1178..e47caa4 100644 --- a/packages/server/syscalls/space.ts +++ b/packages/server/syscalls/space.ts @@ -1,4 +1,4 @@ -import { PageMeta } from "@silverbulletmd/common/types"; +import { AttachmentMeta, PageMeta } from "@silverbulletmd/common/types"; import { SysCallMapping } from "@plugos/plugos/system"; import { Space } from "@silverbulletmd/common/spaces/space"; @@ -26,5 +26,30 @@ export default (space: Space): SysCallMapping => { "space.deletePage": async (ctx, name: string) => { return space.deletePage(name); }, + "space.listAttachments": async (ctx): Promise => { + return [...(await space.fetchAttachmentList()).attachments]; + }, + "space.readAttachment": async ( + ctx, + name: string + ): Promise<{ buffer: ArrayBuffer; meta: AttachmentMeta }> => { + return await space.readAttachment(name); + }, + "space.getAttachmentMeta": async ( + ctx, + name: string + ): Promise => { + return await space.getAttachmentMeta(name); + }, + "space.writeAttachment": async ( + ctx, + name: string, + buffer: ArrayBuffer + ): Promise => { + return await space.writeAttachment(name, buffer); + }, + "space.deleteAttachment": async (ctx, name: string) => { + await space.deleteAttachment(name); + }, }; }; diff --git a/packages/web/syscalls/space.ts b/packages/web/syscalls/space.ts index dc45856..299b62c 100644 --- a/packages/web/syscalls/space.ts +++ b/packages/web/syscalls/space.ts @@ -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 => { + 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 => { + return await editor.space.getAttachmentMeta(name); + }, + "space.writeAttachment": async ( + ctx, + name: string, + buffer: ArrayBuffer + ): Promise => { + return await editor.space.writeAttachment(name, buffer); + }, + "space.deleteAttachment": async (ctx, name: string) => { + await editor.space.deleteAttachment(name); + }, }; }