@@ -8,59 +8,45 @@ import type { FileStat, ResponseDataDetailed, SearchResult, WebDAVClient } from
88
99import { defaultRootPath , getDefaultPropfind , getRecentSearch , resultToNode } from '@nextcloud/files/dav'
1010import { join } from '@nextcloud/paths'
11- import { CancelablePromise } from 'cancelable-promise'
1211
1312/**
1413 * Get the recently changed nodes from the last two weeks
1514 *
16- * @param client - The WebDAV client
15+ * @param context - The context
16+ * @param context.client - The WebDAV client
17+ * @param context.signal - The abort signal to cancel the request
1718 */
18- export function getRecentNodes ( client : WebDAVClient ) : CancelablePromise < Node [ ] > {
19- const controller = new AbortController ( )
19+ export async function getRecentNodes ( { client, signal } : { client : WebDAVClient , signal : AbortSignal } ) : Promise < Node [ ] > {
2020 // unix timestamp in seconds, two weeks ago
2121 const lastTwoWeek = Math . round ( Date . now ( ) / 1000 ) - ( 60 * 60 * 24 * 14 )
22- return new CancelablePromise ( async ( resolve , reject , onCancel ) => {
23- onCancel ( ( ) => controller . abort ( ) )
24- try {
25- const { data } = await client . search ( '/' , {
26- signal : controller . signal ,
27- details : true ,
28- data : getRecentSearch ( lastTwoWeek ) ,
29- } ) as ResponseDataDetailed < SearchResult >
30- const nodes = data . results . map ( ( result : FileStat ) => resultToNode ( result ) )
31- resolve ( nodes )
32- } catch ( error ) {
33- reject ( error )
34- }
35- } )
22+ const { data } = await client . search ( '/' , {
23+ signal,
24+ details : true ,
25+ data : getRecentSearch ( lastTwoWeek ) ,
26+ } ) as ResponseDataDetailed < SearchResult >
27+ return data . results . map ( ( result : FileStat ) => resultToNode ( result ) )
3628}
3729
3830/**
3931 * Get the directory content
4032 *
41- * @param client - The WebDAV client
42- * @param directoryPath - The path to fetch
33+ * @param context - The context
34+ * @param context.client - The WebDAV client
35+ * @param context.path - The path to fetch
36+ * @param context.signal - The abort signal to cancel the request
4337 */
44- export function getNodes ( client : WebDAVClient , directoryPath : string ) : CancelablePromise < ContentsWithRoot > {
45- const controller = new AbortController ( )
46- return new CancelablePromise ( async ( resolve , reject , onCancel ) => {
47- onCancel ( ( ) => controller . abort ( ) )
48- try {
49- const results = await client . getDirectoryContents ( join ( defaultRootPath , directoryPath ) , {
50- signal : controller . signal ,
51- details : true ,
52- includeSelf : true ,
53- data : getDefaultPropfind ( ) ,
54- } ) as ResponseDataDetailed < FileStat [ ] >
55- const nodes = results . data . map ( ( result : FileStat ) => resultToNode ( result ) )
56- resolve ( {
57- contents : nodes . filter ( ( { path } ) => path !== directoryPath ) ,
58- folder : nodes . find ( ( { path } ) => path === directoryPath ) as Folder ,
59- } )
60- } catch ( error ) {
61- reject ( error )
62- }
63- } )
38+ export async function getNodes ( { client, path, signal } : { client : WebDAVClient , path : string , signal : AbortSignal } ) : Promise < ContentsWithRoot > {
39+ const results = await client . getDirectoryContents ( join ( defaultRootPath , path ) , {
40+ signal,
41+ details : true ,
42+ includeSelf : true ,
43+ data : getDefaultPropfind ( ) ,
44+ } ) as ResponseDataDetailed < FileStat [ ] >
45+ const nodes = results . data . map ( ( result : FileStat ) => resultToNode ( result ) )
46+ return {
47+ contents : nodes . filter ( ( { path : nodePath } ) => nodePath !== path ) ,
48+ folder : nodes . find ( ( { path : nodePath } ) => path === nodePath ) as Folder ,
49+ }
6450}
6551
6652/**
0 commit comments