diff --git a/manifest.json b/manifest.json index 3c2a103..d92f744 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-livesync", "name": "Self-hosted LiveSync", - "version": "0.6.0", + "version": "0.6.1", "minAppVersion": "0.9.12", "description": "Community implementation of self-hosted livesync. Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.", "author": "vorotamoroz", diff --git a/package-lock.json b/package-lock.json index 1aa0cd2..e432d52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-livesync", - "version": "0.6.0", + "version": "0.6.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-livesync", - "version": "0.6.0", + "version": "0.6.1", "license": "MIT", "dependencies": { "diff-match-patch": "^1.0.5", diff --git a/package.json b/package.json index 0e87a45..96ebf18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-livesync", - "version": "0.6.0", + "version": "0.6.1", "description": "Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.", "main": "main.js", "scripts": { diff --git a/src/LocalPouchDB.ts b/src/LocalPouchDB.ts index c86dbe1..560fef0 100644 --- a/src/LocalPouchDB.ts +++ b/src/LocalPouchDB.ts @@ -23,7 +23,7 @@ import { MILSTONE_DOCID, DatabaseConnectingStatus, } from "./types"; -import { resolveWithIgnoreKnownError, delay, path2id, runWithLock } from "./utils"; +import { resolveWithIgnoreKnownError, delay, path2id, runWithLock, isPlainText } from "./utils"; import { Logger } from "./logger"; import { checkRemoteVersion, connectRemoteCouchDB, getLastPostFailedBySize } from "./utils_couchdb"; import { decrypt, encrypt } from "./e2ee"; @@ -501,18 +501,6 @@ export class LocalPouchDB { Logger(`deleteDBEntryPrefix:deleted ${deleteCount} items, skipped ${notfound}`); return true; } - isPlainText(filename: string): boolean { - if (filename.endsWith(".md")) return true; - if (filename.endsWith(".txt")) return true; - if (filename.endsWith(".svg")) return true; - if (filename.endsWith(".html")) return true; - if (filename.endsWith(".csv")) return true; - if (filename.endsWith(".css")) return true; - if (filename.endsWith(".js")) return true; - if (filename.endsWith(".xml")) return true; - - return false; - } async putDBEntry(note: LoadedEntry) { await this.waitForGCComplete(); let leftData = note.data; @@ -524,7 +512,7 @@ export class LocalPouchDB { let plainSplit = false; let cacheUsed = 0; const userpasswordHash = this.h32Raw(new TextEncoder().encode(this.settings.passphrase)); - if (this.isPlainText(note._id)) { + if (isPlainText(note._id)) { pieceSize = MAX_DOC_SIZE; plainSplit = true; } diff --git a/src/main.ts b/src/main.ts index 0d66760..6595a1d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,7 +18,7 @@ import { diff_result, FLAGMD_REDFLAG, } from "./types"; -import { base64ToString, arrayBufferToBase64, base64ToArrayBuffer, isValidPath, versionNumberString2Number, id2path, path2id, runWithLock, shouldBeIgnored, getProcessingCounts, setLockNotifier } from "./utils"; +import { base64ToString, arrayBufferToBase64, base64ToArrayBuffer, isValidPath, versionNumberString2Number, id2path, path2id, runWithLock, shouldBeIgnored, getProcessingCounts, setLockNotifier, isPlainText } from "./utils"; import { Logger, setLogger } from "./logger"; import { LocalPouchDB } from "./LocalPouchDB"; import { LogDisplayModal } from "./LogDisplayModal"; @@ -48,7 +48,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin { } showHistory(file: TFile) { if (!this.settings.useHistory) { - Logger("You have to enable Use history in misc.", LOG_LEVEL.NOTICE); + Logger("You have to enable Use History in misc.", LOG_LEVEL.NOTICE); } else { new DocumentHistoryModal(this.app, this, file).open(); } @@ -1217,7 +1217,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin { await this.localDatabase.waitForGCComplete(); let content = ""; let datatype: "plain" | "newnote" = "newnote"; - if (file.extension != "md") { + if (!isPlainText(file.name)) { const contentBin = await this.app.vault.readBinary(file); content = await arrayBufferToBase64(contentBin); datatype = "newnote"; diff --git a/src/utils.ts b/src/utils.ts index 3d2e646..1c5b9a3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -234,3 +234,16 @@ export function runWithLock(key: unknown, ignoreWhenRunning: boolean, proc: ( }); } } + +export function isPlainText(filename: string): boolean { + if (filename.endsWith(".md")) return true; + if (filename.endsWith(".txt")) return true; + if (filename.endsWith(".svg")) return true; + if (filename.endsWith(".html")) return true; + if (filename.endsWith(".csv")) return true; + if (filename.endsWith(".css")) return true; + if (filename.endsWith(".js")) return true; + if (filename.endsWith(".xml")) return true; + + return false; +}