Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebDAV support to backups #5398

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions lib/modules/backupAndRestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,39 @@ module.options = {
title: 'backupAndRestoreGoogleAccountTitle',
advanced: true,
},
webDAV: {
type: 'table',
addRowText: 'backupAndRestoreAddWebDAVAccount',
fields: [{
key: 'username',
name: 'backupAndRestoreUsername',
type: 'text',
}, {
key: 'password',
name: 'backupAndRestorePassword',
type: 'password',
}, {
key: 'url',
name: 'backupAndRestoreUrl',
type: 'text',
}, {
key: 'digest',
name: 'backupAndRestoreDigest',
type: 'boolean',
value: false,
}],
value: ([]: Array<[string, string, string, boolean]>),
description: 'backupAndRestoreWebDAVDesc',
title: 'backupAndRestoreWebDAVTitle',
onChange() {
Notifications.showNotification({
message: i18n('backupAndRestoreWarnNotification'),
notificationID: i18n('backupAndRestoreWarn'),
moduleID: module.moduleID,
closeDelay: 1000,
});
},
},
};

module.afterLoad = async () => {
Expand All @@ -112,6 +145,10 @@ module.afterLoad = async () => {
function getProvider(providerClass) {
return new providerClass().init({ // eslint-disable-line new-cap
googleLoginHint: module.options.googleAccount.value,
webDAVUsername: module.options.webDAV.value[0][0],
webDAVPassword: module.options.webDAV.value[0][1],
webDAVUrl: module.options.webDAV.value[0][2],
webDAVDigest: module.options.webDAV.value[0][3],
});
}

Expand Down
37 changes: 37 additions & 0 deletions lib/modules/backupAndRestore/providers/WebDAV.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* @flow */

import { AuthType, createClient } from 'webdav/web';
import { Provider } from './Provider';

const FILE = '/res-storage.json';

export class WebDAV extends Provider {
static key = 'webdav';
static text = 'WebDAV';
static supportsAutomaticBackups = true;

client: any;

// eslint-disable-next-line require-await
async init({ webDAVUrl, webDAVDigest, webDAVUsername, webDAVPassword }: *): Promise<Provider> { // eslint-disable-line no-empty-pattern
this.client = createClient(webDAVUrl, {
authType: webDAVDigest ? AuthType.digest : AuthType.password,
username: webDAVUsername,
password: webDAVPassword,
});

return this;
}

async read() {
try {
return await this.client.getFileContents(FILE);
} catch (e) {
throw new Error('Could not find backup.');
}
}

async write(data: string) {
await this.client.putFileContents(FILE, data);
}
}
1 change: 1 addition & 0 deletions lib/modules/backupAndRestore/providers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { File } from './File';
export { GoogleDrive } from './GoogleDrive';
export { OneDrive } from './OneDrive';
export { Dropbox } from './Dropbox';
export { WebDAV } from './WebDAV';
27 changes: 27 additions & 0 deletions locales/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,27 @@
"backupAndRestoreGoogleAccountDesc": {
"message": "If, and only if, you have multiple Google accounts logged in at once, enter the email of the account you want to use.\n\nIn most cases you will not need to use this option."
},
"backupAndRestoreAddWebDAVAccount": {
"message": "+add account"
},
"backupAndRestoreWebDAVTitle": {
"message": "WebDAV"
},
"backupAndRestoreWebDAVDesc": {
"message": "Configure a WebDAV account for use in RES backups"
},
"backupAndRestoreUsername": {
"message": "username"
},
"backupAndRestorePassword": {
"message": "password"
},
"backupAndRestoreUrl": {
"message": "url"
},
"backupAndRestoreDigest": {
"message": "uses digest"
},
"backupAndRestoreBackupTitle": {
"message": "Backup"
},
Expand All @@ -1884,6 +1905,12 @@
"backupAndRestoreSavedNotification": {
"message": "Backup saved to $1."
},
"backupAndRestoreWarnNotification": {
"message": "RES stores WebDAV credentials in plain text."
},
"backupAndRestoreWarn": {
"message": "Warning"
},
"backupAndRestoreFoundBackup": {
"message": "Found new automatic backup from $1."
},
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@
"lodash-es": "4.17.21",
"snudown-js": "3.2.2",
"sortablejs": "1.15.0",
"stream": "^0.0.2",
"suncalc": "1.9.0",
"tinycolor2": "1.4.2"
"tinycolor2": "1.4.2",
"webdav": "^4.9.0"
},
"devDependencies": {
"@babel/core": "7.17.10",
Expand Down