diff --git a/package-lock.json b/package-lock.json index d229c30..ecfb64e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,8 @@ "dependencies": { "diff-match-patch": "^1.0.5", "idb": "^7.1.1", - "xxhash-wasm": "^0.4.2" + "xxhash-wasm": "^0.4.2", + "xxhash-wasm-102": "npm:xxhash-wasm@^1.0.2" }, "devDependencies": { "@tsconfig/svelte": "^4.0.1", @@ -4076,6 +4077,12 @@ "resolved": "https://registry.npmjs.org/xxhash-wasm/-/xxhash-wasm-0.4.2.tgz", "integrity": "sha512-/eyHVRJQCirEkSZ1agRSCwriMhwlyUcFkXD5TPVSLP+IPzjsqMVzZwdoczLp1SoQU0R3dxz1RpIK+4YNQbCVOA==" }, + "node_modules/xxhash-wasm-102": { + "name": "xxhash-wasm", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/xxhash-wasm/-/xxhash-wasm-1.0.2.tgz", + "integrity": "sha512-ibF0Or+FivM9lNrg+HGJfVX8WJqgo+kCLDc4vx6xMeTce7Aj+DLttKbxxRR/gNLSAelRc1omAPlJ77N/Jem07A==" + }, "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -7032,6 +7039,11 @@ "resolved": "https://registry.npmjs.org/xxhash-wasm/-/xxhash-wasm-0.4.2.tgz", "integrity": "sha512-/eyHVRJQCirEkSZ1agRSCwriMhwlyUcFkXD5TPVSLP+IPzjsqMVzZwdoczLp1SoQU0R3dxz1RpIK+4YNQbCVOA==" }, + "xxhash-wasm-102": { + "version": "npm:xxhash-wasm@1.0.2", + "resolved": "https://registry.npmjs.org/xxhash-wasm/-/xxhash-wasm-1.0.2.tgz", + "integrity": "sha512-ibF0Or+FivM9lNrg+HGJfVX8WJqgo+kCLDc4vx6xMeTce7Aj+DLttKbxxRR/gNLSAelRc1omAPlJ77N/Jem07A==" + }, "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", diff --git a/package.json b/package.json index 77636f4..4533de4 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "dependencies": { "diff-match-patch": "^1.0.5", "idb": "^7.1.1", - "xxhash-wasm": "^0.4.2" + "xxhash-wasm": "^0.4.2", + "xxhash-wasm-102": "npm:xxhash-wasm@^1.0.2" } } diff --git a/src/CmdConfigSync.ts b/src/CmdConfigSync.ts index 1926873..404d8f8 100644 --- a/src/CmdConfigSync.ts +++ b/src/CmdConfigSync.ts @@ -7,7 +7,7 @@ import { ICXHeader, PERIODIC_PLUGIN_SWEEP, } from "./types"; import { Parallels, delay, getDocData } from "./lib/src/utils"; import { Logger } from "./lib/src/logger"; import { WrappedNotice } from "./lib/src/wrapper"; -import { base64ToArrayBuffer, arrayBufferToBase64, readString, uint8ArrayToHexString } from "./lib/src/strbin"; +import { base64ToArrayBuffer, arrayBufferToBase64, readString, crc32CKHash } from "./lib/src/strbin"; import { runWithLock } from "./lib/src/lock"; import { LiveSyncCommands } from "./LiveSyncCommands"; import { stripAllPrefixes } from "./lib/src/path"; @@ -35,14 +35,6 @@ function deserialize(str: string, def: T) { export const pluginList = writable([] as PluginDataExDisplay[]); export const pluginIsEnumerating = writable(false); -const encoder = new TextEncoder(); -const hashString = (async (key: string) => { - // const buff = writeString(key); - const buff = encoder.encode(key); - const digest = await crypto.subtle.digest('SHA-256', buff); - return uint8ArrayToHexString(new Uint8Array(digest)); -}) - export type PluginDataExFile = { filename: string, data?: string[], @@ -209,7 +201,7 @@ export class ConfigSync extends LiveSyncCommands { for (const file of data.files) { const work = { ...file }; const tempStr = getDocData(work.data); - work.data = [await hashString(tempStr)]; + work.data = [crc32CKHash(tempStr)]; xFiles.push(work); } entries.push({ diff --git a/src/CmdHiddenFileSync.ts b/src/CmdHiddenFileSync.ts index 7990eca..3c33f5d 100644 --- a/src/CmdHiddenFileSync.ts +++ b/src/CmdHiddenFileSync.ts @@ -1,6 +1,6 @@ -import { Notice, normalizePath, PluginManifest } from "./deps"; -import { EntryDoc, LoadedEntry, LOG_LEVEL, InternalFileEntry, FilePathWithPrefix, FilePath } from "./lib/src/types"; -import { InternalFileInfo, ICHeader, ICHeaderEnd } from "./types"; +import { Notice, normalizePath, type PluginManifest } from "./deps"; +import { type EntryDoc, type LoadedEntry, LOG_LEVEL, type InternalFileEntry, type FilePathWithPrefix, type FilePath } from "./lib/src/types"; +import { type InternalFileInfo, ICHeader, ICHeaderEnd } from "./types"; import { Parallels, delay, isDocContentSame } from "./lib/src/utils"; import { Logger } from "./lib/src/logger"; import { PouchDB } from "./lib/src/pouchdb-browser.js"; diff --git a/src/ObsidianLiveSyncSettingTab.ts b/src/ObsidianLiveSyncSettingTab.ts index e0ec045..d8bd679 100644 --- a/src/ObsidianLiveSyncSettingTab.ts +++ b/src/ObsidianLiveSyncSettingTab.ts @@ -1,5 +1,5 @@ import { App, PluginSettingTab, Setting, sanitizeHTMLToDom, TextAreaComponent, MarkdownRenderer, stringifyYaml } from "./deps"; -import { DEFAULT_SETTINGS, LOG_LEVEL, type ObsidianLiveSyncSettings, type ConfigPassphraseStore, type RemoteDBSettings, type FilePathWithPrefix, type DocumentID } from "./lib/src/types"; +import { DEFAULT_SETTINGS, LOG_LEVEL, type ObsidianLiveSyncSettings, type ConfigPassphraseStore, type RemoteDBSettings, type FilePathWithPrefix, type HashAlgorithm, type DocumentID } from "./lib/src/types"; import { delay } from "./lib/src/utils"; import { Semaphore } from "./lib/src/semaphore"; import { versionNumberString2Number } from "./lib/src/strbin"; @@ -7,8 +7,7 @@ import { Logger } from "./lib/src/logger"; import { checkSyncInfo, isCloudantURI } from "./lib/src/utils_couchdb.js"; import { testCrypt } from "./lib/src/e2ee_v2"; import ObsidianLiveSyncPlugin from "./main"; -import { balanceChunks, isChunk, localDatabaseCleanUp, performRebuildDB, remoteDatabaseCleanup, requestToCouchDB } from "./utils"; -import { stripAllPrefixes } from "./lib/src/path"; +import { balanceChunks, localDatabaseCleanUp, performRebuildDB, remoteDatabaseCleanup, requestToCouchDB } from "./utils"; export class ObsidianLiveSyncSettingTab extends PluginSettingTab { @@ -1716,6 +1715,22 @@ ${stringifyYaml(pluginConfig)}`; await this.plugin.initializeDatabase(); }) }) + + new Setting(containerHatchEl) + .setName("The Hash algorithm for chunk IDs") + .setDesc("xxhash64 is the current default.") + .setClass("wizardHidden") + .addDropdown((dropdown) => + dropdown + .addOptions({ "": "Old Algorithm", "xxhash32": "xxhash32 (Fast)", "xxhash64": "xxhash64 (Fastest)" } as Record) + .setValue(this.plugin.settings.hashAlg) + .onChange(async (value: HashAlgorithm) => { + this.plugin.settings.hashAlg = value; + await this.plugin.saveSettings(); + }) + ) + .setClass("wizardHidden"); + addScreenElement("50", containerHatchEl); diff --git a/src/lib b/src/lib index 63fa007..250f63e 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 63fa0074fe5bf2d45e9132885040ffbebade8e09 +Subproject commit 250f63eb48926d7b8168a594b6cbb7961fbee95e diff --git a/tsconfig.json b/tsconfig.json index 79bca56..a7369d6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,7 +21,8 @@ "ES5", "ES6", "ES7", - "es2019.array" + "es2019.array", + "ES2020.BigInt", ] }, "include": [