fix(deps): update webdav 5 usage

Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
pull/36534/head
John Molakvoæ 1 year ago
parent c7c9ee1ebd
commit a66cae02ef
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF

@ -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

@ -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)
})
}

@ -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(),
}
}

@ -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 })

@ -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,

@ -19,16 +19,19 @@
* 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() ?? '',
},
})

@ -68,6 +68,7 @@ export default {
/**
* Return the mtime of the first version to display "Initial version" label
*
* @return {number}
*/
initialVersionMtime() {

@ -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,

@ -165,8 +165,6 @@ export default {
},
_onPopState(e) {
debugger
if (this._cancelPop) {
this._cancelPop = false
return

@ -111,7 +111,7 @@
"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",

Loading…
Cancel
Save