Remove debug logging and add file size limit

This commit is contained in:
Andras Schmelczer 2025-01-08 22:25:04 +00:00
commit 5582691cf7
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 62 additions and 47 deletions

View file

@ -5,6 +5,8 @@ export interface FileOperations {
read: (path: RelativePath) => Promise<Uint8Array>;
getFileSize(path: RelativePath): Promise<number>;
getModificationTime: (path: RelativePath) => Promise<Date>;
// Create and write the file if it doesn't exist. Otherwise, it has the same behavior as write.

View file

@ -8,41 +8,32 @@ export class ObsidianFileOperations implements FileOperations {
public constructor(private readonly vault: Vault) {}
public async listAllFiles(): Promise<RelativePath[]> {
console.log(this.vault);
console.log("before getFiles");
await sleep(1000);
const files = this.vault.getFiles();
console.log("after getFiles");
await sleep(1000);
console.log(files);
return files.map((file) => file.path);
}
public async read(path: RelativePath): Promise<Uint8Array> {
console.log("before readBinary");
await sleep(1000);
const result = new Uint8Array(
await this.vault.readBinary(this.getAbstractFile(path))
);
console.log("after readBinary");
await sleep(1000);
return result;
}
public async getFileSize(path: RelativePath): Promise<number> {
const file = await this.vault.adapter.stat(normalizePath(path));
if (!file) {
throw new Error(`File not found: ${path}`);
}
return file.size;
}
public async getModificationTime(path: RelativePath): Promise<Date> {
console.log("before stat");
await sleep(1000);
const file = await this.vault.adapter.stat(normalizePath(path));
if (!file) {
throw new Error(`File not found: ${path}`);
}
console.log("after stat");
await sleep(1000);
return new Date(file.mtime);
}
@ -51,19 +42,13 @@ export class ObsidianFileOperations implements FileOperations {
path: RelativePath,
newContent: Uint8Array
): Promise<void> {
console.log("before create");
await sleep(1000);
if (await this.vault.adapter.exists(normalizePath(path))) {
await this.write(path, new Uint8Array(0), newContent);
console.log("after create");
await sleep(1000);
return;
}
await this.createParentDirectories(normalizePath(path));
await this.vault.createBinary(normalizePath(path), newContent);
console.log("after create2");
await sleep(1000);
}
public async write(