blob: ae6f1ee50e01df25f8d72dc8ea7adc991c7fc003 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { ContentsWithRoot } from '@nextcloud/files'
import { getCurrentUser } from '@nextcloud/auth'
import { Folder, Permission } from '@nextcloud/files'
import { defaultRemoteURL } from '@nextcloud/files/dav'
import { CancelablePromise } from 'cancelable-promise'
import { searchNodes } from './WebDavSearch.ts'
import logger from '../logger.ts'
import { useSearchStore } from '../store/search.ts'
import { getPinia } from '../store/index.ts'
/**
* Get the contents for a search view
*/
export function getContents(): CancelablePromise<ContentsWithRoot> {
const controller = new AbortController()
const searchStore = useSearchStore(getPinia())
const dir = searchStore.base?.path
return new CancelablePromise<ContentsWithRoot>(async (resolve, reject, cancel) => {
cancel(() => controller.abort())
try {
const contents = await searchNodes(searchStore.query, { dir, signal: controller.signal })
resolve({
contents,
folder: new Folder({
id: 0,
source: `${defaultRemoteURL}#search`,
owner: getCurrentUser()!.uid,
permissions: Permission.READ,
}),
})
} catch (error) {
logger.error('Failed to fetch search results', { error })
reject(error)
}
})
}
|