Add more file operations
This commit is contained in:
parent
d069cbdb67
commit
c0fd041532
2 changed files with 15 additions and 0 deletions
|
|
@ -1,8 +1,12 @@
|
|||
import { RelativePath } from "src/database/document-metadata";
|
||||
|
||||
export interface FileOperations {
|
||||
listAllFiles(): Promise<RelativePath[]>;
|
||||
|
||||
read(path: RelativePath): Promise<Uint8Array>;
|
||||
|
||||
getModificationTime(path: RelativePath): Promise<Date>;
|
||||
|
||||
create(path: RelativePath, newContent: Uint8Array): Promise<void>;
|
||||
|
||||
// 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.
|
||||
|
|
|
|||
|
|
@ -7,12 +7,23 @@ import { RelativePath } from "src/database/document-metadata";
|
|||
export class ObsidianFileOperations implements FileOperations {
|
||||
public constructor(private vault: Vault) {}
|
||||
|
||||
async listAllFiles(): Promise<RelativePath[]> {
|
||||
const files = this.vault.getFiles();
|
||||
return files.map((file) => file.path);
|
||||
}
|
||||
|
||||
async read(path: RelativePath): Promise<Uint8Array> {
|
||||
return new Uint8Array(
|
||||
await this.vault.adapter.readBinary(normalizePath(path))
|
||||
);
|
||||
}
|
||||
|
||||
async getModificationTime(path: RelativePath): Promise<Date> {
|
||||
return new Date(
|
||||
(await this.vault.adapter.stat(normalizePath(path)))!.mtime
|
||||
);
|
||||
}
|
||||
|
||||
async write(
|
||||
path: RelativePath,
|
||||
expectedContent: Uint8Array,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue