fix(api_service): adjust pagination to 1-based index for OpenWebUI compatibility

This commit is contained in:
cogwheel0
2025-08-28 09:30:57 +05:30
parent d8f2f1763d
commit 7c4fb892b9

View File

@@ -283,7 +283,10 @@ class ApiService {
if (limit == null) { if (limit == null) {
// Fetch all conversations using pagination // Fetch all conversations using pagination
int currentPage = 0; // OpenWebUI expects 1-based pagination for the `page` query param.
// Using 0 triggers server-side offset calculation like `offset = page*limit - limit`,
// which becomes negative for page=0 and causes a DB error.
int currentPage = 1;
while (true) { while (true) {
final response = await _dio.get( final response = await _dio.get(
@@ -322,7 +325,12 @@ class ApiService {
// Original single page fetch // Original single page fetch
final regularResponse = await _dio.get( final regularResponse = await _dio.get(
'/api/v1/chats/', '/api/v1/chats/',
queryParameters: {if (limit > 0) 'page': ((skip ?? 0) / limit).floor()}, // Convert skip/limit to 1-based page index expected by OpenWebUI.
// Example: skip=0 => page=1, skip=limit => page=2, etc.
queryParameters: {
if (limit > 0)
'page': (((skip ?? 0) / limit).floor() + 1).clamp(1, 1 << 30),
},
); );
if (regularResponse.data is! List) { if (regularResponse.data is! List) {