Skip to content

Commit a66cae0

Browse files
committed
fix(deps): update webdav 5 usage
Signed-off-by: John Molakvoæ <[email protected]>
1 parent c7c9ee1 commit a66cae0

File tree

10 files changed

+71
-89
lines changed

10 files changed

+71
-89
lines changed

apps/comments/src/services/DavClient.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@
2020
*
2121
*/
2222

23-
import { createClient, getPatcher } from 'webdav'
24-
import axios from '@nextcloud/axios'
25-
23+
import { createClient } from 'webdav'
2624
import { getRootPath } from '../utils/davUtils.js'
27-
28-
// Add this so the server knows it is an request from the browser
29-
axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
30-
31-
// force our axios
32-
const patcher = getPatcher()
33-
patcher.patch('request', axios)
25+
import { getRequestToken } from '@nextcloud/auth'
3426

3527
// init webdav client
36-
const client = createClient(getRootPath())
28+
const client = createClient(getRootPath(), {
29+
headers: {
30+
// Add this so the server knows it is an request from the browser
31+
'X-Requested-With': 'XMLHttpRequest',
32+
// Inject user auth
33+
requesttoken: getRequestToken() ?? '',
34+
},
35+
})
3736

3837
export default client
Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,29 @@
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'
2628
import client from './DavClient.js'
2729

2830
export 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
}

apps/comments/src/utils/cancelableRequest.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,15 @@
2020
*
2121
*/
2222

23-
import axios from '@nextcloud/axios'
24-
25-
/**
26-
* Create a cancel token
27-
*
28-
* @return {import('axios').CancelTokenSource}
29-
*/
30-
const createCancelToken = () => axios.CancelToken.source()
31-
3223
/**
3324
* Creates a cancelable axios 'request object'.
3425
*
3526
* @param {Function} request the axios promise request
3627
* @return {object}
3728
*/
3829
const cancelableRequest = function(request) {
39-
/**
40-
* Generate an axios cancel token
41-
*/
42-
const cancelToken = createCancelToken()
30+
const controller = new AbortController()
31+
const signal = controller.signal
4332

4433
/**
4534
* Execute the request
@@ -48,15 +37,16 @@ const cancelableRequest = function(request) {
4837
* @param {object} [options] optional config for the request
4938
*/
5039
const fetch = async function(url, options) {
51-
return request(
40+
const response = await request(
5241
url,
53-
Object.assign({ cancelToken: cancelToken.token }, options)
42+
Object.assign({ signal }, options)
5443
)
44+
return response
5545
}
5646

5747
return {
5848
request: fetch,
59-
cancel: cancelToken.cancel,
49+
abort: () => controller.abort(),
6050
}
6151
}
6252

apps/comments/src/views/Comments.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ import MessageReplyTextIcon from 'vue-material-design-icons/MessageReplyText.vue
9494
import AlertCircleOutlineIcon from 'vue-material-design-icons/AlertCircleOutline.vue'
9595
9696
import Comment from '../components/Comment.vue'
97-
import getComments, { DEFAULT_LIMIT } from '../services/GetComments.js'
97+
import { getComments, DEFAULT_LIMIT } from '../services/GetComments.ts'
9898
import cancelableRequest from '../utils/cancelableRequest.js'
9999
100100
Vue.use(VTooltip)
@@ -206,14 +206,14 @@ export default {
206206
this.error = ''
207207
208208
// Init cancellable request
209-
const { request, cancel } = cancelableRequest(getComments)
210-
this.cancelRequest = cancel
209+
const { request, abort } = cancelableRequest(getComments)
210+
this.cancelRequest = abort
211211
212212
// Fetch comments
213-
const comments = await request({
213+
const { data: comments } = await request({
214214
commentsType: this.commentsType,
215215
ressourceId: this.ressourceId,
216-
}, { offset: this.offset })
216+
}, { offset: this.offset }) || { data: [] }
217217
218218
this.logger.debug(`Processed ${comments.length} comments`, { comments })
219219

apps/dav/src/service/CalendarService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
import { getClient } from '../dav/client.js'
2222
import logger from './logger.js'
23-
import { parseXML } from 'webdav/dist/node/tools/dav.js'
23+
import { parseXML } from 'webdav'
2424

2525
import {
2626
slotsToVavailability,

apps/files_versions/src/utils/davClient.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22-
import { createClient, getPatcher } from 'webdav'
22+
import { createClient } from 'webdav'
2323
import { generateRemoteUrl } from '@nextcloud/router'
24-
import axios from '@nextcloud/axios'
24+
import { getRequestToken } from '@nextcloud/auth'
2525

2626
const rootPath = 'dav'
2727

28-
// force our axios
29-
const patcher = getPatcher()
30-
patcher.patch('request', axios)
31-
3228
// init webdav client on default dav endpoint
3329
const remote = generateRemoteUrl(rootPath)
34-
export default createClient(remote)
30+
export default createClient(remote, {
31+
headers: {
32+
// Add this so the server knows it is an request from the browser
33+
'X-Requested-With': 'XMLHttpRequest',
34+
// Inject user auth
35+
requesttoken: getRequestToken() ?? '',
36+
},
37+
})

apps/files_versions/src/views/VersionTab.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export default {
6868
6969
/**
7070
* Return the mtime of the first version to display "Initial version" label
71+
*
7172
* @return {number}
7273
*/
7374
initialVersionMtime() {

core/src/OC/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ import {
4444
import {
4545
build as buildQueryString,
4646
parse as parseQueryString,
47-
} from './query-string'
48-
import Config from './config'
47+
} from './query-string.js'
48+
import Config from './config.js'
4949
import {
5050
coreApps,
5151
menuSpeed,
@@ -57,30 +57,30 @@ import {
5757
PERMISSION_SHARE,
5858
PERMISSION_UPDATE,
5959
TAG_FAVORITE,
60-
} from './constants'
61-
import ContactsMenu from './contactsmenu'
62-
import { currentUser, getCurrentUser } from './currentuser'
63-
import Dialogs from './dialogs'
64-
import EventSource from './eventsource'
65-
import { get, set } from './get_set'
66-
import { getCapabilities } from './capabilities'
60+
} from './constants.js'
61+
import ContactsMenu from './contactsmenu.js'
62+
import { currentUser, getCurrentUser } from './currentuser.js'
63+
import Dialogs from './dialogs.js'
64+
import EventSource from './eventsource.js'
65+
import { get, set } from './get_set.js'
66+
import { getCapabilities } from './capabilities.js'
6767
import {
6868
getHost,
6969
getHostName,
7070
getPort,
7171
getProtocol,
72-
} from './host'
72+
} from './host.js'
7373
import {
7474
getToken as getRequestToken,
75-
} from './requesttoken'
75+
} from './requesttoken.js'
7676
import {
7777
hideMenus,
7878
registerMenu,
7979
showMenu,
8080
unregisterMenu,
81-
} from './menu'
82-
import { isUserAdmin } from './admin'
83-
import L10N from './l10n'
81+
} from './menu.js'
82+
import { isUserAdmin } from './admin.js'
83+
import L10N from './l10n.js'
8484
import {
8585
getCanonicalLocale,
8686
getLanguage,

core/src/OC/util-history.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ export default {
165165
},
166166

167167
_onPopState(e) {
168-
debugger
169-
170168
if (this._cancelPop) {
171169
this._cancelPop = false
172170
return

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"vuedraggable": "^2.24.3",
112112
"vuex": "^3.6.2",
113113
"vuex-router-sync": "^5.0.0",
114-
"webdav": "^5.0.0-r1"
114+
"webdav": "^5.0.0-r3"
115115
},
116116
"devDependencies": {
117117
"@babel/node": "^7.20.7",

0 commit comments

Comments
 (0)