1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

All: Added sync config check to config screens

This commit is contained in:
Laurent Cozic
2018-02-06 18:59:36 +00:00
parent a25fcacace
commit fa5f418c22
13 changed files with 230 additions and 46 deletions

View File

@@ -12,8 +12,8 @@ class SyncTargetWebDAV extends BaseSyncTarget {
return 6;
}
constructor(db, options = null) {
super(db, options);
static supportsConfigCheck() {
return true;
}
static targetName() {
@@ -28,18 +28,49 @@ class SyncTargetWebDAV extends BaseSyncTarget {
return true;
}
async initFileApi() {
const options = {
baseUrl: () => Setting.value('sync.6.path'),
username: () => Setting.value('sync.6.username'),
password: () => Setting.value('sync.6.password'),
static async initFileApi_(options) {
const apiOptions = {
baseUrl: () => options.path,
username: () => options.username,
password: () => options.password,
};
const api = new WebDavApi(options);
const api = new WebDavApi(apiOptions);
const driver = new FileApiDriverWebDav(api);
const fileApi = new FileApi('', driver);
fileApi.setSyncTargetId(SyncTargetWebDAV.id());
fileApi.setSyncTargetId(this.id());
return fileApi;
}
static async checkConfig(options) {
const fileApi = await SyncTargetWebDAV.initFileApi_(options);
const output = {
ok: false,
errorMessage: '',
};
try {
const result = await fileApi.stat('');
if (!result) throw new Error('Could not access WebDAV directory');
output.ok = true;
} catch (error) {
output.errorMessage = error.message;
if (error.code) output.errorMessage += ' (Code ' + error.code + ')';
}
return output;
}
async initFileApi() {
const fileApi = await SyncTargetWebDAV.initFileApi_({
path: Setting.value('sync.6.path'),
username: Setting.value('sync.6.username'),
password: Setting.value('sync.6.password'),
});
fileApi.setLogger(this.logger());
return fileApi;
}