@@ -55,29 +55,17 @@ const querySchema = z.object({
5555 } ,
5656 example : 'character-sheets,splash-art' ,
5757 } ) ,
58- page : z
58+ offset : z
5959 . string ( )
6060 . optional ( )
6161 . openapi ( {
6262 param : {
63- description : 'Page number for pagination (starts at 1 ).' ,
63+ description : 'Number of results to skip for pagination (starts at 0 ).' ,
6464 in : 'query' ,
65- name : 'page ' ,
65+ name : 'offset ' ,
6666 required : false ,
6767 } ,
68- example : '1' ,
69- } ) ,
70- limit : z
71- . string ( )
72- . optional ( )
73- . openapi ( {
74- param : {
75- description : 'Number of results per page (max 50).' ,
76- in : 'query' ,
77- name : 'limit' ,
78- required : false ,
79- } ,
80- example : '20' ,
68+ example : '0' ,
8169 } ) ,
8270 sortBy : z
8371 . enum ( [ 'viewCount' , 'downloadCount' , 'uploadDate' , 'name' ] )
@@ -139,12 +127,8 @@ const responseSchema = z.object({
139127 } ) ,
140128 ) ,
141129 pagination : z . object ( {
142- page : z . number ( ) ,
143- limit : z . number ( ) ,
144- total : z . number ( ) ,
145- totalPages : z . number ( ) ,
130+ offset : z . number ( ) ,
146131 hasNext : z . boolean ( ) ,
147- hasPrev : z . boolean ( ) ,
148132 } ) ,
149133} )
150134
@@ -174,7 +158,7 @@ export const AssetSearchRoute = (handler: AppHandler) => {
174158 handler . use (
175159 '/search' ,
176160 cache ( {
177- cacheName : 'asset-search' ,
161+ cacheName : 'asset-search-all ' ,
178162 cacheControl : 'max-age=600, s-maxage=600' ,
179163 } ) ,
180164 )
@@ -184,17 +168,15 @@ export const AssetSearchRoute = (handler: AppHandler) => {
184168
185169 const { drizzle } = getConnection ( ctx . env )
186170
187- const page = query . page ? parseInt ( query . page ) : 1
188- const limit = query . limit ? Math . min ( parseInt ( query . limit ) , 50 ) : 20
189- const offset = ( page - 1 ) * limit
171+ const offset = query . offset ? parseInt ( query . offset ) : 0
190172 const sortBy = query . sortBy || 'uploadDate'
191173 const sortOrder = query . sortOrder || 'desc'
192174
193- if ( page < 1 ) {
175+ if ( offset < 0 ) {
194176 return ctx . json (
195177 {
196178 success : false ,
197- message : 'Page must be 1 or greater' ,
179+ message : 'Offset must be 0 or greater' ,
198180 } ,
199181 400 ,
200182 )
@@ -296,17 +278,12 @@ export const AssetSearchRoute = (handler: AppHandler) => {
296278 . where ( and ( conditions . length > 0 ? and ( ...conditions ) : undefined , eq ( asset . status , 'approved' ) ) )
297279 . orderBy ( sortDirection ( sortColumn ) )
298280
299- const countQuery = drizzle
300- . select ( { count : sql < number > `COUNT(*)` } )
301- . from ( asset )
302- . where ( and ( conditions . length > 0 ? and ( ...conditions ) : undefined , eq ( asset . status , 'approved' ) ) )
303-
304- const [ assets , countResult ] = await Promise . all ( [ baseQuery . limit ( limit ) . offset ( offset ) , countQuery ] )
281+ const assets = await baseQuery . limit ( 21 ) . offset ( offset )
305282
306- const total = countResult [ 0 ] ?. count || 0
307- const totalPages = Math . ceil ( total / limit )
283+ const hasNext = assets . length > 20
284+ const finalAssets = hasNext ? assets . slice ( 0 , 20 ) : assets
308285
309- const assetIds = assets . map ( a => a . id )
286+ const assetIds = finalAssets . map ( a => a . id )
310287 const assetTags =
311288 assetIds . length > 0
312289 ? await drizzle
@@ -337,7 +314,7 @@ export const AssetSearchRoute = (handler: AppHandler) => {
337314 { } as Record < string , any [ ] > ,
338315 )
339316
340- const uploaderIds = assets . map ( a => a . uploadedBy )
317+ const uploaderIds = finalAssets . map ( a => a . uploadedBy )
341318 const uploaders =
342319 uploaderIds . length > 0
343320 ? await drizzle
@@ -351,7 +328,7 @@ export const AssetSearchRoute = (handler: AppHandler) => {
351328 : [ ]
352329 const uploaderMap = Object . fromEntries ( uploaders . map ( u => [ u . id , u ] ) )
353330
354- const formattedAssets = assets . map ( asset => {
331+ const formattedAssets = finalAssets . map ( asset => {
355332 const gameInfo = gameMap [ asset . gameId ]
356333 const categoryInfo = categoryMap [ asset . categoryId ]
357334
@@ -372,12 +349,8 @@ export const AssetSearchRoute = (handler: AppHandler) => {
372349 success : true ,
373350 assets : formattedAssets ,
374351 pagination : {
375- page,
376- limit,
377- total,
378- totalPages,
379- hasNext : page < totalPages ,
380- hasPrev : page > 1 ,
352+ offset,
353+ hasNext,
381354 } ,
382355 } ,
383356 200 ,
0 commit comments