2017-11-24 20:37:40 +02:00
|
|
|
const BaseSyncTarget = require('lib/BaseSyncTarget.js');
|
|
|
|
const { _ } = require('lib/locale.js');
|
2017-12-14 20:12:14 +02:00
|
|
|
const Setting = require('lib/models/Setting.js');
|
2017-11-24 20:37:40 +02:00
|
|
|
const { FileApi } = require('lib/file-api.js');
|
|
|
|
const { FileApiDriverLocal } = require('lib/file-api-driver-local.js');
|
|
|
|
const { Synchronizer } = require('lib/synchronizer.js');
|
|
|
|
|
2017-11-24 21:09:15 +02:00
|
|
|
class SyncTargetFilesystem extends BaseSyncTarget {
|
2017-11-24 20:59:16 +02:00
|
|
|
static id() {
|
2017-11-24 20:37:40 +02:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2017-11-24 21:21:30 +02:00
|
|
|
static targetName() {
|
|
|
|
return 'filesystem';
|
|
|
|
}
|
|
|
|
|
2017-11-24 20:59:16 +02:00
|
|
|
static label() {
|
2017-11-24 20:37:40 +02:00
|
|
|
return _('File system');
|
|
|
|
}
|
|
|
|
|
2018-03-26 19:33:55 +02:00
|
|
|
async isAuthenticated() {
|
2017-11-24 20:37:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-24 20:59:16 +02:00
|
|
|
async initFileApi() {
|
2018-01-17 23:01:41 +02:00
|
|
|
const syncPath = Setting.value('sync.2.path');
|
|
|
|
const driver = new FileApiDriverLocal();
|
|
|
|
const fileApi = new FileApi(syncPath, driver);
|
2017-11-24 20:37:40 +02:00
|
|
|
fileApi.setLogger(this.logger());
|
2017-11-24 21:09:15 +02:00
|
|
|
fileApi.setSyncTargetId(SyncTargetFilesystem.id());
|
2018-01-17 23:01:41 +02:00
|
|
|
await driver.mkdir(syncPath);
|
2017-11-24 20:37:40 +02:00
|
|
|
return fileApi;
|
|
|
|
}
|
|
|
|
|
|
|
|
async initSynchronizer() {
|
2017-11-24 20:59:16 +02:00
|
|
|
return new Synchronizer(this.db(), await this.fileApi(), Setting.value('appType'));
|
2017-11-24 20:37:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = SyncTargetFilesystem;
|