Skip to content

Commit 9f3947e

Browse files
feat(recent-search): add parameter to allow dynamic limit of returned items
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
1 parent 749e6c4 commit 9f3947e

1 file changed

Lines changed: 3 additions & 31 deletions

File tree

lib/dav/davProperties.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import { getCurrentUser } from '@nextcloud/auth'
7-
import { getCapabilities } from '@nextcloud/capabilities'
87
import { scopedGlobals } from '../globalScope.ts'
98
import logger from '../utils/logger.ts'
109

@@ -123,6 +122,7 @@ export function getFavoritesReport(): string {
123122
* Get the SEARCH body to search for recently modified/uploaded files
124123
*
125124
* @param timestamp Oldest timestamp to include (Unix timestamp)
125+
* @param limit Maximum number of items to return
126126
* @example
127127
* ```ts
128128
* // SEARCH for recent files need a different DAV endpoint
@@ -140,10 +140,7 @@ export function getFavoritesReport(): string {
140140
* }) as ResponseDataDetailed<FileStat[]>
141141
* ```
142142
*/
143-
export function getRecentSearch(timestamp: number): string {
144-
const capabilities = getCapabilities() as { dav?: { search_supports_upload_time?: boolean } }
145-
const supportsUploadTime = capabilities.dav?.search_supports_upload_time
146-
143+
export function getRecentSearch(timestamp: number, limit: number = 100): string {
147144
return `<?xml version="1.0" encoding="UTF-8"?>
148145
<d:searchrequest ${getDavNameSpaces()}
149146
xmlns:ns="https://github.com/icewind1991/SearchDAV/ns">
@@ -177,31 +174,6 @@ export function getRecentSearch(timestamp: number): string {
177174
<d:literal>0</d:literal>
178175
</d:eq>
179176
</d:or>
180-
${supportsUploadTime
181-
? `
182-
<d:or>
183-
<d:gt>
184-
<d:prop>
185-
<d:getlastmodified/>
186-
</d:prop>
187-
<d:literal>${timestamp}</d:literal>
188-
</d:gt>
189-
<d:gt>
190-
<d:prop>
191-
<nc:upload_time/>
192-
</d:prop>
193-
<d:literal>${timestamp}</d:literal>
194-
</d:gt>
195-
</d:or>
196-
`
197-
: `
198-
<d:gt>
199-
<d:prop>
200-
<d:getlastmodified/>
201-
</d:prop>
202-
<d:literal>${timestamp}</d:literal>
203-
</d:gt>
204-
`}
205177
</d:and>
206178
</d:where>
207179
<d:orderby>
@@ -213,7 +185,7 @@ export function getRecentSearch(timestamp: number): string {
213185
</d:order>
214186
</d:orderby>
215187
<d:limit>
216-
<d:nresults>100</d:nresults>
188+
<d:nresults>${limit}</d:nresults>
217189
<ns:firstresult>0</ns:firstresult>
218190
</d:limit>
219191
</d:basicsearch>

0 commit comments

Comments
 (0)