Skip to content

Commit

Permalink
Cloud Data: "extraPath" api configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rodichenko committed Dec 25, 2023
1 parent 2104d3b commit 22737b2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const DEFAULT_APP_NAME = 'Cloud Data';
* @property {string} [api]
* @property {string} [server]
* @property {string} [extra]
* @property {string} [extraPath]
* @property {string} [username]
* @property {string} [password]
* @property {string} [name]
Expand Down Expand Up @@ -77,6 +78,10 @@ class Configuration extends TokenExpirationChecker {
return this.config?.extra;
}

get extraPath() {
return this.config?.extraPath;
}

get server() {
return this.config?.server;
}
Expand Down Expand Up @@ -260,6 +265,7 @@ class Configuration extends TokenExpirationChecker {
const {
api = this.api,
extra = this.extra,
extraPath = this.extraPath,
password = this.password,
name = this.name,
ignoreCertificateErrors = this.ignoreCertificateErrors,
Expand Down Expand Up @@ -306,6 +312,7 @@ class Configuration extends TokenExpirationChecker {
...(this.config || {}),
api,
extra,
extraPath,
server,
username,
password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ const WebDAVInterface = require('./interface');

class WebDAVAdapter extends WebBasedAdapter {
/**
* @param {FileSystemAdapterOptions & {rootName: string?, apiURL: string?, extraApiURL: string?, updatePermissions: boolean?, disclaimer?: string, restricted?: boolean}} options
* @param {FileSystemAdapterOptions & {rootName: string?, apiURL: string?, extraApiURL: string?, extraPath: string?, updatePermissions: boolean?, disclaimer?: string, restricted?: boolean}} options
*/
constructor(options) {
super(options);
this.name = this.name || 'Data Server';
this.apiURL = options?.apiURL;
this.extraApiURL = options?.extraApiURL;
this.extraPath = options?.extraPath;
this.rootName = options?.rootName;
this.storages = [];
this.ignoreCertificateErrors = options?.ignoreCertificateErrors;
Expand All @@ -26,6 +27,7 @@ class WebDAVAdapter extends WebBasedAdapter {
` password: ${this.password ? '***' : '<empty>'}`,
` api (for storage fetching): ${this.apiURL}`,
` extra api (chown, checksum):${this.extraApiURL}`,
` extra path(chown, checksum):${this.extraPath}`,
` ignore cert errors: ${!!this.ignoreCertificateErrors}`,
` update permissions: ${!!this.updatePermissions}`,
].join('\n');
Expand All @@ -42,6 +44,7 @@ class WebDAVAdapter extends WebBasedAdapter {
storages: this.storages,
apiURL: this.apiURL,
extraApiURL: this.extraApiURL,
extraPath: this.extraPath,
ignoreCertificateErrors: this.ignoreCertificateErrors,
updatePermissions: this.updatePermissions,
disclaimer: this.disclaimer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class WebDAVInterface extends WebBasedInterface {
* @property {string} [rootName]
* @property {string} [apiURL]
* @property {string} [extraApiURL]
* @property {string} [extraPath]
* @property {boolean} [ignoreCertificateErrors]
* @property {boolean} [updatePermissions]
* @property {string} [disclaimer]
Expand All @@ -59,6 +60,7 @@ class WebDAVInterface extends WebBasedInterface {
ignoreCertificateErrors: this.ignoreCertificateErrors,
});
}
this.webdavApiExtraPath = options.extraPath;
this.webdavApi = new WebDAVApi({
url: options.extraApiURL || options.url,
password: options.password,
Expand Down Expand Up @@ -136,11 +138,27 @@ class WebDAVInterface extends WebBasedInterface {
this.permissionsRequestTimeout = undefined;
}

correctWebdavApiPath(relativePath) {
if (!this.webdavApiExtraPath) {
return relativePath;
}
let result = this.webdavApiExtraPath;
if (result.endsWith('/')) {
result.slice(0, -1);
}
if (relativePath.startsWith('/')) {
result = result.concat(relativePath);
} else {
result = result.concat('/').concat(relativePath);
}
return result;
}

async sendPermissionsRequest(debounce = PERMISSIONS_REQUESTS_DEBOUNCE_MS) {
this.clearPermissionsRequestsTimeout();
if (this.permissionsRequests.length > 0 && this.updatePermissions) {
const send = async () => {
const path = this.permissionsRequests.slice();
const path = this.permissionsRequests.slice().map(this.correctWebdavApiPath.bind(this));
const list = '\n\n'.concat(path.join('\n')).concat('\n');
logger.log(`Sending ${path.length} permission${path.length === 1 ? '' : 's'} requests:${list}`);
this.permissionsRequests = [];
Expand Down Expand Up @@ -170,7 +188,7 @@ class WebDAVInterface extends WebBasedInterface {
}

getFilesChecksums(files = []) {
return this.webdavApi.getChecksum(files);
return this.webdavApi.getChecksum(files.map(this.correctWebdavApiPath.bind(this)));
}

async list(directory = '/') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class FileSystemAdapters extends EventEmitter {
password: this.configuration.password,
apiURL: this.configuration.api,
extraApiURL: this.configuration.extra,
extraPath: this.configuration.extraPath,
rootName: this.configuration.name,
ignoreCertificateErrors: this.configuration.ignoreCertificateErrors,
updatePermissions: this.configuration.updatePermissions,
Expand Down

0 comments on commit 22737b2

Please sign in to comment.