-
-
Notifications
You must be signed in to change notification settings - Fork 3
Release: Chat Drawer Pagination - 22.10.2025 #621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,22 @@ import { getChats } from '@utils/getChats' | |
|
|
||
| import type { Chat } from 'types' | ||
|
|
||
| const DEFAULT_PAGE_SIZE = 20 | ||
| const MAX_PAGE_SIZE = 100 | ||
|
|
||
| export async function GET(req: Request): Promise<NextResponse<Chat[]>> { | ||
| const session = await getCachedSession() | ||
|
|
||
| if (!session?.user?.email) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const mergedChats = await getChats(session.user) | ||
| const { searchParams } = new URL(req.url) | ||
| const requestedLimit = parseInt(searchParams.get('limit') || String(DEFAULT_PAGE_SIZE)) | ||
| const limit = Math.min(Math.max(1, requestedLimit), MAX_PAGE_SIZE) | ||
| const cursor = searchParams.get('cursor') || undefined | ||
|
Comment on lines
+18
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new GET handler clamps the Useful? React with 👍 / 👎. |
||
|
|
||
| const mergedChats = await getChats(session.user, { limit, cursor }) | ||
| return NextResponse.json(mergedChats) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,18 @@ import chatsService from '../../services/chats' | |
| import { InternalFlowiseError } from '../../errors/internalFlowiseError' | ||
| import { StatusCodes } from 'http-status-codes' | ||
|
|
||
| const DEFAULT_PAGE_SIZE = 20 | ||
| const MAX_PAGE_SIZE = 100 | ||
|
|
||
| const getAllChats = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| if (!req.user) { | ||
| throw new InternalFlowiseError(StatusCodes.UNAUTHORIZED, 'Error: chatsController.getAllChats - Unauthorized') | ||
| } | ||
| const apiResponse = await chatsService.getAllChats(req.user) | ||
| const requestedLimit = req.query.limit ? parseInt(req.query.limit as string, 10) : DEFAULT_PAGE_SIZE | ||
| const limit = Math.min(Math.max(1, requestedLimit), MAX_PAGE_SIZE) | ||
| const cursor = req.query.cursor as string | undefined | ||
| const apiResponse = await chatsService.getAllChats(req.user, { limit, cursor }) | ||
|
Comment on lines
+14
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The controller similarly parses Useful? React with 👍 / 👎.
Comment on lines
+14
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The controller similarly parses Useful? React with 👍 / 👎. |
||
| return res.json(apiResponse) | ||
| } catch (error) { | ||
| next(error) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limitwhen parsing chat list queryThe new GET handler clamps the
limitquery param usingMath.min(Math.max(1, requestedLimit), MAX_PAGE_SIZE), butrequestedLimitcan beNaNwhen a client calls/api/chats?limit=abcor/api/chats?limit=. BecauseMath.min/Math.maxpropagateNaN,limitends up asNaNand is forwarded togetChats, ultimately producing alimit=NaNremote request. The backend then attempts to useNaNfor the SQLtakeclause and returns a 500. To keep the “1‑100 items per page” validation promise, the handler should detectNumber.isNaN(requestedLimit)and either default toDEFAULT_PAGE_SIZEor return a 400 before calling the service.Useful? React with 👍 / 👎.