diff options
author | Varun Patil <varunpatil@ucla.edu> | 2023-10-30 10:52:08 -0700 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2024-02-28 19:23:47 +0100 |
commit | b03fd6e363ef75ec69c5150b8992a838f724ce45 (patch) | |
tree | ebe8428c555863fbdcb3d477726995a661d66be8 /apps/comments | |
parent | dfd42307f04148f09a9f9811323178d4657fcc0a (diff) | |
download | nextcloud-server-b03fd6e363ef75ec69c5150b8992a838f724ce45.tar.gz nextcloud-server-b03fd6e363ef75ec69c5150b8992a838f724ce45.zip |
fix(dav): multiple fixes in usage of webdav library
1. Refresh token on update
2. Fix some very weird imports
3. Patch fetch instead of request to prevent accessing impl details
Signed-off-by: Varun Patil <varunpatil@ucla.edu>
Diffstat (limited to 'apps/comments')
-rw-r--r-- | apps/comments/src/services/DavClient.js | 25 | ||||
-rw-r--r-- | apps/comments/src/services/GetComments.ts | 10 |
2 files changed, 20 insertions, 15 deletions
diff --git a/apps/comments/src/services/DavClient.js b/apps/comments/src/services/DavClient.js index 5c2fc96e4db..78bc056357e 100644 --- a/apps/comments/src/services/DavClient.js +++ b/apps/comments/src/services/DavClient.js @@ -22,16 +22,23 @@ import { createClient } from 'webdav' import { getRootPath } from '../utils/davUtils.js' -import { getRequestToken } from '@nextcloud/auth' +import { getRequestToken, onRequestTokenUpdate } from '@nextcloud/auth' // init webdav client -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() ?? '', - }, -}) +const client = createClient(getRootPath()) + +// set CSRF token header +const setHeaders = (token) => { + client.setHeaders({ + // Add this so the server knows it is an request from the browser + 'X-Requested-With': 'XMLHttpRequest', + // Inject user auth + requesttoken: token ?? '', + }) +} + +// refresh headers when request token changes +onRequestTokenUpdate(setHeaders) +setHeaders(getRequestToken()) export default client diff --git a/apps/comments/src/services/GetComments.ts b/apps/comments/src/services/GetComments.ts index c55cb4ee4a0..0736632192d 100644 --- a/apps/comments/src/services/GetComments.ts +++ b/apps/comments/src/services/GetComments.ts @@ -23,8 +23,8 @@ import { parseXML, type DAVResult, type FileStat, type ResponseDataDetailed } 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 { processResponsePayload } from 'webdav/dist/node/response.js' +import { prepareFileFromProps } from 'webdav/dist/node/tools/dav.js' import client from './DavClient.js' export const DEFAULT_LIMIT = 20 @@ -77,10 +77,8 @@ const getDirectoryFiles = function( // 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 + const props = item.propstat!.prop!; - return prepareFileFromProps(props, props.id.toString(), isDetailed) + return prepareFileFromProps(props, props.id!.toString(), isDetailed) }) } |