Skip to content

Commit

Permalink
add limit to asset query etc
Browse files Browse the repository at this point in the history
  • Loading branch information
dromzeh committed Apr 4, 2024
1 parent 5cdaa89 commit b3df3a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ app.use(
"*",
cors({
// todo(dromzeh): this should be set dependant on ENV, PROD or DEV w/ next() for context
origin: "*",
origin: "http://localhost:3000",
credentials: true,
})
)
Expand Down
2 changes: 2 additions & 0 deletions src/v2/routes/asset/get-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const responseSchema = z.object({
url: true,
viewCount: true,
downloadCount: true,
uploadedDate: true,
fileSize: true,
width: true,
height: true,
Expand Down Expand Up @@ -106,6 +107,7 @@ export const GetAssetByIdRoute = (handler: AppHandler) => {
url: true,
viewCount: true,
downloadCount: true,
uploadedDate: true,
fileSize: true,
width: true,
height: true,
Expand Down
19 changes: 15 additions & 4 deletions src/v2/routes/asset/search-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const responseSchema = z.object({
gameId: true,
viewCount: true,
downloadCount: true,
uploadedDate: true,
fileSize: true,
width: true,
height: true,
Expand Down Expand Up @@ -83,14 +84,22 @@ const querySchema = z
}),
offset: z.string().openapi({
param: {
description:
"The offset of the asset(s) to retrieve. For pagination / infinite scrolling.",
description: "The offset for the asset(s) to retrieve.",
name: "offset",
example: "0",
in: "query",
required: false,
},
}),
limit: z.string().openapi({
param: {
description: "The limit for the asset(s) to retrieve.",
name: "limit",
example: "25",
in: "query",
required: false,
},
}),
})
.partial()

Expand Down Expand Up @@ -122,7 +131,8 @@ export const AssetSearchAllFilterRoute = (handler: AppHandler) => {
handler.openapi(openRoute, async (ctx) => {
const { drizzle } = await getConnection(ctx.env)

const { name, game, category, tags, offset } = ctx.req.valid("query")
const { name, game, category, tags, offset, limit } =
ctx.req.valid("query")

const gameList = game ? SplitQueryByCommas(game.toLowerCase()) : null
const categoryList = category
Expand Down Expand Up @@ -158,7 +168,7 @@ export const AssetSearchAllFilterRoute = (handler: AppHandler) => {
: undefined,
eq(asset.status, "approved")
),
limit: 100,
limit: limit ? parseInt(limit) : 50,
offset: offset ? parseInt(offset) : 0,
columns: {
id: true,
Expand All @@ -169,6 +179,7 @@ export const AssetSearchAllFilterRoute = (handler: AppHandler) => {
gameId: true,
viewCount: true,
downloadCount: true,
uploadedDate: true,
fileSize: true,
width: true,
height: true,
Expand Down

0 comments on commit b3df3a0

Please sign in to comment.