From 8f4fa82a9e94aface2aba871b22bda5f056ea299 Mon Sep 17 00:00:00 2001 From: Hampus Date: Sun, 6 Sep 2026 17:38:21 +0200 Subject: [PATCH] fix(api): always return the page total when listing reports (#2534) --- fluxer_admin/openapi-admin.json | 27 ++++++------------- .../api/admin/services/AdminReportService.ts | 5 +++- fluxer_api/src/api/report/ReportService.ts | 13 ++++++--- .../schema/src/domains/admin/AdminSchemas.ts | 5 +--- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/fluxer_admin/openapi-admin.json b/fluxer_admin/openapi-admin.json index 5a0ee22fd..2ce8c78eb 100644 --- a/fluxer_admin/openapi-admin.json +++ b/fluxer_admin/openapi-admin.json @@ -12923,25 +12923,14 @@ ] }, "AdminReportListResponse": { - "oneOf": [ - { - "type": "object", - "properties": { - "reports": {"type": "array", "items": {"$ref": "#/components/schemas/ReportAdminResponseSchema"}}, - "total": {"type": "number"}, - "offset": {"type": "number"}, - "limit": {"type": "number"} - }, - "required": ["reports", "total", "offset", "limit"] - }, - { - "type": "object", - "properties": { - "reports": {"type": "array", "items": {"$ref": "#/components/schemas/ReportAdminResponseSchema"}} - }, - "required": ["reports"] - } - ] + "type": "object", + "properties": { + "reports": {"type": "array", "items": {"$ref": "#/components/schemas/ReportAdminResponseSchema"}}, + "total": {"type": "number"}, + "offset": {"type": "number"}, + "limit": {"type": "number"} + }, + "required": ["reports", "total", "offset", "limit"] }, "ReportAdminResponseSchema": { "type": "object", diff --git a/fluxer_api/src/api/admin/services/AdminReportService.ts b/fluxer_api/src/api/admin/services/AdminReportService.ts index 941b36230..181df1f03 100644 --- a/fluxer_api/src/api/admin/services/AdminReportService.ts +++ b/fluxer_api/src/api/admin/services/AdminReportService.ts @@ -74,7 +74,7 @@ export class AdminReportService { const {reportService} = this.deps; const requestedLimit = limit || 50; const currentOffset = offset || 0; - const reports = await reportService.listReportsByStatus(status, requestedLimit, currentOffset); + const {reports, total} = await reportService.listReportsByStatus(status, requestedLimit, currentOffset); const requestCache = createRequestCache(); const reportNsfwLookupCache = createReportNsfwLookupCache(); const reportResponses = await Promise.all( @@ -84,6 +84,9 @@ export class AdminReportService { ); return { reports: reportResponses, + total, + offset: currentOffset, + limit: requestedLimit, }; } diff --git a/fluxer_api/src/api/report/ReportService.ts b/fluxer_api/src/api/report/ReportService.ts index c49484a28..f425e8a0d 100644 --- a/fluxer_api/src/api/report/ReportService.ts +++ b/fluxer_api/src/api/report/ReportService.ts @@ -813,14 +813,19 @@ export class ReportService { return reports.filter((report): report is IARSubmission => report !== null); } - async listReportsByStatus(status: number, limit?: number, offset?: number): Promise> { + async listReportsByStatus( + status: number, + limit?: number, + offset?: number, + ): Promise<{reports: Array; total: number}> { if (!this.reportSearchService) { throw new FeatureTemporarilyDisabledError(); } - const {hits} = await this.reportSearchService.listReportsByStatus(status, limit, offset); + const {hits, total} = await this.reportSearchService.listReportsByStatus(status, limit, offset); const reportIds = hits.map((hit) => createReportID(BigInt(hit.id))); - const reports = await Promise.all(reportIds.map((id) => this.reportRepository.getReport(id))); - return reports.filter((report): report is IARSubmission => report !== null); + const loaded = await Promise.all(reportIds.map((id) => this.reportRepository.getReport(id))); + const reports = loaded.filter((report): report is IARSubmission => report !== null); + return {reports, total: Math.max(0, total - (hits.length - reports.length))}; } async resolveReport( diff --git a/packages/schema/src/domains/admin/AdminSchemas.ts b/packages/schema/src/domains/admin/AdminSchemas.ts index 819eb45b8..b51315bb4 100644 --- a/packages/schema/src/domains/admin/AdminSchemas.ts +++ b/packages/schema/src/domains/admin/AdminSchemas.ts @@ -1444,9 +1444,6 @@ export const ReportAdminResponseSchema = z.object({ message_context: z.array(ReportMessageContextSchema).optional(), message_responses: z.array(MessageResponseSchema).optional(), }); -const ListReportsResponse = z.object({ - reports: z.array(ReportAdminResponseSchema), -}); export const ResolveReportResponse = z.object({ report_id: SnowflakeStringType, status: ReportStatusSchema, @@ -1459,7 +1456,7 @@ const SearchReportsResponse = z.object({ offset: z.number(), limit: z.number(), }); -export const AdminReportListResponse = z.union([SearchReportsResponse, ListReportsResponse]); +export const AdminReportListResponse = SearchReportsResponse; const LimitKeyMetadataSchema = z.object({ key: z.string(), label: z.string(),