From bd94ebe64b2923919c79f3359e02a02e01faeda5 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 12 Sep 2023 14:22:17 +0200 Subject: [PATCH] fix(FilePicker): Use `search` function from `webdav` package instead of workaround Signed-off-by: Ferdinand Thiessen --- lib/usables/dav.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/usables/dav.ts b/lib/usables/dav.ts index 0f8d0f55a..b1a365e13 100644 --- a/lib/usables/dav.ts +++ b/lib/usables/dav.ts @@ -21,7 +21,7 @@ */ import type { Node } from '@nextcloud/files' import type { ComputedRef, Ref } from 'vue' -import type { FileStat, ResponseDataDetailed, WebDAVClient } from 'webdav' +import type { FileStat, ResponseDataDetailed, SearchResult, WebDAVClient } from 'webdav' import { davGetClient, davGetDefaultPropfind, davGetRecentSearch, davResultToNode, davRootPath, getFavoriteNodes } from '@nextcloud/files' import { onMounted, ref, watch } from 'vue' @@ -32,7 +32,10 @@ import { onMounted, ref, watch } from 'vue' * @param currentView Reference to the current files view * @param currentPath Reference to the current files path */ -export const useDAVFiles = function(currentView: Ref<'files'|'recent'|'favorites'> | ComputedRef<'files'|'recent'|'favorites'>, currentPath: Ref | ComputedRef): { isLoading: Ref, client: WebDAVClient, files: Ref, loadFiles: () => void, getFile: (path: string) => Promise } { +export const useDAVFiles = function( + currentView: Ref<'files'|'recent'|'favorites'> | ComputedRef<'files'|'recent'|'favorites'>, + currentPath: Ref | ComputedRef, +): { isLoading: Ref, client: WebDAVClient, files: Ref, loadFiles: () => void, getFile: (path: string) => Promise } { /** * The WebDAV client */ @@ -72,17 +75,11 @@ export const useDAVFiles = function(currentView: Ref<'files'|'recent'|'favorites } else if (currentView.value === 'recent') { // unix timestamp in seconds, two weeks ago const lastTwoWeek = Math.round(Date.now() / 1000) - (60 * 60 * 24 * 14) - const results = await client.getDirectoryContents(currentPath.value, { + const { data } = await client.search('/', { details: true, data: davGetRecentSearch(lastTwoWeek), - headers: { - method: 'SEARCH', - 'Content-Type': 'application/xml; charset=utf-8', - }, - deep: true, - }) as ResponseDataDetailed - - files.value = results.data.map((r) => davResultToNode(r)) + }) as ResponseDataDetailed + files.value = data.results.map((r) => davResultToNode(r)) } else { const results = await client.getDirectoryContents(`${davRootPath}${currentPath.value}`, { details: true,