mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-02 12:47:41 +02:00
This commit is contained in:
parent
219585bbcf
commit
32bb256cca
@ -513,6 +513,7 @@ packages/lib/markdownUtils.js
|
|||||||
packages/lib/markdownUtils.test.js
|
packages/lib/markdownUtils.test.js
|
||||||
packages/lib/markdownUtils2.test.js
|
packages/lib/markdownUtils2.test.js
|
||||||
packages/lib/markupLanguageUtils.js
|
packages/lib/markupLanguageUtils.js
|
||||||
|
packages/lib/migrations/42.js
|
||||||
packages/lib/models/Alarm.js
|
packages/lib/models/Alarm.js
|
||||||
packages/lib/models/BaseItem.js
|
packages/lib/models/BaseItem.js
|
||||||
packages/lib/models/Folder.js
|
packages/lib/models/Folder.js
|
||||||
@ -759,6 +760,8 @@ packages/lib/themes/type.js
|
|||||||
packages/lib/time.js
|
packages/lib/time.js
|
||||||
packages/lib/utils/credentialFiles.js
|
packages/lib/utils/credentialFiles.js
|
||||||
packages/lib/utils/joplinCloud.js
|
packages/lib/utils/joplinCloud.js
|
||||||
|
packages/lib/utils/webDAVUtils.js
|
||||||
|
packages/lib/utils/webDAVUtils.test.js
|
||||||
packages/lib/uuid.js
|
packages/lib/uuid.js
|
||||||
packages/lib/versionInfo.js
|
packages/lib/versionInfo.js
|
||||||
packages/lib/versionInfo.test.js
|
packages/lib/versionInfo.test.js
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -501,6 +501,7 @@ packages/lib/markdownUtils.js
|
|||||||
packages/lib/markdownUtils.test.js
|
packages/lib/markdownUtils.test.js
|
||||||
packages/lib/markdownUtils2.test.js
|
packages/lib/markdownUtils2.test.js
|
||||||
packages/lib/markupLanguageUtils.js
|
packages/lib/markupLanguageUtils.js
|
||||||
|
packages/lib/migrations/42.js
|
||||||
packages/lib/models/Alarm.js
|
packages/lib/models/Alarm.js
|
||||||
packages/lib/models/BaseItem.js
|
packages/lib/models/BaseItem.js
|
||||||
packages/lib/models/Folder.js
|
packages/lib/models/Folder.js
|
||||||
@ -747,6 +748,8 @@ packages/lib/themes/type.js
|
|||||||
packages/lib/time.js
|
packages/lib/time.js
|
||||||
packages/lib/utils/credentialFiles.js
|
packages/lib/utils/credentialFiles.js
|
||||||
packages/lib/utils/joplinCloud.js
|
packages/lib/utils/joplinCloud.js
|
||||||
|
packages/lib/utils/webDAVUtils.js
|
||||||
|
packages/lib/utils/webDAVUtils.test.js
|
||||||
packages/lib/uuid.js
|
packages/lib/uuid.js
|
||||||
packages/lib/versionInfo.js
|
packages/lib/versionInfo.js
|
||||||
packages/lib/versionInfo.test.js
|
packages/lib/versionInfo.test.js
|
||||||
|
@ -354,7 +354,7 @@ export default class JoplinDatabase extends Database {
|
|||||||
// must be set in the synchronizer too.
|
// must be set in the synchronizer too.
|
||||||
|
|
||||||
// Note: v16 and v17 don't do anything. They were used to debug an issue.
|
// 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);
|
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 ""');
|
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] };
|
const updateVersionQuery = { sql: 'UPDATE version SET version = ?', params: [targetVersion] };
|
||||||
|
|
||||||
queries.push(updateVersionQuery);
|
queries.push(updateVersionQuery);
|
||||||
|
@ -5,6 +5,7 @@ const { FileApi } = require('./file-api.js');
|
|||||||
const Synchronizer = require('./Synchronizer').default;
|
const Synchronizer = require('./Synchronizer').default;
|
||||||
const WebDavApi = require('./WebDavApi');
|
const WebDavApi = require('./WebDavApi');
|
||||||
const { FileApiDriverWebDav } = require('./file-api-driver-webdav');
|
const { FileApiDriverWebDav } = require('./file-api-driver-webdav');
|
||||||
|
const checkProviderIsSupported = require('./utils/webDAVUtils').default;
|
||||||
|
|
||||||
class SyncTargetWebDAV extends BaseSyncTarget {
|
class SyncTargetWebDAV extends BaseSyncTarget {
|
||||||
static id() {
|
static id() {
|
||||||
@ -56,6 +57,7 @@ class SyncTargetWebDAV extends BaseSyncTarget {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
checkProviderIsSupported(options.path());
|
||||||
const result = await fileApi.stat('');
|
const result = await fileApi.stat('');
|
||||||
if (!result) throw new Error(`WebDAV directory not found: ${options.path()}`);
|
if (!result) throw new Error(`WebDAV directory not found: ${options.path()}`);
|
||||||
output.ok = true;
|
output.ok = true;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
const { basicDelta } = require('./file-api');
|
const { basicDelta } = require('./file-api');
|
||||||
const { rtrimSlashes, ltrimSlashes } = require('./path-utils');
|
const { rtrimSlashes, ltrimSlashes } = require('./path-utils');
|
||||||
const JoplinError = require('./JoplinError').default;
|
const JoplinError = require('./JoplinError').default;
|
||||||
|
const Setting = require('./models/Setting').default;
|
||||||
|
const checkProviderIsSupported = require('./utils/webDAVUtils').default;
|
||||||
|
|
||||||
class FileApiDriverWebDav {
|
class FileApiDriverWebDav {
|
||||||
constructor(api) {
|
constructor(api) {
|
||||||
@ -224,6 +226,10 @@ class FileApiDriverWebDav {
|
|||||||
await this.delete('');
|
await this.delete('');
|
||||||
await this.mkdir('');
|
await this.mkdir('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initialize() {
|
||||||
|
checkProviderIsSupported(Setting.value('sync.6.path'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { FileApiDriverWebDav };
|
module.exports = { FileApiDriverWebDav };
|
||||||
|
21
packages/lib/migrations/42.ts
Normal file
21
packages/lib/migrations/42.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import Setting from '../models/Setting';
|
||||||
|
import checkProviderIsSupported from '../utils/webDAVUtils';
|
||||||
|
|
||||||
|
interface Script {
|
||||||
|
exec: ()=> Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const script: Script = <Script>{};
|
||||||
|
|
||||||
|
script.exec = async () => {
|
||||||
|
try {
|
||||||
|
checkProviderIsSupported(Setting.value('sync.6.path'));
|
||||||
|
Setting.setValue('sync.allowUnsupportedProviders', 0);
|
||||||
|
} catch (error) {
|
||||||
|
Setting.setValue('sync.allowUnsupportedProviders', 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default script;
|
||||||
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
|||||||
import BaseModel from '../BaseModel';
|
import BaseModel from '../BaseModel';
|
||||||
|
import migration42 from '../migrations/42';
|
||||||
|
|
||||||
const migrationScripts: Record<number, any> = {
|
const migrationScripts: Record<number, any> = {
|
||||||
20: require('../migrations/20.js'),
|
20: require('../migrations/20.js'),
|
||||||
27: require('../migrations/27.js'),
|
27: require('../migrations/27.js'),
|
||||||
33: require('../migrations/33.js'),
|
33: require('../migrations/33.js'),
|
||||||
35: require('../migrations/35.js'),
|
35: require('../migrations/35.js'),
|
||||||
|
42: migration42,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class Migration extends BaseModel {
|
export default class Migration extends BaseModel {
|
||||||
|
@ -1671,6 +1671,12 @@ class Setting extends BaseModel {
|
|||||||
// storage: SettingStorage.File,
|
// storage: SettingStorage.File,
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
'sync.allowUnsupportedProviders': {
|
||||||
|
value: -1,
|
||||||
|
type: SettingItemType.Int,
|
||||||
|
public: false,
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.metadata_ = Object.assign(this.metadata_, this.customMetadata_);
|
this.metadata_ = Object.assign(this.metadata_, this.customMetadata_);
|
||||||
|
43
packages/lib/utils/webDAVUtils.test.ts
Normal file
43
packages/lib/utils/webDAVUtils.test.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import checkProviderIsSupported from './webDAVUtils';
|
||||||
|
import Setting from '../models/Setting';
|
||||||
|
|
||||||
|
describe('checkProviderIsSupported', () => {
|
||||||
|
describe('when no unsupported provider is already configured', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
Setting.setValue('sync.allowUnsupportedProviders', 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw when no provider path is provided ', () => {
|
||||||
|
expect(() => checkProviderIsSupported('')).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw when a valid provider path is provided', () => {
|
||||||
|
expect(() => checkProviderIsSupported('https://good-webdav-provider.com')).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw when a valid provider path with a name that contains an unsupported provider is provided', () => {
|
||||||
|
expect(() => checkProviderIsSupported('https://hopcloudabc.com')).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error with the name of the provider when an unsupported provider path is provided', () => {
|
||||||
|
expect(() => checkProviderIsSupported('https://pcloud.com')).toThrowError('The WebDAV implementation of pcloud is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.');
|
||||||
|
|
||||||
|
expect(() => checkProviderIsSupported('https://api.pcloud.com')).toThrowError('The WebDAV implementation of pcloud is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.');
|
||||||
|
|
||||||
|
expect(() => checkProviderIsSupported('https://api-pcloud-test.com')).toThrowError('The WebDAV implementation of pcloud is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.');
|
||||||
|
});
|
||||||
|
expect(() => checkProviderIsSupported('?param=pcloud')).toThrowError('The WebDAV implementation of pcloud is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when an unsupported provider is already configured', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
Setting.setValue('sync.allowUnsupportedProviders', 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw when an unsupported provider is already configured', () => {
|
||||||
|
expect(() => checkProviderIsSupported('pcloud')).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
21
packages/lib/utils/webDAVUtils.ts
Normal file
21
packages/lib/utils/webDAVUtils.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { _ } from '../locale';
|
||||||
|
import Setting from '../models/Setting';
|
||||||
|
|
||||||
|
export const checkProviderIsSupported = (path: string): void => {
|
||||||
|
if (Setting.value('sync.allowUnsupportedProviders') === 1) return;
|
||||||
|
|
||||||
|
const unsupportedProviders = ['pcloud', 'jianguoyun'];
|
||||||
|
for (const p of unsupportedProviders) {
|
||||||
|
// For a provider named abc, this regex will match the provider's name if enclosed by either '/', '.', '-', '=' or end of string.
|
||||||
|
// E.g: https://abc.com, https://api.abc.com, https://api-abc-test.com, https://api/test?param=abc
|
||||||
|
//
|
||||||
|
// It will not match a provider which name happens to contain an unsupported provider (i.e a substring).
|
||||||
|
// E.g: https://fooabc.com
|
||||||
|
const pattern = `(?<=[-/.=])${p}(?=[-/.=]|$)`;
|
||||||
|
if (path.search(new RegExp(pattern)) !== -1) {
|
||||||
|
throw new Error(_('The WebDAV implementation of %s is incompatible with Joplin, and as such is no longer supported. Please use a different sync method.', p));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default checkProviderIsSupported;
|
Loading…
Reference in New Issue
Block a user