mirror of https://github.com/keeweb/keeweb.git
storage
This commit is contained in:
parent
ebfdff90c7
commit
2f93e53716
|
@ -1,32 +1,32 @@
|
|||
import { IoBrowserCache } from 'storage/io-browser-cache';
|
||||
import { StorageBase } from 'storage/storage-base';
|
||||
|
||||
const StorageCache = StorageBase.extend({
|
||||
name: 'cache',
|
||||
enabled: IoBrowserCache.enabled,
|
||||
system: true,
|
||||
class StorageCache extends StorageBase {
|
||||
name = 'cache';
|
||||
enabled = IoBrowserCache.enabled;
|
||||
system = true;
|
||||
|
||||
io: null,
|
||||
io = null;
|
||||
|
||||
init() {
|
||||
StorageBase.prototype.init.call(this);
|
||||
super.init();
|
||||
this.io = new IoBrowserCache({
|
||||
cacheName: 'FilesCache',
|
||||
logger: this.logger
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
save(id, opts, data, callback) {
|
||||
this.io.save(id, data, callback);
|
||||
},
|
||||
}
|
||||
|
||||
load(id, opts, callback) {
|
||||
this.io.load(id, callback);
|
||||
},
|
||||
}
|
||||
|
||||
remove(id, opts, callback) {
|
||||
this.io.remove(id, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { StorageCache };
|
||||
|
|
|
@ -11,12 +11,12 @@ const DropboxCustomErrors = {
|
|||
BadKey: 'bad-key'
|
||||
};
|
||||
|
||||
const StorageDropbox = StorageBase.extend({
|
||||
name: 'dropbox',
|
||||
icon: 'dropbox',
|
||||
enabled: true,
|
||||
uipos: 20,
|
||||
backup: true,
|
||||
class StorageDropbox extends StorageBase {
|
||||
name = 'dropbox';
|
||||
icon = 'dropbox';
|
||||
enabled = true;
|
||||
uipos = 20;
|
||||
backup = true;
|
||||
|
||||
_toFullPath(path) {
|
||||
const rootFolder = this.appSettings.dropboxFolder;
|
||||
|
@ -24,7 +24,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
path = UrlFormat.fixSlashes('/' + rootFolder + '/' + path);
|
||||
}
|
||||
return path;
|
||||
},
|
||||
}
|
||||
|
||||
_toRelPath(path) {
|
||||
const rootFolder = this.appSettings.dropboxFolder;
|
||||
|
@ -38,7 +38,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
path = UrlFormat.fixSlashes('/' + path);
|
||||
}
|
||||
return path;
|
||||
},
|
||||
}
|
||||
|
||||
_fixConfigFolder(folder) {
|
||||
folder = folder.replace(/\\/g, '/').trim();
|
||||
|
@ -46,21 +46,21 @@ const StorageDropbox = StorageBase.extend({
|
|||
folder = folder.substr(1);
|
||||
}
|
||||
return folder;
|
||||
},
|
||||
}
|
||||
|
||||
_getKey() {
|
||||
return this.appSettings.dropboxAppKey || DropboxKeys.AppFolder;
|
||||
},
|
||||
}
|
||||
|
||||
_isValidKey() {
|
||||
const key = this._getKey();
|
||||
const isBuiltIn = key === DropboxKeys.AppFolder || key === DropboxKeys.FullDropbox;
|
||||
return key && key.indexOf(' ') < 0 && (!isBuiltIn || this._canUseBuiltInKeys());
|
||||
},
|
||||
}
|
||||
|
||||
_canUseBuiltInKeys() {
|
||||
return !Features.isSelfHosted;
|
||||
},
|
||||
}
|
||||
|
||||
_getOAuthConfig() {
|
||||
return {
|
||||
|
@ -70,11 +70,11 @@ const StorageDropbox = StorageBase.extend({
|
|||
width: 600,
|
||||
height: 400
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
needShowOpenConfig() {
|
||||
return !this._isValidKey();
|
||||
},
|
||||
}
|
||||
|
||||
getOpenConfig() {
|
||||
return {
|
||||
|
@ -97,7 +97,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
getSettingsConfig() {
|
||||
const fields = [];
|
||||
|
@ -142,7 +142,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
fields.push(folderField);
|
||||
}
|
||||
return { fields };
|
||||
},
|
||||
}
|
||||
|
||||
applyConfig(config, callback) {
|
||||
if (config.key === DropboxKeys.AppFolder || config.key === DropboxKeys.FullDropbox) {
|
||||
|
@ -157,7 +157,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
dropboxFolder: config.folder
|
||||
});
|
||||
callback();
|
||||
},
|
||||
}
|
||||
|
||||
applySetting(key, value) {
|
||||
switch (key) {
|
||||
|
@ -190,18 +190,18 @@ const StorageDropbox = StorageBase.extend({
|
|||
return;
|
||||
}
|
||||
this.appSettings[key] = value;
|
||||
},
|
||||
}
|
||||
|
||||
getPathForName(fileName) {
|
||||
return '/' + fileName + '.kdbx';
|
||||
},
|
||||
}
|
||||
|
||||
_encodeJsonHttpHeader(json) {
|
||||
return json.replace(
|
||||
/[\u007f-\uffff]/g,
|
||||
c => '\\u' + ('000' + c.charCodeAt(0).toString(16)).slice(-4)
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
_apiCall(args) {
|
||||
this._oauthAuthorize(err => {
|
||||
|
@ -246,7 +246,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
load(path, opts, callback) {
|
||||
this.logger.debug('Load', path);
|
||||
|
@ -264,7 +264,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
},
|
||||
error: callback
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
stat(path, opts, callback) {
|
||||
this.logger.debug('Stat', path);
|
||||
|
@ -291,7 +291,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
},
|
||||
error: callback
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
save(path, opts, data, callback, rev) {
|
||||
this.logger.debug('Save', path, rev);
|
||||
|
@ -313,7 +313,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
},
|
||||
error: callback
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
list(dir, callback) {
|
||||
this.logger.debug('List');
|
||||
|
@ -336,7 +336,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
},
|
||||
error: callback
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
remove(path, callback) {
|
||||
this.logger.debug('Remove', path);
|
||||
|
@ -351,7 +351,7 @@ const StorageDropbox = StorageBase.extend({
|
|||
},
|
||||
error: callback
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
mkdir(path, callback) {
|
||||
this.logger.debug('Make dir', path);
|
||||
|
@ -366,14 +366,14 @@ const StorageDropbox = StorageBase.extend({
|
|||
},
|
||||
error: callback
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
setEnabled(enabled) {
|
||||
if (!enabled) {
|
||||
this._oauthRevokeToken();
|
||||
}
|
||||
StorageBase.prototype.setEnabled.call(this, enabled);
|
||||
super.setEnabled(enabled);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { StorageDropbox };
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import { Launcher } from 'comp/launcher';
|
||||
import { StorageBase } from 'storage/storage-base';
|
||||
|
||||
const StorageFileCache = StorageBase.extend({
|
||||
name: 'cache',
|
||||
enabled: !!Launcher,
|
||||
system: true,
|
||||
class StorageFileCache extends StorageBase {
|
||||
name = 'cache';
|
||||
enabled = !!Launcher;
|
||||
system = true;
|
||||
|
||||
path: null,
|
||||
path = null;
|
||||
|
||||
getPath(id) {
|
||||
return Launcher.joinPath(this.path, id);
|
||||
},
|
||||
}
|
||||
|
||||
initFs(callback) {
|
||||
if (this.path) {
|
||||
|
@ -34,7 +34,7 @@ const StorageFileCache = StorageBase.extend({
|
|||
Launcher.mkdir(path, setPath);
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
save(id, opts, data, callback) {
|
||||
this.logger.debug('Save', id);
|
||||
|
@ -54,7 +54,7 @@ const StorageFileCache = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
load(id, opts, callback) {
|
||||
this.logger.debug('Load', id);
|
||||
|
@ -74,7 +74,7 @@ const StorageFileCache = StorageBase.extend({
|
|||
return callback && callback(null, data.buffer);
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
remove(id, opts, callback) {
|
||||
this.logger.debug('Remove', id);
|
||||
|
@ -102,6 +102,6 @@ const StorageFileCache = StorageBase.extend({
|
|||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { StorageFileCache };
|
||||
|
|
|
@ -3,12 +3,12 @@ import { StorageBase } from 'storage/storage-base';
|
|||
|
||||
const fileWatchers = {};
|
||||
|
||||
const StorageFile = StorageBase.extend({
|
||||
name: 'file',
|
||||
icon: 'hdd-o',
|
||||
enabled: !!Launcher,
|
||||
system: true,
|
||||
backup: true,
|
||||
class StorageFile extends StorageBase {
|
||||
name = 'file';
|
||||
icon = 'hdd-o';
|
||||
enabled = !!Launcher;
|
||||
system = true;
|
||||
backup = true;
|
||||
|
||||
load(path, opts, callback) {
|
||||
this.logger.debug('Load', path);
|
||||
|
@ -36,7 +36,7 @@ const StorageFile = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
stat(path, opts, callback) {
|
||||
this.logger.debug('Stat', path);
|
||||
|
@ -56,7 +56,7 @@ const StorageFile = StorageBase.extend({
|
|||
callback(null, { rev: fileRev });
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
save(path, opts, data, callback, rev) {
|
||||
this.logger.debug('Save', path, rev);
|
||||
|
@ -105,7 +105,7 @@ const StorageFile = StorageBase.extend({
|
|||
} else {
|
||||
write();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
mkdir(path, callback) {
|
||||
this.logger.debug('Make dir', path);
|
||||
|
@ -124,7 +124,7 @@ const StorageFile = StorageBase.extend({
|
|||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
watch(path, callback) {
|
||||
const names = Launcher.parsePath(path);
|
||||
|
@ -147,7 +147,7 @@ const StorageFile = StorageBase.extend({
|
|||
callback
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
unwatch(path) {
|
||||
const names = Launcher.parsePath(path);
|
||||
|
@ -163,7 +163,7 @@ const StorageFile = StorageBase.extend({
|
|||
delete fileWatchers[names.dir];
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
fsWatcherChange(dirname, evt, fileName) {
|
||||
const watcher = fileWatchers[dirname];
|
||||
|
@ -176,6 +176,6 @@ const StorageFile = StorageBase.extend({
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { StorageFile };
|
||||
|
|
|
@ -7,21 +7,21 @@ const GDriveClientId = {
|
|||
};
|
||||
const NewFileIdPrefix = 'NewFile:';
|
||||
|
||||
const StorageGDrive = StorageBase.extend({
|
||||
name: 'gdrive',
|
||||
enabled: true,
|
||||
uipos: 30,
|
||||
iconSvg:
|
||||
class StorageGDrive extends StorageBase {
|
||||
name = 'gdrive';
|
||||
enabled = true;
|
||||
uipos = 30;
|
||||
iconSvg =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><path d="M86.657536,76.246208 L47.768064,9 L89.111168,' +
|
||||
'9 L128,76.246208 L86.657536,76.246208 Z M25.010048,119.08 L102.690048,119.08 L123.36256,83.24 L45.68064,83.24 L25.010048,119.08 L25.010048,' +
|
||||
'119.08 Z M38.793088,9.003712 L0,76.30496 L20.671872,112.110016 L59.464704,44.808128 L38.793088,9.003712 Z"></path></svg>',
|
||||
'119.08 Z M38.793088,9.003712 L0,76.30496 L20.671872,112.110016 L59.464704,44.808128 L38.793088,9.003712 Z"></path></svg>';
|
||||
|
||||
_baseUrl: 'https://www.googleapis.com/drive/v3',
|
||||
_baseUrlUpload: 'https://www.googleapis.com/upload/drive/v3',
|
||||
_baseUrl = 'https://www.googleapis.com/drive/v3';
|
||||
_baseUrlUpload = 'https://www.googleapis.com/upload/drive/v3';
|
||||
|
||||
getPathForName(fileName) {
|
||||
return NewFileIdPrefix + fileName;
|
||||
},
|
||||
}
|
||||
|
||||
load(path, opts, callback) {
|
||||
this.stat(path, opts, (err, stat) => {
|
||||
|
@ -48,7 +48,7 @@ const StorageGDrive = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
stat(path, opts, callback) {
|
||||
if (path.lastIndexOf(NewFileIdPrefix, 0) === 0) {
|
||||
|
@ -75,7 +75,7 @@ const StorageGDrive = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
save(path, opts, data, callback, rev) {
|
||||
this._oauthAuthorize(err => {
|
||||
|
@ -153,7 +153,7 @@ const StorageGDrive = StorageBase.extend({
|
|||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
list(dir, callback) {
|
||||
this._oauthAuthorize(err => {
|
||||
|
@ -208,7 +208,7 @@ const StorageGDrive = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
remove(path, callback) {
|
||||
this.logger.debug('Remove', path);
|
||||
|
@ -228,14 +228,14 @@ const StorageGDrive = StorageBase.extend({
|
|||
return callback && callback(err);
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
setEnabled(enabled) {
|
||||
if (!enabled) {
|
||||
this._oauthRevokeToken('https://accounts.google.com/o/oauth2/revoke?token={token}');
|
||||
}
|
||||
StorageBase.prototype.setEnabled.call(this, enabled);
|
||||
},
|
||||
super.setEnabled(enabled);
|
||||
}
|
||||
|
||||
_getOAuthConfig() {
|
||||
let clientId = this.appSettings.gdriveClientId;
|
||||
|
@ -253,6 +253,6 @@ const StorageGDrive = StorageBase.extend({
|
|||
height: 400
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { StorageGDrive };
|
||||
|
|
|
@ -6,11 +6,11 @@ const OneDriveClientId = {
|
|||
Local: '0000000044183D18'
|
||||
};
|
||||
|
||||
const StorageOneDrive = StorageBase.extend({
|
||||
name: 'onedrive',
|
||||
enabled: true,
|
||||
uipos: 40,
|
||||
iconSvg:
|
||||
class StorageOneDrive extends StorageBase {
|
||||
name = 'onedrive';
|
||||
enabled = true;
|
||||
uipos = 40;
|
||||
iconSvg =
|
||||
'<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" width="256" height="256" version="1.1" viewBox="0 0 256 256">' +
|
||||
'<g transform="translate(296.64282,-100.61434)"><g transform="translate(222.85714,-11.428576)"><g transform="matrix(0.83394139,0,0,0.83394139,' +
|
||||
'-86.101383,10.950635)"><path d="m-419.5 365.94c-18.48-4.62-28.77-19.31-28.81-41.1-0.01-6.97 0.49-10.31 2.23-14.79 4.26-10.99 15.55-19.27 ' +
|
||||
|
@ -21,13 +21,13 @@ const StorageOneDrive = StorageBase.extend({
|
|||
'0.81-4 0.95-7.5 0.85-21.78 15.15-40.97 35.1-47.14 10.78-3.33 24.33-2.51 36.05 2.18 3.72 1.49 3.3 1.81 11.16-8.5 4.65-6.1 14.05-13.68 21.74-17.55 ' +
|
||||
'8.3-4.17 16.94-6.09 27.26-6.07 28.86 0.07 53.73 18.12 62.92 45.67 2.94 8.8 2.79 11.27-0.67 11.34-1.51 0.03-5.85 0.86-9.63 1.85l-6.88 1.79-6.28-' +
|
||||
'6.28c-17.7-17.7-46.59-21.53-71.15-9.42-9.81 4.84-17.7 11.78-23.65 20.83-4.25 6.45-9.66 18.48-9.66 21.47 0 2.12-1.72 3.18-9.05 5.58-22.69 7.44-' +
|
||||
'35.94 24.63-35.93 46.62 0 8 2.06 17.8 4.93 23.41 1.08 2.11 1.68 4.13 1.34 4.47-0.88 0.88-29.11 0.58-33.01-0.35z" /></g></g></g></svg>',
|
||||
'35.94 24.63-35.93 46.62 0 8 2.06 17.8 4.93 23.41 1.08 2.11 1.68 4.13 1.34 4.47-0.88 0.88-29.11 0.58-33.01-0.35z" /></g></g></g></svg>';
|
||||
|
||||
_baseUrl: 'https://graph.microsoft.com/v1.0/me',
|
||||
_baseUrl = 'https://graph.microsoft.com/v1.0/me';
|
||||
|
||||
getPathForName(fileName) {
|
||||
return '/drive/root:/' + fileName + '.kdbx';
|
||||
},
|
||||
}
|
||||
|
||||
load(path, opts, callback) {
|
||||
this._oauthAuthorize(err => {
|
||||
|
@ -74,7 +74,7 @@ const StorageOneDrive = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
stat(path, opts, callback) {
|
||||
this._oauthAuthorize(err => {
|
||||
|
@ -106,7 +106,7 @@ const StorageOneDrive = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
save(path, opts, data, callback, rev) {
|
||||
this._oauthAuthorize(err => {
|
||||
|
@ -142,7 +142,7 @@ const StorageOneDrive = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
list(dir, callback) {
|
||||
this._oauthAuthorize(err => {
|
||||
|
@ -177,7 +177,7 @@ const StorageOneDrive = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
remove(path, callback) {
|
||||
this.logger.debug('Remove', path);
|
||||
|
@ -197,7 +197,7 @@ const StorageOneDrive = StorageBase.extend({
|
|||
return callback && callback(err);
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
mkdir(path, callback) {
|
||||
this._oauthAuthorize(err => {
|
||||
|
@ -224,7 +224,7 @@ const StorageOneDrive = StorageBase.extend({
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
setEnabled(enabled) {
|
||||
if (!enabled) {
|
||||
|
@ -234,8 +234,8 @@ const StorageOneDrive = StorageBase.extend({
|
|||
);
|
||||
this._oauthRevokeToken(url);
|
||||
}
|
||||
StorageBase.prototype.setEnabled.call(this, enabled);
|
||||
},
|
||||
super.setEnabled(enabled);
|
||||
}
|
||||
|
||||
_getClientId() {
|
||||
let clientId = this.appSettings.onedriveClientId;
|
||||
|
@ -246,7 +246,7 @@ const StorageOneDrive = StorageBase.extend({
|
|||
: OneDriveClientId.Production;
|
||||
}
|
||||
return clientId;
|
||||
},
|
||||
}
|
||||
|
||||
_getOAuthConfig() {
|
||||
const clientId = this._getClientId();
|
||||
|
@ -257,7 +257,7 @@ const StorageOneDrive = StorageBase.extend({
|
|||
width: 600,
|
||||
height: 500
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
_popupOpened(popupWindow) {
|
||||
if (popupWindow.webContents) {
|
||||
|
@ -276,6 +276,6 @@ if (document.querySelectorAll(selector).length === 1) document.querySelector(sel
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { StorageOneDrive };
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import { StorageBase } from 'storage/storage-base';
|
||||
|
||||
const StorageWebDav = StorageBase.extend({
|
||||
name: 'webdav',
|
||||
icon: 'server',
|
||||
enabled: true,
|
||||
uipos: 10,
|
||||
class StorageWebDav extends StorageBase {
|
||||
name = 'webdav';
|
||||
icon = 'server';
|
||||
enabled = true;
|
||||
uipos = 10;
|
||||
|
||||
needShowOpenConfig() {
|
||||
return true;
|
||||
},
|
||||
}
|
||||
|
||||
getOpenConfig() {
|
||||
return {
|
||||
|
@ -30,7 +30,7 @@ const StorageWebDav = StorageBase.extend({
|
|||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
getSettingsConfig() {
|
||||
return {
|
||||
|
@ -44,11 +44,11 @@ const StorageWebDav = StorageBase.extend({
|
|||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
applySetting(key, value) {
|
||||
this.appSettings[key] = value;
|
||||
},
|
||||
}
|
||||
|
||||
load(path, opts, callback) {
|
||||
this._request(
|
||||
|
@ -65,7 +65,7 @@ const StorageWebDav = StorageBase.extend({
|
|||
}
|
||||
: null
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
stat(path, opts, callback) {
|
||||
this._request(
|
||||
|
@ -82,7 +82,7 @@ const StorageWebDav = StorageBase.extend({
|
|||
}
|
||||
: null
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
save(path, opts, data, callback, rev) {
|
||||
const cb = function(err, xhr, stat) {
|
||||
|
@ -234,7 +234,7 @@ const StorageWebDav = StorageBase.extend({
|
|||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
fileOptsToStoreOpts(opts, file) {
|
||||
const result = { user: opts.user, encpass: opts.encpass };
|
||||
|
@ -250,7 +250,7 @@ const StorageWebDav = StorageBase.extend({
|
|||
result.encpass = btoa(encpass);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
}
|
||||
|
||||
storeOptsToFileOpts(opts, file) {
|
||||
const result = { user: opts.user, password: opts.password };
|
||||
|
@ -266,7 +266,7 @@ const StorageWebDav = StorageBase.extend({
|
|||
result.password = password;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
}
|
||||
|
||||
_request(config, callback) {
|
||||
const that = this;
|
||||
|
@ -362,6 +362,6 @@ const StorageWebDav = StorageBase.extend({
|
|||
xhr.send();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { StorageWebDav };
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import Backbone from 'backbone';
|
||||
import { Events } from 'framework/events';
|
||||
import { Links } from 'const/links';
|
||||
import { AppSettingsModel } from 'models/app-settings-model';
|
||||
|
@ -8,19 +7,17 @@ import { Logger } from 'util/logger';
|
|||
|
||||
const MaxRequestRetries = 3;
|
||||
|
||||
const StorageBase = function() {};
|
||||
class StorageBase {
|
||||
name = null;
|
||||
icon = null;
|
||||
iconSvg = null;
|
||||
enabled = false;
|
||||
system = false;
|
||||
uipos = null;
|
||||
|
||||
Object.assign(StorageBase.prototype, {
|
||||
name: null,
|
||||
icon: null,
|
||||
iconSvg: null,
|
||||
enabled: false,
|
||||
system: false,
|
||||
uipos: null,
|
||||
|
||||
logger: null,
|
||||
appSettings: AppSettingsModel,
|
||||
runtimeData: RuntimeDataModel,
|
||||
logger = null;
|
||||
appSettings = AppSettingsModel;
|
||||
runtimeData = RuntimeDataModel;
|
||||
|
||||
init() {
|
||||
if (!this.name) {
|
||||
|
@ -46,15 +43,15 @@ Object.assign(StorageBase.prototype, {
|
|||
}
|
||||
}
|
||||
return this;
|
||||
},
|
||||
}
|
||||
|
||||
setEnabled(enabled) {
|
||||
this.enabled = enabled;
|
||||
},
|
||||
}
|
||||
|
||||
handleOAuthReturnMessage(message) {
|
||||
this._oauthReturnMessage = message;
|
||||
},
|
||||
}
|
||||
|
||||
_xhr(config) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
@ -105,7 +102,7 @@ Object.assign(StorageBase.prototype, {
|
|||
data = new Uint8Array(data);
|
||||
}
|
||||
xhr.send(data);
|
||||
},
|
||||
}
|
||||
|
||||
_openPopup(url, title, width, height) {
|
||||
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;
|
||||
|
@ -143,7 +140,7 @@ Object.assign(StorageBase.prototype, {
|
|||
}
|
||||
|
||||
return window.open(url, title, settings);
|
||||
},
|
||||
}
|
||||
|
||||
_getOauthRedirectUrl() {
|
||||
let redirectUrl = window.location.href;
|
||||
|
@ -152,7 +149,7 @@ Object.assign(StorageBase.prototype, {
|
|||
}
|
||||
redirectUrl = redirectUrl.split('?')[0];
|
||||
return redirectUrl;
|
||||
},
|
||||
}
|
||||
|
||||
_oauthAuthorize(callback) {
|
||||
if (this._tokenIsValid(this._oauthToken)) {
|
||||
|
@ -202,9 +199,9 @@ Object.assign(StorageBase.prototype, {
|
|||
};
|
||||
Events.on('popup-closed', popupClosed);
|
||||
window.addEventListener('message', windowMessage);
|
||||
},
|
||||
}
|
||||
|
||||
_popupOpened(popupWindow) {},
|
||||
_popupOpened(popupWindow) {}
|
||||
|
||||
_oauthProcessReturn(message) {
|
||||
const token = this._oauthMsgToToken(message);
|
||||
|
@ -214,7 +211,7 @@ Object.assign(StorageBase.prototype, {
|
|||
this.logger.debug('OAuth token received');
|
||||
}
|
||||
return token;
|
||||
},
|
||||
}
|
||||
|
||||
_oauthMsgToToken(data) {
|
||||
if (!data.token_type) {
|
||||
|
@ -233,13 +230,13 @@ Object.assign(StorageBase.prototype, {
|
|||
scope: data.scope,
|
||||
userId: data.user_id
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
_oauthRefreshToken(callback) {
|
||||
this._oauthToken.expired = true;
|
||||
this.runtimeData[this.name + 'OAuthToken'] = this._oauthToken;
|
||||
this._oauthAuthorize(callback);
|
||||
},
|
||||
}
|
||||
|
||||
_oauthRevokeToken(url) {
|
||||
const token = this.runtimeData[this.name + 'OAuthToken'];
|
||||
|
@ -253,7 +250,7 @@ Object.assign(StorageBase.prototype, {
|
|||
delete this.runtimeData[this.name + 'OAuthToken'];
|
||||
this._oauthToken = null;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_tokenIsValid(token) {
|
||||
if (!token || token.expired) {
|
||||
|
@ -264,8 +261,6 @@ Object.assign(StorageBase.prototype, {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
StorageBase.extend = Backbone.Model.extend;
|
||||
}
|
||||
|
||||
export { StorageBase };
|
||||
|
|
Loading…
Reference in New Issue