*
*/
-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
+++ /dev/null
-/**
- * @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)
- })
-}
--- /dev/null
+/**
+ * @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)
+ })
+}
*
*/
-import axios from '@nextcloud/axios'
-
-/**
- * Create a cancel token
- *
- * @return {import('axios').CancelTokenSource}
- */
-const createCancelToken = () => axios.CancelToken.source()
-
/**
* Creates a cancelable axios 'request object'.
*
* @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
* @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(),
}
}
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)
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 })
*/
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,
* 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() ?? '',
+ },
+})
/**
* Return the mtime of the first version to display "Initial version" label
+ *
* @return {number}
*/
initialVersionMtime() {
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,
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,
},
_onPopState(e) {
- debugger
-
if (this._cancelPop) {
this._cancelPop = false
return
"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",