From 280089264cd27b6e6a2ff0ad4dfb41f442a67bd8 Mon Sep 17 00:00:00 2001 From: Favo Yang Date: Wed, 25 Oct 2023 01:50:14 +0800 Subject: [PATCH] fix: delegates to the searchV1 API to handle the query.size and query.from parameters --- src/v1-search.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/v1-search.ts b/src/v1-search.ts index 51c6208..816b146 100644 --- a/src/v1-search.ts +++ b/src/v1-search.ts @@ -51,6 +51,8 @@ export default function (route, auth: IBasicAuth, storag size = parseInt(size, 10) || 250; from = parseInt(from, 10) || 0; + query.size = size; + query.from = from; try { data = await search(storage, logger, { @@ -72,9 +74,19 @@ export default function (route, auth: IBasicAuth, storag // ); const checkAccessPromises: searchUtils.SearchItemPkg[] = data; - const final: searchUtils.SearchItemPkg[] = checkAccessPromises - .filter((i) => !_.isNull(i)) - .slice(from, size); + let final: searchUtils.SearchItemPkg[] = checkAccessPromises.filter((i) => !_.isNull(i)); + + // If the search is for searchV1, the search result has already been limited by the 'from' and 'size' parameters. + // Otherwise, we need to slice the result here. + let storagePlugin = (storage as any).localStorage.storagePlugin; + if (typeof storagePlugin.loadedBackends !== 'undefined') { + storagePlugin = storagePlugin.loadedBackends['redis-storage']; + logger.debug('VerdaccioStorageProxy found'); + } + if (typeof storagePlugin.searchV1 === 'undefined') { + final = final.slice(from, size); + } + logger.debug(`search results ${final?.length}`); const response: searchUtils.SearchResults = {