summaryrefslogtreecommitdiffstats
path: root/apps/comments
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2023-03-31 14:56:11 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-04-06 14:49:32 +0200
commita66cae02efcc27d962d867ba9a9e5da0441333e5 (patch)
tree1961e4bef2fe10626088bff18fe8460d146d18df /apps/comments
parentc7c9ee1ebdd07fdd5cf295835d5cf5e061fc40af (diff)
downloadnextcloud-server-a66cae02efcc27d962d867ba9a9e5da0441333e5.tar.gz
nextcloud-server-a66cae02efcc27d962d867ba9a9e5da0441333e5.zip
fix(deps): update webdav 5 usage
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/comments')
-rw-r--r--apps/comments/src/services/DavClient.js21
-rw-r--r--apps/comments/src/services/GetComments.ts (renamed from apps/comments/src/services/GetComments.js)55
-rw-r--r--apps/comments/src/utils/cancelableRequest.js22
-rw-r--r--apps/comments/src/views/Comments.vue10
4 files changed, 44 insertions, 64 deletions
diff --git a/apps/comments/src/services/DavClient.js b/apps/comments/src/services/DavClient.js
index 6837ce90c56..5c2fc96e4db 100644
--- a/apps/comments/src/services/DavClient.js
+++ b/apps/comments/src/services/DavClient.js
@@ -20,19 +20,18 @@
*
*/
-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.ts
index 4bdab9046a2..d74e92bce68 100644
--- a/apps/comments/src/services/GetComments.js
+++ b/apps/comments/src/services/GetComments.ts
@@ -20,12 +20,15 @@
*
*/
-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 { 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
*
@@ -33,13 +36,13 @@ export const DEFAULT_LIMIT = 20
* @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 default async function({ commentsType, ressourceId }, options = {}) {
- let response = null
+export const getComments = async function({ commentsType, ressourceId }, options: { offset: number }) {
const ressourcePath = ['', commentsType, ressourceId].join('/')
- return await client.customRequest(ressourcePath, Object.assign({
+ const response = await client.customRequest(ressourcePath, Object.assign({
method: 'REPORT',
data: `<?xml version="1.0"?>
<oc:filter-comments
@@ -51,42 +54,30 @@ export default async function({ commentsType, ressourceId }, options = {}) {
<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)
+
+ 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/9de2da4a2599e06bd86c2778145b7ade39fe0b3c/source/interface/directoryContents.js#L32
-/**
- * @param {any} result -
- * @param {any} isDetailed -
- */
-function processMultistatus(result, isDetailed = false) {
+// 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
- // 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)
+
+ return prepareFileFromProps(props, props.id.toString(), isDetailed)
})
}
diff --git a/apps/comments/src/utils/cancelableRequest.js b/apps/comments/src/utils/cancelableRequest.js
index cdb31441926..1973de38903 100644
--- a/apps/comments/src/utils/cancelableRequest.js
+++ b/apps/comments/src/utils/cancelableRequest.js
@@ -20,15 +20,6 @@
*
*/
-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(),
}
}
diff --git a/apps/comments/src/views/Comments.vue b/apps/comments/src/views/Comments.vue
index b3b75a92dca..55f735d566d 100644
--- a/apps/comments/src/views/Comments.vue
+++ b/apps/comments/src/views/Comments.vue
@@ -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 })