Files
wekan/models/lib/webdavStorage.js
T
Lauri Ojansivu 4234081752 WebDAV attachment storage: attachments in Nextcloud Files or any WebDAV server.
Admin Panel -> Attachments has a WebDAV (Nextcloud Files) pane beside S3,
Azure and Google Cloud Storage: a folder address, a user and an app
password, with the same read and write switches, connection test, default
storage choice and Move Attachment target as the others. Files are stored
with PUT, read with GET and removed with DELETE; the folders are made with
MKCOL as needed, and the connection test is a PROPFIND of the folder.

The password is a secret field like the other backends' keys: never
published, and kept when the form is saved without it. The address is the
site admin's own setting, so a Nextcloud on WeKan's own network can be
used; redirects are refused so it cannot be pointed somewhere else.

With the CalDAV sync of the previous commit this completes #687. The
Nextcloud ExApp is built by .github/workflows/nextcloud.yml; publishing it
to the Nextcloud app store is the maintainer's own step.

Thanks to scriptPilot and xet7 !

Fixes #687.
2026-10-14 16:46:59 +03:00

38 lines
1.5 KiB
JavaScript

'use strict';
// #687: the addresses of WebDAV attachment storage (server/lib/webdavAdapter.js).
// An object key is its file's path under the configured folder; each segment
// is URL-encoded, and a key that tries to climb out ("..") is refused.
// Pure: tests/webdavStorage.test.cjs.
function segments(path) {
const parts = String(path || '').split('/').filter(Boolean);
if (parts.some(p => p === '.' || p === '..')) throw new Error('invalid WebDAV path');
return parts.map(p => encodeURIComponent(p));
}
function base(endpoint) {
return String(endpoint || '').replace(/\/+$/, '');
}
function webdavObjectUrl(endpoint, folder, key) {
return [base(endpoint), ...segments(folder), ...segments(key)].join('/');
}
// The collections to make, outermost first, so `key` can be stored.
function webdavCollectionUrls(endpoint, folder, key) {
const parts = [...segments(folder), ...segments(key).slice(0, -1)];
return parts.map((_, i) => `${[base(endpoint), ...parts.slice(0, i + 1)].join('/')}/`);
}
function validWebdavConfig(cfg) {
if (!cfg || !cfg.endpoint) return 'WebDAV endpoint is required.';
let u;
try { u = new URL(cfg.endpoint); } catch (e) { return 'WebDAV endpoint must be an http:// or https:// address.'; }
if (!['http:', 'https:'].includes(u.protocol) || u.username || u.password) return 'WebDAV endpoint must be an http:// or https:// address, without a user name or password in it.';
if (!cfg.bucket) return 'WebDAV folder is required.';
return null;
}
module.exports = { webdavObjectUrl, webdavCollectionUrls, validWebdavConfig };