Skip to content

Build your personal knowledge base with Trilium Notes

fix blobIds - they shouldn't contain + and / characters

zadam72122d0f957a
diff --git a/db/migrations/0224__fix_blobIds.sql b/db/migrations/0224__fix_blobIds.sql
new file mode 100644
index 0000000000..d8709cd79c
--- /dev/null
+++ b/db/migrations/0224__fix_blobIds.sql
@@ -0,0 +1,14 @@
+UPDATE blobs SET blobId = REPLACE(blobId, '+', 'X');
+UPDATE blobs SET blobId = REPLACE(blobId, '/', 'Y');
+
+UPDATE notes SET blobId = REPLACE(blobId, '+', 'X');
+UPDATE notes SET blobId = REPLACE(blobId, '/', 'Y');
+
+UPDATE attachments SET blobId = REPLACE(blobId, '+', 'X');
+UPDATE attachments SET blobId = REPLACE(blobId, '/', 'Y');
+
+UPDATE revisions SET blobId = REPLACE(blobId, '+', 'X');
+UPDATE revisions SET blobId = REPLACE(blobId, '/', 'Y');
+
+UPDATE entity_changes SET entityId = REPLACE(blobId, '+', 'X') WHERE entityName = 'blobs';
+UPDATE entity_changes SET entityId = REPLACE(blobId, '/', 'Y') WHERE entityName = 'blobs';
\ No newline at end of file
diff --git a/src/services/app_info.js b/src/services/app_info.js
index 5c390897cb..0db6fcee73 100644
--- a/src/services/app_info.js
+++ b/src/services/app_info.js
@@ -4,8 +4,8 @@ const build = require('./build');
const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir');
-const APP_DB_VERSION = 223;
-const SYNC_VERSION = 30;
+const APP_DB_VERSION = 224;
+const SYNC_VERSION = 31;
const CLIPPER_PROTOCOL_VERSION = "1.0";
module.exports = {
diff --git a/src/services/sync.js b/src/services/sync.js
index 99dd72aa37..c2dd9b0f16 100644
--- a/src/services/sync.js
+++ b/src/services/sync.js
@@ -56,10 +56,9 @@ async function sync() {
catch (e) {
proxyToggle = !proxyToggle;
- if (e.message &&
- (e.message.includes('ECONNREFUSED') ||
- e.message.includes('ERR_') || // node network errors
- e.message.includes('Bad Gateway'))) {
+ if (e.message?.includes('ECONNREFUSED') ||
+ e.message?.includes('ERR_') || // node network errors
+ e.message?.includes('Bad Gateway')) {
ws.syncFailed();
diff --git a/src/services/utils.js b/src/services/utils.js
index 5b6d84fddd..1b6b303ab8 100644
--- a/src/services/utils.js
+++ b/src/services/utils.js
@@ -28,8 +28,13 @@ function hashedBlobId(content) {
// sha512 is faster than sha256
const base64Hash = crypto.createHash('sha512').update(content).digest('base64');
- // 20 characters of base64 gives us 120 bit of entropy which is plenty enough
- return base64Hash.substr(0, 20);
+ // we don't want such + and / in the IDs
+ const kindaBase62Hash = base64Hash
+ .replace('+', 'X')
+ .replace('/', 'Y');
+
+ // 20 characters of base62 gives us ~120 bit of entropy which is plenty enough
+ return kindaBase62Hash.substr(0, 20);
}
function toBase64(plainText) {