CRUD syscalls for attachments
This commit is contained in:
parent
24be260a34
commit
9415624b93
@ -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<PageMeta[]> {
|
||||
return syscall("space.listPages", unfiltered);
|
||||
}
|
||||
|
||||
export async function getPageMeta(
|
||||
name: string
|
||||
): Promise<{ text: string; meta: PageMeta }> {
|
||||
export async function getPageMeta(name: string): Promise<PageMeta> {
|
||||
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);
|
||||
}
|
||||
|
||||
export async function deletePage(name: string): Promise<PageMeta> {
|
||||
export async function deletePage(name: string): Promise<void> {
|
||||
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);
|
||||
}
|
||||
|
@ -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<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);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
@ -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);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user