Try with not using adapter
This commit is contained in:
parent
b93e2c7c83
commit
1566197b60
1 changed files with 24 additions and 16 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import type { Vault } from "obsidian";
|
import { TFile, Vault } from "obsidian";
|
||||||
import { normalizePath } from "obsidian";
|
import { normalizePath } from "obsidian";
|
||||||
import type { FileOperations } from "./file-operations";
|
import type { FileOperations } from "./file-operations";
|
||||||
import type { RelativePath } from "src/database/document-metadata";
|
import type { RelativePath } from "src/database/document-metadata";
|
||||||
|
|
@ -25,7 +25,7 @@ export class ObsidianFileOperations implements FileOperations {
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
|
|
||||||
const result = new Uint8Array(
|
const result = new Uint8Array(
|
||||||
await this.vault.adapter.readBinary(normalizePath(path))
|
await this.vault.readBinary(this.getAbstractFile(path))
|
||||||
);
|
);
|
||||||
console.log("after readBinary");
|
console.log("after readBinary");
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
|
|
@ -61,7 +61,7 @@ export class ObsidianFileOperations implements FileOperations {
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.createParentDirectories(normalizePath(path));
|
await this.createParentDirectories(normalizePath(path));
|
||||||
await this.vault.adapter.writeBinary(normalizePath(path), newContent);
|
await this.vault.createBinary(normalizePath(path), newContent);
|
||||||
console.log("after create2");
|
console.log("after create2");
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
@ -77,26 +77,21 @@ export class ObsidianFileOperations implements FileOperations {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBinary(expectedContent)) {
|
if (isBinary(expectedContent)) {
|
||||||
await this.vault.adapter.writeBinary(
|
await this.vault.createBinary(normalizePath(path), newContent);
|
||||||
normalizePath(path),
|
|
||||||
newContent
|
|
||||||
);
|
|
||||||
return newContent;
|
return newContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
const expetedText = new TextDecoder().decode(expectedContent);
|
const expetedText = new TextDecoder().decode(expectedContent);
|
||||||
const newText = new TextDecoder().decode(newContent);
|
const newText = new TextDecoder().decode(newContent);
|
||||||
|
|
||||||
const resultText = await this.vault.adapter.process(
|
const file = this.getAbstractFile(path);
|
||||||
normalizePath(path),
|
const resultText = await this.vault.process(file, (currentText) => {
|
||||||
(currentText) => {
|
|
||||||
if (currentText !== expetedText) {
|
if (currentText !== expetedText) {
|
||||||
return mergeText(expetedText, currentText, newText);
|
return mergeText(expetedText, currentText, newText);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newText;
|
return newText;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
return new TextEncoder().encode(resultText);
|
return new TextEncoder().encode(resultText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,4 +127,17 @@ export class ObsidianFileOperations implements FileOperations {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getAbstractFile(path: RelativePath): TFile {
|
||||||
|
const file = this.vault.getAbstractFileByPath(path);
|
||||||
|
if (!file) {
|
||||||
|
throw new Error(`File not found: ${path}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file instanceof TFile) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Not a file: ${path}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue