UNPKG

@sync-in/server

Version:

The secure, open-source platform for file storage, sharing, collaboration, and sync

167 lines (166 loc) 5.21 kB
/* * Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com> * This file is part of Sync-in | The open source file sync and share solution * See the LICENSE file for licensing details */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get }); } _export(exports, { get DAV_ERROR () { return DAV_ERROR; }, get DAV_ERROR_RES () { return DAV_ERROR_RES; }, get LOCK_DISCOVERY () { return LOCK_DISCOVERY; }, get LOCK_PROP () { return LOCK_PROP; }, get MULTI_STATUS () { return MULTI_STATUS; }, get PROP () { return PROP; }, get PROPFIND_ALL_PROP () { return PROPFIND_ALL_PROP; }, get PROPFIND_COLLECTION () { return PROPFIND_COLLECTION; }, get PROP_STAT () { return PROP_STAT; }, get SUPPORTED_LOCKS () { return SUPPORTED_LOCKS; }, get XML_DAV_NS () { return XML_DAV_NS; } }); const _nodehttp = /*#__PURE__*/ _interop_require_default(require("node:http")); const _appconstants = require("../../../app.constants"); const _shared = require("../../../common/shared"); const _webdav = require("../constants/webdav"); const _xml = require("./xml"); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const XML_DAV_NS = { [`${_xml.XML_NS}:${_webdav.NS_PREFIX}`]: `${_webdav.NS_DAV}` }; const PROPFIND_COLLECTION = { [`${_webdav.NS_PREFIX}:collection`]: null }; const PROPFIND_ALL_PROP = { [`${_webdav.NS_PREFIX}:propfind`]: { [`${_webdav.NS_PREFIX}:${_webdav.PROPSTAT.ALLPROP}`]: null, ...XML_DAV_NS } }; const SUPPORTED_LOCKS = { [`${_webdav.NS_PREFIX}:lockentry`]: [ { [`${_webdav.NS_PREFIX}:lockscope`]: { [`${_webdav.NS_PREFIX}:exclusive`]: null }, [`${_webdav.NS_PREFIX}:locktype`]: { [`${_webdav.NS_PREFIX}:write`]: null } }, { [`${_webdav.NS_PREFIX}:lockscope`]: { [`${_webdav.NS_PREFIX}:shared`]: null }, [`${_webdav.NS_PREFIX}:locktype`]: { [`${_webdav.NS_PREFIX}:write`]: null } } ] }; function PROP(prop, httpVersion, httpStatus, description) { return { [`${_webdav.NS_PREFIX}:prop`]: prop, [`${_webdav.NS_PREFIX}:status`]: `${httpVersion} ${httpStatus} ${_nodehttp.default.STATUS_CODES[httpStatus]}`, [`${_webdav.NS_PREFIX}:responsedescription`]: description ? { [`${_webdav.NS_PREFIX}:error`]: { [`${_webdav.NS_PREFIX}:${description}`]: null } } : undefined }; } function PROP_STAT(href, props) { return { [`${_webdav.NS_PREFIX}:href`]: href, [`${_webdav.NS_PREFIX}:propstat`]: props }; } function MULTI_STATUS(content) { return { [`${_webdav.NS_PREFIX}:multistatus`]: { [`${_webdav.NS_PREFIX}:response`]: content, ...XML_DAV_NS } }; } function LOCK_DISCOVERY(locks) { // only locktype write is currently implemented in RFC const activeLocks = []; for (const lock of locks){ activeLocks.push({ [`${_webdav.NS_PREFIX}:activelock`]: { [`${_webdav.NS_PREFIX}:locktype`]: { [`${_webdav.NS_PREFIX}:write`]: null }, [`${_webdav.NS_PREFIX}:lockscope`]: { [`${_webdav.NS_PREFIX}:${lock.davLock?.lockscope || _webdav.LOCK_SCOPE.EXCLUSIVE}`]: null }, [`${_webdav.NS_PREFIX}:locktoken`]: { [`${_webdav.NS_PREFIX}:href`]: lock.davLock?.locktoken || _appconstants.SERVER_NAME }, [`${_webdav.NS_PREFIX}:lockroot`]: { [`${_webdav.NS_PREFIX}:href`]: (0, _shared.encodeUrl)(lock.davLock?.lockroot || lock.dbFilePath) }, [`${_webdav.NS_PREFIX}:owner`]: lock.davLock?.owner || 'WebDAV', [`${_webdav.NS_PREFIX}:timeout`]: `Second-${Math.floor(lock.expiration - (0, _shared.currentTimeStamp)())}`, [`${_webdav.NS_PREFIX}:depth`]: lock.depth } }); } return activeLocks; } function LOCK_PROP(locks) { return { [`${_webdav.NS_PREFIX}:prop`]: { [`${_webdav.NS_PREFIX}:lockdiscovery`]: LOCK_DISCOVERY(locks), ...XML_DAV_NS } }; } function DAV_ERROR(error, href) { return (0, _xml.xmlBuild)({ 'ns0:error': { [`ns0:${error}`]: href ? [ { 'ns0:href': (0, _shared.encodeUrl)(href) } ] : '', [`${_xml.XML_NS}:ns0`]: `${_webdav.NS_DAV}` } }); } function DAV_ERROR_RES(code, error, res, href) { return res.status(code).type(_webdav.XML_CONTENT_TYPE).send(DAV_ERROR(error, href)); } //# sourceMappingURL=webdav.js.map