diff --git a/plugin/src/file-operations/file-operations.ts b/plugin/src/file-operations/file-operations.ts index 69c8a60d..affa71c3 100644 --- a/plugin/src/file-operations/file-operations.ts +++ b/plugin/src/file-operations/file-operations.ts @@ -1,8 +1,12 @@ import { RelativePath } from "src/database/document-metadata"; export interface FileOperations { + listAllFiles(): Promise; + read(path: RelativePath): Promise; + getModificationTime(path: RelativePath): Promise; + create(path: RelativePath, newContent: Uint8Array): Promise; // Writes new content to the file at the given path. If the file's content has changed since the expectedContent was read, the write will merge the changes. diff --git a/plugin/src/file-operations/obsidian-file-operations.ts b/plugin/src/file-operations/obsidian-file-operations.ts index a921bf5a..213b794b 100644 --- a/plugin/src/file-operations/obsidian-file-operations.ts +++ b/plugin/src/file-operations/obsidian-file-operations.ts @@ -7,12 +7,23 @@ import { RelativePath } from "src/database/document-metadata"; export class ObsidianFileOperations implements FileOperations { public constructor(private vault: Vault) {} + async listAllFiles(): Promise { + const files = this.vault.getFiles(); + return files.map((file) => file.path); + } + async read(path: RelativePath): Promise { return new Uint8Array( await this.vault.adapter.readBinary(normalizePath(path)) ); } + async getModificationTime(path: RelativePath): Promise { + return new Date( + (await this.vault.adapter.stat(normalizePath(path)))!.mtime + ); + } + async write( path: RelativePath, expectedContent: Uint8Array,