]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(deps): update webdav 5 usage
authorJohn Molakvoæ <skjnldsv@protonmail.com>
Fri, 31 Mar 2023 12:56:11 +0000 (14:56 +0200)
committerJohn Molakvoæ <skjnldsv@protonmail.com>
Thu, 6 Apr 2023 12:49:32 +0000 (14:49 +0200)
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
apps/comments/src/services/DavClient.js
apps/comments/src/services/GetComments.js [deleted file]
apps/comments/src/services/GetComments.ts [new file with mode: 0644]
apps/comments/src/utils/cancelableRequest.js
apps/comments/src/views/Comments.vue
apps/dav/src/service/CalendarService.js
apps/files_versions/src/utils/davClient.js
apps/files_versions/src/views/VersionTab.vue
core/src/OC/index.js
core/src/OC/util-history.js
package.json

index 6837ce90c56c4e05d85713ed2f869e64e881f691..5c2fc96e4dbb8087589f24058e5fbc0cdf07908b 100644 (file)
  *
  */
 
-import { createClient, getPatcher } from 'webdav'
-import axios from '@nextcloud/axios'
-
+import { createClient } from 'webdav'
 import { getRootPath } from '../utils/davUtils.js'
-
-// Add this so the server knows it is an request from the browser
-axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
-
-// force our axios
-const patcher = getPatcher()
-patcher.patch('request', axios)
+import { getRequestToken } from '@nextcloud/auth'
 
 // init webdav client
-const client = createClient(getRootPath())
+const client = createClient(getRootPath(), {
+       headers: {
+               // Add this so the server knows it is an request from the browser
+               'X-Requested-With': 'XMLHttpRequest',
+               // Inject user auth
+               requesttoken: getRequestToken() ?? '',
+       },
+})
 
 export default client
diff --git a/apps/comments/src/services/GetComments.js b/apps/comments/src/services/GetComments.js
deleted file mode 100644 (file)
index 4bdab90..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @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 <http://www.gnu.org/licenses/>.
- *
- */
-
-import { parseXML, prepareFileFromProps } from 'webdav/dist/node/tools/dav.js'
-import { processResponsePayload } from 'webdav/dist/node/response.js'
-import { decodeHtmlEntities } from '../utils/decodeHtmlEntities.js'
-import client from './DavClient.js'
-
-export const DEFAULT_LIMIT = 20
-/**
- * Retrieve the comments list
- *
- * @param {object} data destructuring object
- * @param {string} data.commentsType the ressource type
- * @param {number} data.ressourceId the ressource ID
- * @param {object} [options] optional options for axios
- * @return {object[]} the comments list
- */
-export default async function({ commentsType, ressourceId }, options = {}) {
-       let response = null
-       const ressourcePath = ['', commentsType, ressourceId].join('/')
-
-       return await client.customRequest(ressourcePath, Object.assign({
-               method: 'REPORT',
-               data: `<?xml version="1.0"?>
-                       <oc:filter-comments
-                               xmlns:d="DAV:"
-                               xmlns:oc="http://owncloud.org/ns"
-                               xmlns:nc="http://nextcloud.org/ns"
-                               xmlns:ocs="http://open-collaboration-services.org/ns">
-                               <oc:limit>${DEFAULT_LIMIT}</oc:limit>
-                               <oc:offset>${options.offset || 0}</oc:offset>
-                       </oc:filter-comments>`,
-       }, options))
-               // See example on how it's done normally
-               // https://github.com/perry-mitchell/webdav-client/blob/9de2da4a2599e06bd86c2778145b7ade39fe0b3c/source/interface/stat.js#L19
-               // Waiting for proper REPORT integration https://github.com/perry-mitchell/webdav-client/issues/207
-               .then(res => {
-                       response = res
-                       return res.data
-               })
-               .then(parseXML)
-               .then(xml => processMultistatus(xml, true))
-               .then(comments => processResponsePayload(response, comments, true))
-               .then(response => response.data)
-}
-
-// https://github.com/perry-mitchell/webdav-client/blob/9de2da4a2599e06bd86c2778145b7ade39fe0b3c/source/interface/directoryContents.js#L32
-/**
- * @param {any} result -
- * @param {any} isDetailed -
- */
-function processMultistatus(result, isDetailed = false) {
-       // Extract the response items (directory contents)
-       const {
-               multistatus: { response: responseItems },
-       } = result
-       return responseItems.map(item => {
-               // Each item should contain a stat object
-               const {
-                       propstat: { prop: props },
-               } = item
-               // Decode HTML entities
-               const decodedProps = {
-                       ...props,
-                       // Decode twice to handle potentially double-encoded entities
-                       // FIXME Remove this once https://github.com/nextcloud/server/issues/29306 is resolved
-                       actorDisplayName: decodeHtmlEntities(props.actorDisplayName, 2),
-                       message: decodeHtmlEntities(props.message, 2),
-               }
-               return prepareFileFromProps(decodedProps, decodedProps.id.toString(), isDetailed)
-       })
-}
diff --git a/apps/comments/src/services/GetComments.ts b/apps/comments/src/services/GetComments.ts
new file mode 100644 (file)
index 0000000..d74e92b
--- /dev/null
@@ -0,0 +1,83 @@
+/**
+ * @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { parseXML, type DAVResult, type FileStat } from 'webdav'
+
+// https://github.com/perry-mitchell/webdav-client/issues/339
+import { processResponsePayload } from '../../../../node_modules/webdav/dist/node/response.js'
+import { prepareFileFromProps } from '../../../../node_modules/webdav/dist/node/tools/dav.js'
+import client from './DavClient.js'
+
+export const DEFAULT_LIMIT = 20
+
+/**
+ * Retrieve the comments list
+ *
+ * @param {object} data destructuring object
+ * @param {string} data.commentsType the ressource type
+ * @param {number} data.ressourceId the ressource ID
+ * @param {object} [options] optional options for axios
+ * @param {number} [options.offset] the pagination offset
+ * @return {object[]} the comments list
+ */
+export const getComments = async function({ commentsType, ressourceId }, options: { offset: number }) {
+       const ressourcePath = ['', commentsType, ressourceId].join('/')
+
+       const response = await client.customRequest(ressourcePath, Object.assign({
+               method: 'REPORT',
+               data: `<?xml version="1.0"?>
+                       <oc:filter-comments
+                               xmlns:d="DAV:"
+                               xmlns:oc="http://owncloud.org/ns"
+                               xmlns:nc="http://nextcloud.org/ns"
+                               xmlns:ocs="http://open-collaboration-services.org/ns">
+                               <oc:limit>${DEFAULT_LIMIT}</oc:limit>
+                               <oc:offset>${options.offset || 0}</oc:offset>
+                       </oc:filter-comments>`,
+       }, options))
+
+       const responseData = await response.text()
+       const result = await parseXML(responseData)
+       const stat = getDirectoryFiles(result, true)
+       return processResponsePayload(response, stat, true)
+}
+
+// https://github.com/perry-mitchell/webdav-client/blob/8d9694613c978ce7404e26a401c39a41f125f87f/source/operations/directoryContents.ts
+const getDirectoryFiles = function(
+       result: DAVResult,
+       isDetailed = false,
+): Array<FileStat> {
+       // Extract the response items (directory contents)
+       const {
+               multistatus: { response: responseItems },
+       } = result
+
+       // Map all items to a consistent output structure (results)
+       return responseItems.map(item => {
+               // Each item should contain a stat object
+               const {
+                       propstat: { prop: props },
+               } = item
+
+               return prepareFileFromProps(props, props.id.toString(), isDetailed)
+       })
+}
index cdb314419269120c00f16e0e3734b04e6240ed0e..1973de38903b419bf4fcb9271a6e7edfb87dea0e 100644 (file)
  *
  */
 
-import axios from '@nextcloud/axios'
-
-/**
- * Create a cancel token
- *
- * @return {import('axios').CancelTokenSource}
- */
-const createCancelToken = () => axios.CancelToken.source()
-
 /**
  * Creates a cancelable axios 'request object'.
  *
@@ -36,10 +27,8 @@ const createCancelToken = () => axios.CancelToken.source()
  * @return {object}
  */
 const cancelableRequest = function(request) {
-       /**
-        * Generate an axios cancel token
-        */
-       const cancelToken = createCancelToken()
+       const controller = new AbortController()
+       const signal = controller.signal
 
        /**
         * Execute the request
@@ -48,15 +37,16 @@ const cancelableRequest = function(request) {
         * @param {object} [options] optional config for the request
         */
        const fetch = async function(url, options) {
-               return request(
+               const response = await request(
                        url,
-                       Object.assign({ cancelToken: cancelToken.token }, options)
+                       Object.assign({ signal }, options)
                )
+               return response
        }
 
        return {
                request: fetch,
-               cancel: cancelToken.cancel,
+               abort: () => controller.abort(),
        }
 }
 
index b3b75a92dcacb107ad272e80755dbfd8cee4a7b1..55f735d566db91a128571102e65cef83f18b916d 100644 (file)
@@ -94,7 +94,7 @@ import MessageReplyTextIcon from 'vue-material-design-icons/MessageReplyText.vue
 import AlertCircleOutlineIcon from 'vue-material-design-icons/AlertCircleOutline.vue'
 
 import Comment from '../components/Comment.vue'
-import getComments, { DEFAULT_LIMIT } from '../services/GetComments.js'
+import { getComments, DEFAULT_LIMIT } from '../services/GetComments.ts'
 import cancelableRequest from '../utils/cancelableRequest.js'
 
 Vue.use(VTooltip)
@@ -206,14 +206,14 @@ export default {
                                this.error = ''
 
                                // Init cancellable request
-                               const { request, cancel } = cancelableRequest(getComments)
-                               this.cancelRequest = cancel
+                               const { request, abort } = cancelableRequest(getComments)
+                               this.cancelRequest = abort
 
                                // Fetch comments
-                               const comments = await request({
+                               const { data: comments } = await request({
                                        commentsType: this.commentsType,
                                        ressourceId: this.ressourceId,
-                               }, { offset: this.offset })
+                               }, { offset: this.offset }) || { data: [] }
 
                                this.logger.debug(`Processed ${comments.length} comments`, { comments })
 
index 9faad92f41843c6f4c6a2b6d60d59d68732380bb..46c92436d6b7214fd6ea8a5e8520216eae78bc4d 100644 (file)
@@ -20,7 +20,7 @@
  */
 import { getClient } from '../dav/client.js'
 import logger from './logger.js'
-import { parseXML } from 'webdav/dist/node/tools/dav.js'
+import { parseXML } from 'webdav'
 
 import {
        slotsToVavailability,
index e4bfeb10411df1f8aa03a973c9399fda2440b7af..022d34bbba4c96e95dc46f208b8c03bae5072075 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
-import { createClient, getPatcher } from 'webdav'
+import { createClient } from 'webdav'
 import { generateRemoteUrl } from '@nextcloud/router'
-import axios from '@nextcloud/axios'
+import { getRequestToken } from '@nextcloud/auth'
 
 const rootPath = 'dav'
 
-// force our axios
-const patcher = getPatcher()
-patcher.patch('request', axios)
-
 // init webdav client on default dav endpoint
 const remote = generateRemoteUrl(rootPath)
-export default createClient(remote)
+export default createClient(remote, {
+       headers: {
+               // Add this so the server knows it is an request from the browser
+               'X-Requested-With': 'XMLHttpRequest',
+               // Inject user auth
+               requesttoken: getRequestToken() ?? '',
+       },
+})
index f2e9576abd0a81a2af749ccc8e577d6aa64f8465..04b6ecf1addb6b68b254a2d19864b87e37fbc5bf 100644 (file)
@@ -68,6 +68,7 @@ export default {
 
                /**
                 * Return the mtime of the first version to display "Initial version" label
+                *
                 * @return {number}
                 */
                initialVersionMtime() {
index e8f4b199103cffcefba9d11a697f53aa64d96090..32c31c2c3a35bb5320c35ffafbdcd3f62aca90f7 100644 (file)
@@ -44,8 +44,8 @@ import {
 import {
        build as buildQueryString,
        parse as parseQueryString,
-} from './query-string'
-import Config from './config'
+} from './query-string.js'
+import Config from './config.js'
 import {
        coreApps,
        menuSpeed,
@@ -57,30 +57,30 @@ import {
        PERMISSION_SHARE,
        PERMISSION_UPDATE,
        TAG_FAVORITE,
-} from './constants'
-import ContactsMenu from './contactsmenu'
-import { currentUser, getCurrentUser } from './currentuser'
-import Dialogs from './dialogs'
-import EventSource from './eventsource'
-import { get, set } from './get_set'
-import { getCapabilities } from './capabilities'
+} from './constants.js'
+import ContactsMenu from './contactsmenu.js'
+import { currentUser, getCurrentUser } from './currentuser.js'
+import Dialogs from './dialogs.js'
+import EventSource from './eventsource.js'
+import { get, set } from './get_set.js'
+import { getCapabilities } from './capabilities.js'
 import {
        getHost,
        getHostName,
        getPort,
        getProtocol,
-} from './host'
+} from './host.js'
 import {
        getToken as getRequestToken,
-} from './requesttoken'
+} from './requesttoken.js'
 import {
        hideMenus,
        registerMenu,
        showMenu,
        unregisterMenu,
-} from './menu'
-import { isUserAdmin } from './admin'
-import L10N from './l10n'
+} from './menu.js'
+import { isUserAdmin } from './admin.js'
+import L10N from './l10n.js'
 import {
        getCanonicalLocale,
        getLanguage,
index e5f9ff9447b352e95d300f2a748f1f043cd4e042..d18b87439364945afe8d19e0e59d086eb4720277 100644 (file)
@@ -165,8 +165,6 @@ export default {
        },
 
        _onPopState(e) {
-               debugger
-
                if (this._cancelPop) {
                        this._cancelPop = false
                        return
index 8df2826e368389c35803df1e94383679a8389635..2c2bbf28eaa56341a009e85bdc44cc5b60c4a3d1 100644 (file)
     "vuedraggable": "^2.24.3",
     "vuex": "^3.6.2",
     "vuex-router-sync": "^5.0.0",
-    "webdav": "^5.0.0-r1"
+    "webdav": "^5.0.0-r3"
   },
   "devDependencies": {
     "@babel/node": "^7.20.7",