diff --git a/package-lock.json b/package-lock.json index 3db8beb30..15003e278 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,7 +38,7 @@ "vue-virtual-grid": "^2.5.0", "vuex": "^3.6.2", "vuex-router-sync": "^5.0.0", - "webdav": "^4.11.0" + "webdav": "^5.2.2" }, "devDependencies": { "@cypress/browserify-preprocessor": "^3.0.2", @@ -2119,6 +2119,14 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "node_modules/@buttercup/fetch": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@buttercup/fetch/-/fetch-0.1.1.tgz", + "integrity": "sha512-RwBiPEmPaZv3oLOPY0fcmAGYdd3A4FDoYDc7JN+qxGTXumrYAYEC1RpyCM2pHSr6RYpuaAeg4A1fJy+PiigPIA==", + "optionalDependencies": { + "node-fetch": "^3.3.0" + } + }, "node_modules/@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -8385,6 +8393,15 @@ "node": ">=0.10" } }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "optional": true, + "engines": { + "node": ">= 12" + } + }, "node_modules/data-urls": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-3.0.2.tgz", @@ -10539,18 +10556,24 @@ "dev": true }, "node_modules/fast-xml-parser": { - "version": "3.21.1", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.21.1.tgz", - "integrity": "sha512-FTFVjYoBOZTJekiUsawGsSYV9QL0A+zDYCRj7y34IO6Jg+2IMYEtQa+bbictpdpV8dHxXywqU7C0gRDEOFtBFg==", + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.2.5.tgz", + "integrity": "sha512-B9/wizE4WngqQftFPmdaMYlXoJlJOYxGQOanC77fq9k8+Z0v5dDSVh+3glErdIROP//s/jgb7ZuxKfB8nVyo0g==", + "funding": [ + { + "type": "paypal", + "url": "https://paypal.me/naturalintelligence" + }, + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], "dependencies": { - "strnum": "^1.0.4" + "strnum": "^1.0.5" }, "bin": { - "xml2js": "cli.js" - }, - "funding": { - "type": "paypal", - "url": "https://paypal.me/naturalintelligence" + "fxparser": "src/cli/cli.js" } }, "node_modules/fastest-levenshtein": { @@ -10604,6 +10627,29 @@ "pend": "~1.2.0" } }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "optional": true, + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, "node_modules/figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -10822,6 +10868,18 @@ "node": ">= 6" } }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "optional": true, + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -11407,9 +11465,9 @@ "peer": true }, "node_modules/hot-patcher": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/hot-patcher/-/hot-patcher-1.0.0.tgz", - "integrity": "sha512-3H8VH0PreeNsKMZw16nTHbUp4YoHCnPlawpsPXGJUR4qENDynl79b6Xk9CIFvLcH1qungBsCuzKcWyzoPPalTw==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/hot-patcher/-/hot-patcher-2.0.0.tgz", + "integrity": "sha512-rwJ0ZqSFgm+5oD0KiGBVinyPWRJESRSsHlEWDzZjyOe/OfhD9tynHqUyUIGX2fWuV+BihW4nXxeoZRJVHid64w==" }, "node_modules/hpack.js": { "version": "2.1.6", @@ -12289,27 +12347,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/is-svg/node_modules/fast-xml-parser": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.2.5.tgz", - "integrity": "sha512-B9/wizE4WngqQftFPmdaMYlXoJlJOYxGQOanC77fq9k8+Z0v5dDSVh+3glErdIROP//s/jgb7ZuxKfB8nVyo0g==", - "funding": [ - { - "type": "paypal", - "url": "https://paypal.me/naturalintelligence" - }, - { - "type": "github", - "url": "https://github.com/sponsors/NaturalIntelligence" - } - ], - "dependencies": { - "strnum": "^1.0.5" - }, - "bin": { - "fxparser": "src/cli/cli.js" - } - }, "node_modules/is-symbol": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", @@ -16105,6 +16142,43 @@ "resolved": "https://registry.npmjs.org/nested-property/-/nested-property-4.0.0.tgz", "integrity": "sha512-yFehXNWRs4cM0+dz7QxCd06hTbWbSkV0ISsqBfkntU6TOY4Qm3Q88fRRLOddkGh2Qq6dZvnKVAahfhjcUvLnyA==" }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "optional": true, + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz", + "integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==", + "optional": true, + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, "node_modules/node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -21167,17 +21241,26 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "optional": true, + "engines": { + "node": ">= 8" + } + }, "node_modules/webdav": { - "version": "4.11.2", - "resolved": "https://registry.npmjs.org/webdav/-/webdav-4.11.2.tgz", - "integrity": "sha512-Ht9TPD5EB7gYW0YmhRcE5NW0/dn/HQfyLSPQY1Rw1coQ5MQTUooAQ9Bpqt4EU7QLw0b95tX4cU59R+SIojs9KQ==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/webdav/-/webdav-5.2.2.tgz", + "integrity": "sha512-CTnhTTKug7pKbMqcvrnGNr4rV9qhWXV1sLk1PpN4BOskqDT+cEfFx4Y4VlcFXUX6lSUFsQBm9Ka8+6dIe0doQQ==", "dependencies": { - "axios": "^0.27.2", + "@buttercup/fetch": "^0.1.1", "base-64": "^1.0.0", "byte-length": "^1.0.2", - "fast-xml-parser": "^3.19.0", + "fast-xml-parser": "^4.2.4", "he": "^1.2.0", - "hot-patcher": "^1.0.0", + "hot-patcher": "^2.0.0", "layerr": "^0.1.2", "md5": "^2.3.0", "minimatch": "^5.1.0", @@ -21187,7 +21270,7 @@ "url-parse": "^1.5.10" }, "engines": { - "node": ">=10" + "node": ">=14" } }, "node_modules/webdav/node_modules/brace-expansion": { @@ -23607,6 +23690,14 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "@buttercup/fetch": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@buttercup/fetch/-/fetch-0.1.1.tgz", + "integrity": "sha512-RwBiPEmPaZv3oLOPY0fcmAGYdd3A4FDoYDc7JN+qxGTXumrYAYEC1RpyCM2pHSr6RYpuaAeg4A1fJy+PiigPIA==", + "requires": { + "node-fetch": "^3.3.0" + } + }, "@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -28480,6 +28571,12 @@ "assert-plus": "^1.0.0" } }, + "data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "optional": true + }, "data-urls": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-3.0.2.tgz", @@ -30129,11 +30226,11 @@ "dev": true }, "fast-xml-parser": { - "version": "3.21.1", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.21.1.tgz", - "integrity": "sha512-FTFVjYoBOZTJekiUsawGsSYV9QL0A+zDYCRj7y34IO6Jg+2IMYEtQa+bbictpdpV8dHxXywqU7C0gRDEOFtBFg==", + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.2.5.tgz", + "integrity": "sha512-B9/wizE4WngqQftFPmdaMYlXoJlJOYxGQOanC77fq9k8+Z0v5dDSVh+3glErdIROP//s/jgb7ZuxKfB8nVyo0g==", "requires": { - "strnum": "^1.0.4" + "strnum": "^1.0.5" } }, "fastest-levenshtein": { @@ -30181,6 +30278,16 @@ "pend": "~1.2.0" } }, + "fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "optional": true, + "requires": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + } + }, "figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -30345,6 +30452,15 @@ "mime-types": "^2.1.12" } }, + "formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "optional": true, + "requires": { + "fetch-blob": "^3.1.2" + } + }, "forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -30774,9 +30890,9 @@ "peer": true }, "hot-patcher": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/hot-patcher/-/hot-patcher-1.0.0.tgz", - "integrity": "sha512-3H8VH0PreeNsKMZw16nTHbUp4YoHCnPlawpsPXGJUR4qENDynl79b6Xk9CIFvLcH1qungBsCuzKcWyzoPPalTw==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/hot-patcher/-/hot-patcher-2.0.0.tgz", + "integrity": "sha512-rwJ0ZqSFgm+5oD0KiGBVinyPWRJESRSsHlEWDzZjyOe/OfhD9tynHqUyUIGX2fWuV+BihW4nXxeoZRJVHid64w==" }, "hpack.js": { "version": "2.1.6", @@ -31395,16 +31511,6 @@ "integrity": "sha512-v+AgVwiK5DsGtT9ng+m4mClp6zDAmwrW8nZi6Gg15qzvBnRWWdfWA1TGaXyCDnWq5g5asofIgMVl3PjKxvk1ug==", "requires": { "fast-xml-parser": "^4.1.3" - }, - "dependencies": { - "fast-xml-parser": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.2.5.tgz", - "integrity": "sha512-B9/wizE4WngqQftFPmdaMYlXoJlJOYxGQOanC77fq9k8+Z0v5dDSVh+3glErdIROP//s/jgb7ZuxKfB8nVyo0g==", - "requires": { - "strnum": "^1.0.5" - } - } } }, "is-symbol": { @@ -34176,6 +34282,23 @@ "resolved": "https://registry.npmjs.org/nested-property/-/nested-property-4.0.0.tgz", "integrity": "sha512-yFehXNWRs4cM0+dz7QxCd06hTbWbSkV0ISsqBfkntU6TOY4Qm3Q88fRRLOddkGh2Qq6dZvnKVAahfhjcUvLnyA==" }, + "node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "optional": true + }, + "node-fetch": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz", + "integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==", + "optional": true, + "requires": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + } + }, "node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -38019,17 +38142,23 @@ "resolved": "https://registry.npmjs.org/web-namespaces/-/web-namespaces-2.0.1.tgz", "integrity": "sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==" }, + "web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "optional": true + }, "webdav": { - "version": "4.11.2", - "resolved": "https://registry.npmjs.org/webdav/-/webdav-4.11.2.tgz", - "integrity": "sha512-Ht9TPD5EB7gYW0YmhRcE5NW0/dn/HQfyLSPQY1Rw1coQ5MQTUooAQ9Bpqt4EU7QLw0b95tX4cU59R+SIojs9KQ==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/webdav/-/webdav-5.2.2.tgz", + "integrity": "sha512-CTnhTTKug7pKbMqcvrnGNr4rV9qhWXV1sLk1PpN4BOskqDT+cEfFx4Y4VlcFXUX6lSUFsQBm9Ka8+6dIe0doQQ==", "requires": { - "axios": "^0.27.2", + "@buttercup/fetch": "^0.1.1", "base-64": "^1.0.0", "byte-length": "^1.0.2", - "fast-xml-parser": "^3.19.0", + "fast-xml-parser": "^4.2.4", "he": "^1.2.0", - "hot-patcher": "^1.0.0", + "hot-patcher": "^2.0.0", "layerr": "^0.1.2", "md5": "^2.3.0", "minimatch": "^5.1.0", diff --git a/package.json b/package.json index 50bf354d1..2a35f93bb 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "vue-virtual-grid": "^2.5.0", "vuex": "^3.6.2", "vuex-router-sync": "^5.0.0", - "webdav": "^4.11.0" + "webdav": "^5.2.2" }, "browserslist": [ "extends @nextcloud/browserslist-config" diff --git a/src/mixins/FetchFacesMixin.js b/src/mixins/FetchFacesMixin.js index 0cff8cbf5..4e0a88445 100644 --- a/src/mixins/FetchFacesMixin.js +++ b/src/mixins/FetchFacesMixin.js @@ -25,13 +25,15 @@ import { mapActions, mapGetters } from 'vuex' import { showError } from '@nextcloud/dialogs' import { getCurrentUser } from '@nextcloud/auth' -import client from '../services/DavClient.js' +import { getClient } from '../services/DavClient.js' import logger from '../services/logger.js' import DavRequest from '../services/DavRequest.js' import { genFileInfo } from '../utils/fileUtils.js' import AbortControllerMixin from './AbortControllerMixin.js' import he from 'he' +const client = getClient() + export default { name: 'FetchFacesMixin', diff --git a/src/patchedRequest.js b/src/patchedRequest.js deleted file mode 100644 index 57244c36d..000000000 --- a/src/patchedRequest.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @copyright Copyright (c) 2019 John Molakvoæ - * - * @author John Molakvoæ - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -const request = require('webdav/dist/node/request') - -const oldPrepareRequestOptions = request.prepareRequestOptions - -// While we wait for official cancellable webdav requests -// https://github.com/perry-mitchell/webdav-client/issues/179 -// let's properly forward our axios options through webdav to axios -request.prepareRequestOptions = function(requestOptions, context, methodOptions) { - // add our cancelToken support - if (methodOptions.cancelToken && typeof methodOptions.cancelToken === 'object') { - requestOptions.cancelToken = methodOptions.cancelToken - } - - // exploit old method - const finalOptions = oldPrepareRequestOptions(requestOptions, context, methodOptions) - - // allow us to override the request method - if (methodOptions.method && typeof methodOptions.method === 'string') { - finalOptions.method = methodOptions.method - } - - return finalOptions -} - -module.exports = request diff --git a/src/services/Albums.js b/src/services/Albums.js index 6dd3f1a9f..107326889 100644 --- a/src/services/Albums.js +++ b/src/services/Albums.js @@ -23,10 +23,10 @@ import moment from '@nextcloud/moment' import { translate } from '@nextcloud/l10n' -import defaultClient from '../services/DavClient.js' -import logger from '../services/logger.js' -import DavRequest from '../services/DavRequest.js' import { genFileInfo } from '../utils/fileUtils.js' +import { getClient } from '../services/DavClient.js' +import DavRequest from '../services/DavRequest.js' +import logger from '../services/logger.js' /** * @typedef {object} Album @@ -68,7 +68,7 @@ function getDavRequest(extraProps = '') { * @param {import('webdav').WebDAVClient} client - The DAV client to use. * @return {Promise} */ -export async function fetchAlbum(path, options, extraProps = '', client = defaultClient) { +export async function fetchAlbum(path, options, extraProps = '', client = getClient()) { try { const response = await client.stat(path, { data: getDavRequest(extraProps), diff --git a/src/services/DavClient.js b/src/services/DavClient.js index c21ddfbe6..04586ebf1 100644 --- a/src/services/DavClient.js +++ b/src/services/DavClient.js @@ -19,23 +19,38 @@ * along with this program. If not, see . * */ - import { createClient, getPatcher } from 'webdav' -import axios from '@nextcloud/axios' -import parseUrl from 'url-parse' import { generateRemoteUrl } from '@nextcloud/router' -import { getCurrentUser } from '@nextcloud/auth' +import { getCurrentUser, getRequestToken } from '@nextcloud/auth' +import { request } from 'webdav/dist/node/request.js' export const rootPath = 'dav' export const prefixPath = `/files/${getCurrentUser()?.uid}` -// force our axios -const patcher = getPatcher() -patcher.patch('request', axios) - // init webdav client on default dav endpoint -const remote = generateRemoteUrl(rootPath) -const client = createClient(remote) +const defaultRootUrl = generateRemoteUrl(rootPath) + +export const getClient = (rootUrl = defaultRootUrl) => { + const client = createClient(rootUrl, { + headers: { + requesttoken: getRequestToken() || '', + }, + }) + + /** + * Allow to override the METHOD to support dav REPORT + * + * @see https://github.com/perry-mitchell/webdav-client/blob/8d9694613c978ce7404e26a401c39a41f125f87f/source/request.ts + */ + const patcher = getPatcher() -export const remotePath = parseUrl(remote).pathname -export default client + // https://github.com/perry-mitchell/hot-patcher/issues/6 + patcher.patch('request', (options) => { + if (options.headers?.method) { + options.method = options.headers.method + delete options.headers.method + } + return request(options) + }) + return client +} diff --git a/src/services/FileInfo.js b/src/services/FileInfo.js index 069590388..17aac50f3 100644 --- a/src/services/FileInfo.js +++ b/src/services/FileInfo.js @@ -20,7 +20,7 @@ * */ -import client, { prefixPath } from './DavClient.js' +import { getClient, prefixPath } from './DavClient.js' import request from './DavRequest.js' import { genFileInfo } from '../utils/fileUtils.js' @@ -35,7 +35,7 @@ export default async function(path) { const fixedPath = path === '/' ? '' : path // fetch listing - const response = await client.stat(prefixPath + fixedPath, { + const response = await getClient().stat(prefixPath + fixedPath, { data: request, details: true, }) diff --git a/src/services/FolderInfo.js b/src/services/FolderInfo.js index 9cf94c76a..616ca8e01 100644 --- a/src/services/FolderInfo.js +++ b/src/services/FolderInfo.js @@ -20,7 +20,7 @@ * */ -import client, { prefixPath } from './DavClient.js' +import { getClient, prefixPath } from './DavClient.js' import request from './DavRequest.js' import { genFileInfo } from '../utils/fileUtils.js' @@ -35,7 +35,7 @@ export default async function(path) { const fixedPath = path === '/' ? '' : path // fetch listing - const response = await client.stat(prefixPath + fixedPath, { + const response = await getClient().stat(prefixPath + fixedPath, { data: request, details: true, }) diff --git a/src/services/PhotoSearch.js b/src/services/PhotoSearch.js index 62e997f4a..7ea8cb070 100644 --- a/src/services/PhotoSearch.js +++ b/src/services/PhotoSearch.js @@ -23,7 +23,7 @@ import { genFileInfo } from '../utils/fileUtils.js' import { getCurrentUser } from '@nextcloud/auth' import { allMimes } from './AllowedMimes.js' -import client from './DavClient.js' +import { getClient } from './DavClient.js' import { props } from './DavRequest.js' import moment from '@nextcloud/moment' @@ -96,9 +96,9 @@ export default async function(path = '', options = {}) { : '' options = Object.assign({ - method: 'SEARCH', headers: { 'content-Type': 'text/xml', + method: 'SEARCH', }, data: ` genFileInfo(data)) } diff --git a/src/services/SystemTags.js b/src/services/SystemTags.js index 891d98fc1..26e9ef581 100644 --- a/src/services/SystemTags.js +++ b/src/services/SystemTags.js @@ -20,7 +20,7 @@ * */ -import client from './DavClient.js' +import { getClient } from './DavClient.js' import { genFileInfo } from '../utils/fileUtils.js' /** @@ -31,7 +31,7 @@ import { genFileInfo } from '../utils/fileUtils.js' * @return {Promise} the file list */ export default async function(path, options = {}) { - const response = await client.getDirectoryContents('/systemtags-assigned/image', Object.assign({}, { + const response = await getClient().getDirectoryContents('/systemtags-assigned/image', Object.assign({}, { data: ` diff --git a/src/services/TaggedImages.js b/src/services/TaggedImages.js index a0611e4f4..4e2bbf48a 100644 --- a/src/services/TaggedImages.js +++ b/src/services/TaggedImages.js @@ -21,9 +21,9 @@ */ import { genFileInfo } from '../utils/fileUtils.js' +import { getClient, prefixPath } from './DavClient.js' import { props } from './DavRequest.js' import allowedMimes from './AllowedMimes.js' -import client, { prefixPath } from './DavClient.js' /** * Get tagged files based on provided tag id @@ -35,7 +35,9 @@ import client, { prefixPath } from './DavClient.js' export default async function(id, options = {}) { options = Object.assign({ - method: 'REPORT', + headers: { + method: 'REPORT', + }, data: ` genFileInfo(data)) diff --git a/src/services/collectionFetcher.js b/src/services/collectionFetcher.js index f1e264251..9b991ab09 100644 --- a/src/services/collectionFetcher.js +++ b/src/services/collectionFetcher.js @@ -23,7 +23,7 @@ import moment from '@nextcloud/moment' import { translate } from '@nextcloud/l10n' -import defaultClient from './DavClient.js' +import { getClient } from './DavClient.js' import logger from './logger.js' import { genFileInfo } from '../utils/fileUtils.js' @@ -101,7 +101,7 @@ function getCollectionFilesDavRequest(extraProps = []) { * @param {import('webdav').WebDAVClient} client - The DAV client to use. * @return {Promise} */ -export async function fetchCollection(path, options, extraProps = [], client = defaultClient) { +export async function fetchCollection(path, options, extraProps = [], client = getClient()) { try { const response = await client.stat(path, { data: getCollectionDavRequest(extraProps), diff --git a/src/services/fileFetcher.js b/src/services/fileFetcher.js index a5fcca8b7..5fc9da885 100644 --- a/src/services/fileFetcher.js +++ b/src/services/fileFetcher.js @@ -21,7 +21,7 @@ */ import { genFileInfo } from '../utils/fileUtils.js' -import defaultClient from './DavClient.js' +import { getClient } from './DavClient.js' /** * @param {string[]} extraProps - Extra properties to add to the DAV request. @@ -56,7 +56,7 @@ function getCollectionFilesDavRequest(extraProps = []) { */ export async function fetchFile(fileName, options = {}) { try { - const response = await defaultClient.stat(fileName, { + const response = await getClient().stat(fileName, { data: getCollectionFilesDavRequest(), details: true, ...options, diff --git a/src/store/collections.js b/src/store/collections.js index 9d242db7c..590cc9417 100644 --- a/src/store/collections.js +++ b/src/store/collections.js @@ -23,10 +23,12 @@ import { showError } from '@nextcloud/dialogs' import { translate } from '@nextcloud/l10n' -import client from '../services/DavClient.js' +import { getClient } from '../services/DavClient.js' import logger from '../services/logger.js' import Semaphore from '../utils/semaphoreWithPriority.js' +const client = getClient() + /** * Collections are indexed by their `filename`. */ @@ -324,7 +326,9 @@ const actions = { await client.customRequest( collection.filename, { - method: 'PROPPATCH', + headers: { + method: 'PROPPATCH', + }, data: ` -1) { - console.debug('Patched request for webdav', basename(resource.contextInfo.issuer)) - resource.request = path.join(__dirname, 'src/patchedRequest.js') - } - }, - ), new WorkboxPlugin.GenerateSW({ swDest: 'photos-service-worker.js', clientsClaim: true,