1
0

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

View File

@ -1,13 +1,11 @@
import { syscall } from "./syscall"; import { syscall } from "./syscall";
import { PageMeta } from "../common/types"; import { AttachmentMeta, PageMeta } from "../common/types";
export async function listPages(unfiltered = false): Promise<PageMeta[]> { export async function listPages(unfiltered = false): Promise<PageMeta[]> {
return syscall("space.listPages", unfiltered); return syscall("space.listPages", unfiltered);
} }
export async function getPageMeta( export async function getPageMeta(name: string): Promise<PageMeta> {
name: string
): Promise<{ text: string; meta: PageMeta }> {
return syscall("space.getPageMeta", name); return syscall("space.getPageMeta", name);
} }
@ -21,6 +19,31 @@ export async function writePage(name: string, text: string): Promise<PageMeta> {
return syscall("space.writePage", name, text); return syscall("space.writePage", name, text);
} }
export async function deletePage(name: string): Promise<PageMeta> { export async function deletePage(name: string): Promise<void> {
return syscall("space.deletePage", name); return syscall("space.deletePage", name);
} }
export async function listAttachments(): Promise<PageMeta[]> {
return syscall("space.listAttachments");
}
export async function getAttachmentMeta(name: string): Promise<AttachmentMeta> {
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<AttachmentMeta> {
return syscall("space.writeAttachment", name, buffer);
}
export async function deleteAttachment(name: string): Promise<void> {
return syscall("space.deleteAttachment", name);
}

View File

@ -1,4 +1,4 @@
import { PageMeta } from "@silverbulletmd/common/types"; import { AttachmentMeta, PageMeta } from "@silverbulletmd/common/types";
import { SysCallMapping } from "@plugos/plugos/system"; import { SysCallMapping } from "@plugos/plugos/system";
import { Space } from "@silverbulletmd/common/spaces/space"; import { Space } from "@silverbulletmd/common/spaces/space";
@ -26,5 +26,30 @@ export default (space: Space): SysCallMapping => {
"space.deletePage": async (ctx, name: string) => { "space.deletePage": async (ctx, name: string) => {
return space.deletePage(name); return space.deletePage(name);
}, },
"space.listAttachments": async (ctx): Promise<AttachmentMeta[]> => {
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<AttachmentMeta> => {
return await space.getAttachmentMeta(name);
},
"space.writeAttachment": async (
ctx,
name: string,
buffer: ArrayBuffer
): Promise<AttachmentMeta> => {
return await space.writeAttachment(name, buffer);
},
"space.deleteAttachment": async (ctx, name: string) => {
await space.deleteAttachment(name);
},
}; };
}; };

View File

@ -1,6 +1,6 @@
import { Editor } from "../editor"; import { Editor } from "../editor";
import { SysCallMapping } from "@plugos/plugos/system"; 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 { export function spaceSyscalls(editor: Editor): SysCallMapping {
return { return {
@ -33,5 +33,30 @@ export function spaceSyscalls(editor: Editor): SysCallMapping {
console.log("Deleting page"); console.log("Deleting page");
await editor.space.deletePage(name); 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);
},
}; };
} }