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";
|
import { RelativePath } from "src/database/document-metadata";
|
||||||
|
|
||||||
export interface FileOperations {
|
export interface FileOperations {
|
||||||
|
listAllFiles(): Promise<RelativePath[]>;
|
||||||
|
|
||||||
read(path: RelativePath): Promise<Uint8Array>;
|
read(path: RelativePath): Promise<Uint8Array>;
|
||||||
|
|
||||||
|
getModificationTime(path: RelativePath): Promise<Date>;
|
||||||
|
|
||||||
create(path: RelativePath, newContent: Uint8Array): Promise<void>;
|
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.
|
// 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 {
|
export class ObsidianFileOperations implements FileOperations {
|
||||||
public constructor(private vault: Vault) {}
|
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> {
|
async read(path: RelativePath): Promise<Uint8Array> {
|
||||||
return new Uint8Array(
|
return new Uint8Array(
|
||||||
await this.vault.adapter.readBinary(normalizePath(path))
|
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(
|
async write(
|
||||||
path: RelativePath,
|
path: RelativePath,
|
||||||
expectedContent: Uint8Array,
|
expectedContent: Uint8Array,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue