Refactoring

This commit is contained in:
Zef Hemel
2023-08-20 17:51:00 +02:00
parent 75bdd6390b
commit a94724768e
34 changed files with 226 additions and 47 deletions
+1 -1
View File
@@ -1,5 +1,4 @@
import { EditorView, syntaxTree, ViewPlugin, ViewUpdate } from "../deps.ts";
import { maximumAttachmentSize } from "../../common/types.ts";
import { Client } from "../client.ts";
// We use turndown to convert HTML to Markdown
@@ -18,6 +17,7 @@ import {
nodeAtPos,
} from "../../plug-api/lib/tree.ts";
import { folderName, resolve } from "../../common/path.ts";
import { maximumAttachmentSize } from "../constants.ts";
const turndownService = new TurndownService({
hr: "---",
+1
View File
@@ -0,0 +1 @@
export const maximumAttachmentSize = 1024 * 1024 * 10; // 10MB
+1 -1
View File
@@ -2,7 +2,7 @@ import Dexie from "https://esm.sh/v120/dexie@3.2.2/dist/dexie.js";
import type { FileContent } from "../common/spaces/indexeddb_space_primitives.ts";
import { simpleHash } from "../common/crypto.ts";
import type { FileMeta } from "../common/types.ts";
import { FileMeta } from "$sb/types.ts";
const CACHE_NAME = "{{CACHE_NAME}}";
+1 -1
View File
@@ -1,11 +1,11 @@
import { SpacePrimitives } from "../common/spaces/space_primitives.ts";
import { FileMeta } from "../common/types.ts";
import { EventEmitter } from "../plugos/event.ts";
import { plugPrefix } from "../common/spaces/constants.ts";
import { safeRun } from "../common/util.ts";
import { AttachmentMeta, PageMeta } from "./types.ts";
import { throttle } from "../common/async_util.ts";
import { KVStore } from "../plugos/lib/kv_store.ts";
import { FileMeta } from "$sb/types.ts";
export type SpaceEvents = {
pageCreated: (meta: PageMeta) => void;
+22
View File
@@ -1,6 +1,7 @@
import { Client } from "../client.ts";
import { SysCallMapping } from "../../plugos/system.ts";
import { AttachmentMeta, PageMeta } from "../types.ts";
import { FileMeta } from "$sb/types.ts";
export function spaceSyscalls(editor: Client): SysCallMapping {
return {
@@ -61,5 +62,26 @@ export function spaceSyscalls(editor: Client): SysCallMapping {
"space.deleteAttachment": async (_ctx, name: string) => {
await editor.space.deleteAttachment(name);
},
// FS
"space.listFiles": (): Promise<FileMeta[]> => {
return editor.space.spacePrimitives.fetchFileList();
},
"space.getFileMeta": (_ctx, name: string): Promise<FileMeta> => {
return editor.space.spacePrimitives.getFileMeta(name);
},
"space.readFile": async (_ctx, name: string): Promise<Uint8Array> => {
return (await editor.space.spacePrimitives.readFile(name)).data;
},
"space.writeFile": (
_ctx,
name: string,
data: Uint8Array,
): Promise<FileMeta> => {
return editor.space.spacePrimitives.writeFile(name, data);
},
"space.deleteFile": (_ctx, name: string) => {
return editor.space.spacePrimitives.deleteFile(name);
},
};
}