* Don't require auth for .ping * Finally introducing loggers * Remove file list caching from disk_space_primitives I don't think this is required anymore with the sync model * Simplification of space primitives and more tests * More reliable online status * Add .zed settings * Remove selfUpdate argument from `writeFile` no longer used - Add `sync` config schema and document sync options - Move sync config handling to client boot logic - Move BootConfig type to ui_types.ts - Remove sync env vars from server - Update documentation for sync and architecture * Improve sync logic and proxy routing for full sync state * Add BoxProxy for late-bound client and improve Lua boot - Add isMobile syscall for editor * Add concurrency to sync process and log indexing duration * Better service worker lifecycle management
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import type { FileMeta } from "@silverbulletmd/silverbullet/type/index";
|
|
import type { SpacePrimitives } from "./space_primitives.ts";
|
|
import { isValidPath } from "@silverbulletmd/silverbullet/lib/ref";
|
|
|
|
export class CheckPathSpacePrimitives implements SpacePrimitives {
|
|
constructor(
|
|
private wrapped: SpacePrimitives,
|
|
) {
|
|
}
|
|
|
|
async fetchFileList(): Promise<FileMeta[]> {
|
|
return (await this.wrapped.fetchFileList()).filter(({ name }) =>
|
|
this.isReadable(name)
|
|
);
|
|
}
|
|
|
|
readFile(path: string): Promise<{ data: Uint8Array; meta: FileMeta }> {
|
|
if (!this.isReadable(path)) {
|
|
throw new Error("Couldn't write file, path isn't writable");
|
|
}
|
|
return this.wrapped.readFile(path);
|
|
}
|
|
|
|
getFileMeta(path: string, observing?: boolean): Promise<FileMeta> {
|
|
if (!this.isReadable(path)) {
|
|
throw new Error("Couldn't get file meta, path isn't writable");
|
|
}
|
|
return this.wrapped.getFileMeta(path, observing);
|
|
}
|
|
|
|
writeFile(
|
|
path: string,
|
|
data: Uint8Array,
|
|
meta?: FileMeta,
|
|
): Promise<FileMeta> {
|
|
if (!this.isWritable(path)) {
|
|
throw new Error("Couldn't write file, path is invalid");
|
|
}
|
|
return this.wrapped.writeFile(path, data, meta);
|
|
}
|
|
|
|
deleteFile(path: string): Promise<void> {
|
|
// We allow deletion of paths we can't write to. This is for the case when
|
|
// the user has an invalidly named file in their space and they need to
|
|
// remove it/rename it
|
|
if (!this.isReadable(path)) {
|
|
throw new Error("Couldn't delete file, path isn't writable");
|
|
}
|
|
return this.wrapped.deleteFile(path);
|
|
}
|
|
|
|
private isReadable(path: string): boolean {
|
|
return !path.startsWith(".");
|
|
}
|
|
|
|
private isWritable(path: string): boolean {
|
|
return this.isReadable(path) && isValidPath(path);
|
|
}
|
|
}
|