mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2025-12-16 03:05:57 +00:00
- Fixed
- Automatic (temporary) batch size adjustment has been restored to work correctly. - Chunk splitting has been backed to the previous behaviour for saving them correctly. - Improved - Corrupted chunks will be detected automatically. - Now on the case-insensitive system, `aaa.md` and `AAA.md` will be treated as the same file or path at applying changesets.
This commit is contained in:
@@ -35,7 +35,7 @@ export class LocalPouchDB extends LocalPouchDBBase {
|
|||||||
|
|
||||||
last_successful_post = false;
|
last_successful_post = false;
|
||||||
getLastPostFailedBySize() {
|
getLastPostFailedBySize() {
|
||||||
return this.last_successful_post;
|
return !this.last_successful_post;
|
||||||
}
|
}
|
||||||
async fetchByAPI(request: RequestUrlParam): Promise<RequestUrlResponse> {
|
async fetchByAPI(request: RequestUrlParam): Promise<RequestUrlResponse> {
|
||||||
const ret = await requestUrl(request);
|
const ret = await requestUrl(request);
|
||||||
@@ -75,7 +75,7 @@ export class LocalPouchDB extends LocalPouchDBBase {
|
|||||||
const method = opts.method ?? "GET";
|
const method = opts.method ?? "GET";
|
||||||
if (opts.body) {
|
if (opts.body) {
|
||||||
const opts_length = opts.body.toString().length;
|
const opts_length = opts.body.toString().length;
|
||||||
if (opts_length > 1024 * 1024 * 10) {
|
if (opts_length > 1000 * 1000 * 10) {
|
||||||
// over 10MB
|
// over 10MB
|
||||||
if (isCloudantURI(uri)) {
|
if (isCloudantURI(uri)) {
|
||||||
this.last_successful_post = false;
|
this.last_successful_post = false;
|
||||||
|
|||||||
2
src/lib
2
src/lib
Submodule src/lib updated: d5f9e0e6e9...2734fe9632
32
src/main.ts
32
src/main.ts
@@ -44,6 +44,16 @@ const ICHeaderEnd = "i;";
|
|||||||
const ICHeaderLength = ICHeader.length;
|
const ICHeaderLength = ICHeader.length;
|
||||||
const FileWatchEventQueueMax = 10;
|
const FileWatchEventQueueMax = 10;
|
||||||
|
|
||||||
|
function getAbstractFileByPath(path: string): TAbstractFile | null {
|
||||||
|
// Hidden API but so useful.
|
||||||
|
if ("getAbstractFileByPathInsensitive" in app.vault && (app.vault.adapter?.insensitive ?? false)) {
|
||||||
|
// @ts-ignore
|
||||||
|
return app.vault.getAbstractFileByPathInsensitive(path);
|
||||||
|
} else {
|
||||||
|
return app.vault.getAbstractFileByPath(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns is internal chunk of file
|
* returns is internal chunk of file
|
||||||
* @param str ID
|
* @param str ID
|
||||||
@@ -97,7 +107,7 @@ const askString = (app: App, title: string, key: string, placeholder: string): P
|
|||||||
};
|
};
|
||||||
let touchedFiles: string[] = [];
|
let touchedFiles: string[] = [];
|
||||||
function touch(file: TFile | string) {
|
function touch(file: TFile | string) {
|
||||||
const f = file instanceof TFile ? file : app.vault.getAbstractFileByPath(file) as TFile;
|
const f = file instanceof TFile ? file : getAbstractFileByPath(file) as TFile;
|
||||||
const key = `${f.path}-${f.stat.mtime}-${f.stat.size}`;
|
const key = `${f.path}-${f.stat.mtime}-${f.stat.size}`;
|
||||||
touchedFiles.unshift(key);
|
touchedFiles.unshift(key);
|
||||||
touchedFiles = touchedFiles.slice(0, 100);
|
touchedFiles = touchedFiles.slice(0, 100);
|
||||||
@@ -147,7 +157,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isRedFlagRaised(): boolean {
|
isRedFlagRaised(): boolean {
|
||||||
const redflag = this.app.vault.getAbstractFileByPath(normalizePath(FLAGMD_REDFLAG));
|
const redflag = getAbstractFileByPath(normalizePath(FLAGMD_REDFLAG));
|
||||||
if (redflag != null) {
|
if (redflag != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1050,7 +1060,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
for (const i of newFiles) {
|
for (const i of newFiles) {
|
||||||
try {
|
try {
|
||||||
const newFilePath = normalizePath(this.getFilePath(i));
|
const newFilePath = normalizePath(this.getFilePath(i));
|
||||||
const newFile = this.app.vault.getAbstractFileByPath(newFilePath);
|
const newFile = getAbstractFileByPath(newFilePath);
|
||||||
if (newFile instanceof TFile) {
|
if (newFile instanceof TFile) {
|
||||||
Logger(`save ${newFile.path} into db`);
|
Logger(`save ${newFile.path} into db`);
|
||||||
await this.updateIntoDB(newFile);
|
await this.updateIntoDB(newFile);
|
||||||
@@ -1278,7 +1288,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
await this.app.vault.modifyBinary(file, bin, { ctime: doc.ctime, mtime: doc.mtime });
|
await this.app.vault.modifyBinary(file, bin, { ctime: doc.ctime, mtime: doc.mtime });
|
||||||
// this.batchFileChange = this.batchFileChange.filter((e) => e != file.path);
|
// this.batchFileChange = this.batchFileChange.filter((e) => e != file.path);
|
||||||
Logger(msg + path);
|
Logger(msg + path);
|
||||||
const xf = this.app.vault.getAbstractFileByPath(file.path) as TFile;
|
const xf = getAbstractFileByPath(file.path) as TFile;
|
||||||
touch(xf);
|
touch(xf);
|
||||||
this.app.vault.trigger("modify", xf);
|
this.app.vault.trigger("modify", xf);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@@ -1295,7 +1305,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
await this.app.vault.modify(file, doc.data, { ctime: doc.ctime, mtime: doc.mtime });
|
await this.app.vault.modify(file, doc.data, { ctime: doc.ctime, mtime: doc.mtime });
|
||||||
Logger(msg + path);
|
Logger(msg + path);
|
||||||
// this.batchFileChange = this.batchFileChange.filter((e) => e != file.path);
|
// this.batchFileChange = this.batchFileChange.filter((e) => e != file.path);
|
||||||
const xf = this.app.vault.getAbstractFileByPath(file.path) as TFile;
|
const xf = getAbstractFileByPath(file.path) as TFile;
|
||||||
touch(xf);
|
touch(xf);
|
||||||
this.app.vault.trigger("modify", xf);
|
this.app.vault.trigger("modify", xf);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@@ -1345,7 +1355,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
async handleDBChangedAsync(change: EntryBody) {
|
async handleDBChangedAsync(change: EntryBody) {
|
||||||
|
|
||||||
const targetFile = this.app.vault.getAbstractFileByPath(id2path(change._id));
|
const targetFile = getAbstractFileByPath(id2path(change._id));
|
||||||
if (targetFile == null) {
|
if (targetFile == null) {
|
||||||
if (change._deleted || change.deleted) {
|
if (change._deleted || change.deleted) {
|
||||||
return;
|
return;
|
||||||
@@ -1461,7 +1471,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
if (!this.isTargetFile(id2path(doc._id))) return;
|
if (!this.isTargetFile(id2path(doc._id))) return;
|
||||||
const skipOldFile = this.settings.skipOlderFilesOnSync && false; //patched temporary.
|
const skipOldFile = this.settings.skipOlderFilesOnSync && false; //patched temporary.
|
||||||
if ((!isInternalChunk(doc._id)) && skipOldFile) {
|
if ((!isInternalChunk(doc._id)) && skipOldFile) {
|
||||||
const info = this.app.vault.getAbstractFileByPath(id2path(doc._id));
|
const info = getAbstractFileByPath(id2path(doc._id));
|
||||||
|
|
||||||
if (info && info instanceof TFile) {
|
if (info && info instanceof TFile) {
|
||||||
const localMtime = ~~((info as TFile).stat.mtime / 1000);
|
const localMtime = ~~((info as TFile).stat.mtime / 1000);
|
||||||
@@ -2027,7 +2037,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
const p = conflictCheckResult.diff.map((e) => e[1]).join("");
|
const p = conflictCheckResult.diff.map((e) => e[1]).join("");
|
||||||
await this.localDatabase.deleteDBEntry(filename, { rev: conflictCheckResult.left.rev });
|
await this.localDatabase.deleteDBEntry(filename, { rev: conflictCheckResult.left.rev });
|
||||||
await this.localDatabase.deleteDBEntry(filename, { rev: conflictCheckResult.right.rev });
|
await this.localDatabase.deleteDBEntry(filename, { rev: conflictCheckResult.right.rev });
|
||||||
const file = this.app.vault.getAbstractFileByPath(filename) as TFile;
|
const file = getAbstractFileByPath(filename) as TFile;
|
||||||
if (file) {
|
if (file) {
|
||||||
await this.app.vault.modify(file, p);
|
await this.app.vault.modify(file, p);
|
||||||
await this.updateIntoDB(file);
|
await this.updateIntoDB(file);
|
||||||
@@ -2074,7 +2084,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
const checkFiles = JSON.parse(JSON.stringify(this.conflictedCheckFiles)) as string[];
|
const checkFiles = JSON.parse(JSON.stringify(this.conflictedCheckFiles)) as string[];
|
||||||
for (const filename of checkFiles) {
|
for (const filename of checkFiles) {
|
||||||
try {
|
try {
|
||||||
const file = this.app.vault.getAbstractFileByPath(filename);
|
const file = getAbstractFileByPath(filename);
|
||||||
if (file != null && file instanceof TFile) {
|
if (file != null && file instanceof TFile) {
|
||||||
await this.showIfConflicted(file.path);
|
await this.showIfConflicted(file.path);
|
||||||
}
|
}
|
||||||
@@ -2106,7 +2116,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async pullFile(filename: string, fileList?: TFile[], force?: boolean, rev?: string, waitForReady = true) {
|
async pullFile(filename: string, fileList?: TFile[], force?: boolean, rev?: string, waitForReady = true) {
|
||||||
const targetFile = this.app.vault.getAbstractFileByPath(id2path(filename));
|
const targetFile = getAbstractFileByPath(id2path(filename));
|
||||||
if (!this.isTargetFile(id2path(filename))) return;
|
if (!this.isTargetFile(id2path(filename))) return;
|
||||||
if (targetFile == null) {
|
if (targetFile == null) {
|
||||||
//have to create;
|
//have to create;
|
||||||
@@ -2137,7 +2147,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
throw new Error(`Missing doc:${(file as any).path}`)
|
throw new Error(`Missing doc:${(file as any).path}`)
|
||||||
}
|
}
|
||||||
if (!(file instanceof TFile) && "path" in file) {
|
if (!(file instanceof TFile) && "path" in file) {
|
||||||
const w = this.app.vault.getAbstractFileByPath((file as any).path);
|
const w = getAbstractFileByPath((file as any).path);
|
||||||
if (w instanceof TFile) {
|
if (w instanceof TFile) {
|
||||||
file = w;
|
file = w;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user