2017-11-24 20:37:40 +02:00
|
|
|
const BaseSyncTarget = require('lib/BaseSyncTarget.js');
|
2020-10-09 19:35:46 +02:00
|
|
|
const { _ } = require('lib/locale');
|
|
|
|
const Setting = require('lib/models/Setting').default;
|
2017-11-24 20:37:40 +02:00
|
|
|
const { FileApi } = require('lib/file-api.js');
|
|
|
|
const { FileApiDriverLocal } = require('lib/file-api-driver-local.js');
|
2020-10-09 19:35:46 +02:00
|
|
|
const Synchronizer = require('lib/Synchronizer').default;
|
2017-11-24 20:37:40 +02:00
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2020-02-08 13:59:19 +02:00
|
|
|
static unsupportedPlatforms() {
|
|
|
|
return ['ios'];
|
|
|
|
}
|
|
|
|
|
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;
|