2024-02-09 04:00:45 +08:00
|
|
|
import { syscall } from "../syscall.ts";
|
2024-02-29 22:23:05 +08:00
|
|
|
import { AttachmentMeta, FileMeta, PageMeta } from "../types.ts";
|
2022-10-10 20:50:21 +08:00
|
|
|
|
2023-05-24 02:53:53 +08:00
|
|
|
export function listPages(unfiltered = false): Promise<PageMeta[]> {
|
|
|
|
return syscall("space.listPages", unfiltered);
|
|
|
|
}
|
2022-10-10 20:50:21 +08:00
|
|
|
|
2023-05-24 02:53:53 +08:00
|
|
|
export function getPageMeta(name: string): Promise<PageMeta> {
|
|
|
|
return syscall("space.getPageMeta", name);
|
|
|
|
}
|
2022-10-10 20:50:21 +08:00
|
|
|
|
2023-05-24 02:53:53 +08:00
|
|
|
export function readPage(
|
|
|
|
name: string,
|
|
|
|
): Promise<string> {
|
|
|
|
return syscall("space.readPage", name);
|
|
|
|
}
|
2022-10-10 20:50:21 +08:00
|
|
|
|
2023-05-24 02:53:53 +08:00
|
|
|
export function writePage(name: string, text: string): Promise<PageMeta> {
|
|
|
|
return syscall("space.writePage", name, text);
|
|
|
|
}
|
2022-10-10 20:50:21 +08:00
|
|
|
|
2023-05-24 02:53:53 +08:00
|
|
|
export function deletePage(name: string): Promise<void> {
|
|
|
|
return syscall("space.deletePage", name);
|
|
|
|
}
|
2022-10-10 20:50:21 +08:00
|
|
|
|
2023-12-07 01:44:48 +08:00
|
|
|
export function listPlugs(): Promise<FileMeta[]> {
|
2023-05-24 02:53:53 +08:00
|
|
|
return syscall("space.listPlugs");
|
|
|
|
}
|
2022-10-10 20:50:21 +08:00
|
|
|
|
2023-08-20 23:51:00 +08:00
|
|
|
export function listAttachments(): Promise<AttachmentMeta[]> {
|
2023-05-24 02:53:53 +08:00
|
|
|
return syscall("space.listAttachments");
|
|
|
|
}
|
2022-10-10 20:50:21 +08:00
|
|
|
|
2023-05-24 02:53:53 +08:00
|
|
|
export function getAttachmentMeta(name: string): Promise<AttachmentMeta> {
|
|
|
|
return syscall("space.getAttachmentMeta", name);
|
|
|
|
}
|
2023-01-13 22:41:29 +08:00
|
|
|
|
2023-05-24 02:53:53 +08:00
|
|
|
/**
|
|
|
|
* Read an attachment from the space
|
|
|
|
* @param name path of the attachment to read
|
|
|
|
* @returns the attachment data encoded as a data URL
|
|
|
|
*/
|
|
|
|
export function readAttachment(
|
|
|
|
name: string,
|
2023-08-15 13:56:29 +08:00
|
|
|
): Promise<Uint8Array> {
|
2023-05-24 02:53:53 +08:00
|
|
|
return syscall("space.readAttachment", name);
|
|
|
|
}
|
2023-01-13 22:41:29 +08:00
|
|
|
|
2023-05-24 02:53:53 +08:00
|
|
|
/**
|
|
|
|
* Writes an attachment to the space
|
|
|
|
* @param name path of the attachment to write
|
|
|
|
* @param data data itself
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
export function writeAttachment(
|
|
|
|
name: string,
|
2023-05-26 20:04:32 +08:00
|
|
|
data: Uint8Array,
|
2023-05-24 02:53:53 +08:00
|
|
|
): Promise<AttachmentMeta> {
|
2023-05-26 20:04:32 +08:00
|
|
|
return syscall("space.writeAttachment", name, data);
|
2022-10-10 20:50:21 +08:00
|
|
|
}
|
2023-01-13 22:41:29 +08:00
|
|
|
|
2023-05-24 02:53:53 +08:00
|
|
|
/**
|
|
|
|
* Deletes an attachment from the space
|
|
|
|
* @param name path of the attachment to delete
|
|
|
|
*/
|
|
|
|
export function deleteAttachment(name: string): Promise<void> {
|
|
|
|
return syscall("space.deleteAttachment", name);
|
|
|
|
}
|
2023-08-20 23:51:00 +08:00
|
|
|
|
|
|
|
// FS
|
|
|
|
export function listFiles(): Promise<FileMeta[]> {
|
|
|
|
return syscall("space.listFiles");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function readFile(name: string): Promise<Uint8Array> {
|
|
|
|
return syscall("space.readFile", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFileMeta(name: string): Promise<FileMeta> {
|
|
|
|
return syscall("space.getFileMeta", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function writeFile(
|
|
|
|
name: string,
|
|
|
|
data: Uint8Array,
|
|
|
|
): Promise<FileMeta> {
|
|
|
|
return syscall("space.writeFile", name, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deleteFile(name: string): Promise<void> {
|
|
|
|
return syscall("space.deleteFile", name);
|
|
|
|
}
|