From 32bb256cca7dd1f1ee9a042466f6ef27d4a4167f Mon Sep 17 00:00:00 2001 From: Julien <32807437+julien-me@users.noreply.github.com> Date: Wed, 22 Feb 2023 21:12:53 +0800 Subject: [PATCH] All: Resolves #7661: Stop synchronization with unsupported WebDAV providers (#7819) --- .eslintignore | 3 ++ .gitignore | 3 ++ packages/lib/JoplinDatabase.ts | 6 +++- packages/lib/SyncTargetWebDAV.js | 2 ++ packages/lib/file-api-driver-webdav.js | 6 ++++ packages/lib/migrations/42.ts | 21 +++++++++++++ packages/lib/models/Migration.ts | 2 ++ packages/lib/models/Setting.ts | 6 ++++ packages/lib/utils/webDAVUtils.test.ts | 43 ++++++++++++++++++++++++++ packages/lib/utils/webDAVUtils.ts | 21 +++++++++++++ 10 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 packages/lib/migrations/42.ts create mode 100644 packages/lib/utils/webDAVUtils.test.ts create mode 100644 packages/lib/utils/webDAVUtils.ts diff --git a/.eslintignore b/.eslintignore index 94f2f3489..1578d9434 100644 --- a/.eslintignore +++ b/.eslintignore @@ -513,6 +513,7 @@ packages/lib/markdownUtils.js packages/lib/markdownUtils.test.js packages/lib/markdownUtils2.test.js packages/lib/markupLanguageUtils.js +packages/lib/migrations/42.js packages/lib/models/Alarm.js packages/lib/models/BaseItem.js packages/lib/models/Folder.js @@ -759,6 +760,8 @@ packages/lib/themes/type.js packages/lib/time.js packages/lib/utils/credentialFiles.js packages/lib/utils/joplinCloud.js +packages/lib/utils/webDAVUtils.js +packages/lib/utils/webDAVUtils.test.js packages/lib/uuid.js packages/lib/versionInfo.js packages/lib/versionInfo.test.js diff --git a/.gitignore b/.gitignore index 158260c48..1bd166dd5 100644 --- a/.gitignore +++ b/.gitignore @@ -501,6 +501,7 @@ packages/lib/markdownUtils.js packages/lib/markdownUtils.test.js packages/lib/markdownUtils2.test.js packages/lib/markupLanguageUtils.js +packages/lib/migrations/42.js packages/lib/models/Alarm.js packages/lib/models/BaseItem.js packages/lib/models/Folder.js @@ -747,6 +748,8 @@ packages/lib/themes/type.js packages/lib/time.js packages/lib/utils/credentialFiles.js packages/lib/utils/joplinCloud.js +packages/lib/utils/webDAVUtils.js +packages/lib/utils/webDAVUtils.test.js packages/lib/uuid.js packages/lib/versionInfo.js packages/lib/versionInfo.test.js diff --git a/packages/lib/JoplinDatabase.ts b/packages/lib/JoplinDatabase.ts index 3b6d5c65a..40275cbc6 100644 --- a/packages/lib/JoplinDatabase.ts +++ b/packages/lib/JoplinDatabase.ts @@ -354,7 +354,7 @@ export default class JoplinDatabase extends Database { // must be set in the synchronizer too. // Note: v16 and v17 don't do anything. They were used to debug an issue. - const existingDatabaseVersions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41]; + const existingDatabaseVersions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42]; let currentVersionIndex = existingDatabaseVersions.indexOf(fromVersion); @@ -913,6 +913,10 @@ export default class JoplinDatabase extends Database { queries.push('ALTER TABLE `folders` ADD COLUMN icon TEXT NOT NULL DEFAULT ""'); } + if (targetVersion === 42) { + queries.push(this.addMigrationFile(42)); + } + const updateVersionQuery = { sql: 'UPDATE version SET version = ?', params: [targetVersion] }; queries.push(updateVersionQuery); diff --git a/packages/lib/SyncTargetWebDAV.js b/packages/lib/SyncTargetWebDAV.js index 85d4c378a..ac1639168 100644 --- a/packages/lib/SyncTargetWebDAV.js +++ b/packages/lib/SyncTargetWebDAV.js @@ -5,6 +5,7 @@ const { FileApi } = require('./file-api.js'); const Synchronizer = require('./Synchronizer').default; const WebDavApi = require('./WebDavApi'); const { FileApiDriverWebDav } = require('./file-api-driver-webdav'); +const checkProviderIsSupported = require('./utils/webDAVUtils').default; class SyncTargetWebDAV extends BaseSyncTarget { static id() { @@ -56,6 +57,7 @@ class SyncTargetWebDAV extends BaseSyncTarget { }; try { + checkProviderIsSupported(options.path()); const result = await fileApi.stat(''); if (!result) throw new Error(`WebDAV directory not found: ${options.path()}`); output.ok = true; diff --git a/packages/lib/file-api-driver-webdav.js b/packages/lib/file-api-driver-webdav.js index fd12226d6..06b08d279 100644 --- a/packages/lib/file-api-driver-webdav.js +++ b/packages/lib/file-api-driver-webdav.js @@ -1,6 +1,8 @@ const { basicDelta } = require('./file-api'); const { rtrimSlashes, ltrimSlashes } = require('./path-utils'); const JoplinError = require('./JoplinError').default; +const Setting = require('./models/Setting').default; +const checkProviderIsSupported = require('./utils/webDAVUtils').default; class FileApiDriverWebDav { constructor(api) { @@ -224,6 +226,10 @@ class FileApiDriverWebDav { await this.delete(''); await this.mkdir(''); } + + initialize() { + checkProviderIsSupported(Setting.value('sync.6.path')); + } } module.exports = { FileApiDriverWebDav }; diff --git a/packages/lib/migrations/42.ts b/packages/lib/migrations/42.ts new file mode 100644 index 000000000..64c2795f4 --- /dev/null +++ b/packages/lib/migrations/42.ts @@ -0,0 +1,21 @@ +import Setting from '../models/Setting'; +import checkProviderIsSupported from '../utils/webDAVUtils'; + +interface Script { + exec: ()=> Promise; +} + +const script: Script =