2020 *
2121 */
2222
23- import { parseXML , prepareFileFromProps } from 'webdav/dist/node/tools/dav.js'
24- import { processResponsePayload } from 'webdav/dist/node/response.js'
25- import { decodeHtmlEntities } from '../utils/decodeHtmlEntities.js'
23+ import { parseXML , type DAVResult , type FileStat } from 'webdav'
24+
25+ // https://github.com/perry-mitchell/webdav-client/issues/339
26+ import { processResponsePayload } from '../../../../node_modules/webdav/dist/node/response.js'
27+ import { prepareFileFromProps } from '../../../../node_modules/webdav/dist/node/tools/dav.js'
2628import client from './DavClient.js'
2729
2830export const DEFAULT_LIMIT = 20
31+
2932/**
3033 * Retrieve the comments list
3134 *
3235 * @param {object } data destructuring object
3336 * @param {string } data.commentsType the ressource type
3437 * @param {number } data.ressourceId the ressource ID
3538 * @param {object } [options] optional options for axios
39+ * @param {number } [options.offset] the pagination offset
3640 * @return {object[] } the comments list
3741 */
38- export default async function ( { commentsType, ressourceId } , options = { } ) {
39- let response = null
42+ export const getComments = async function ( { commentsType, ressourceId } , options : { offset : number } ) {
4043 const ressourcePath = [ '' , commentsType , ressourceId ] . join ( '/' )
4144
42- return await client . customRequest ( ressourcePath , Object . assign ( {
45+ const response = await client . customRequest ( ressourcePath , Object . assign ( {
4346 method : 'REPORT' ,
4447 data : `<?xml version="1.0"?>
4548 <oc:filter-comments
@@ -51,42 +54,30 @@ export default async function({ commentsType, ressourceId }, options = {}) {
5154 <oc:offset>${ options . offset || 0 } </oc:offset>
5255 </oc:filter-comments>` ,
5356 } , options ) )
54- // See example on how it's done normally
55- // https://github.com/perry-mitchell/webdav-client/blob/9de2da4a2599e06bd86c2778145b7ade39fe0b3c/source/interface/stat.js#L19
56- // Waiting for proper REPORT integration https://github.com/perry-mitchell/webdav-client/issues/207
57- . then ( res => {
58- response = res
59- return res . data
60- } )
61- . then ( parseXML )
62- . then ( xml => processMultistatus ( xml , true ) )
63- . then ( comments => processResponsePayload ( response , comments , true ) )
64- . then ( response => response . data )
57+
58+ const responseData = await response . text ( )
59+ const result = await parseXML ( responseData )
60+ const stat = getDirectoryFiles ( result , true )
61+ return processResponsePayload ( response , stat , true )
6562}
6663
67- // https://github.com/perry-mitchell/webdav-client/blob/9de2da4a2599e06bd86c2778145b7ade39fe0b3c/source/interface/directoryContents.js#L32
68- /**
69- * @param {any } result -
70- * @param {any } isDetailed -
71- */
72- function processMultistatus ( result , isDetailed = false ) {
64+ // https://github.com/perry-mitchell/webdav-client/blob/8d9694613c978ce7404e26a401c39a41f125f87f/source/operations/directoryContents.ts
65+ const getDirectoryFiles = function (
66+ result : DAVResult ,
67+ isDetailed = false ,
68+ ) : Array < FileStat > {
7369 // Extract the response items (directory contents)
7470 const {
7571 multistatus : { response : responseItems } ,
7672 } = result
73+
74+ // Map all items to a consistent output structure (results)
7775 return responseItems . map ( item => {
7876 // Each item should contain a stat object
7977 const {
8078 propstat : { prop : props } ,
8179 } = item
82- // Decode HTML entities
83- const decodedProps = {
84- ...props ,
85- // Decode twice to handle potentially double-encoded entities
86- // FIXME Remove this once https://github.com/nextcloud/server/issues/29306 is resolved
87- actorDisplayName : decodeHtmlEntities ( props . actorDisplayName , 2 ) ,
88- message : decodeHtmlEntities ( props . message , 2 ) ,
89- }
90- return prepareFileFromProps ( decodedProps , decodedProps . id . toString ( ) , isDetailed )
80+
81+ return prepareFileFromProps ( props , props . id . toString ( ) , isDetailed )
9182 } )
9283}
0 commit comments