mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
fix(api): always return the page total when listing reports (#2534)
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Array<IARSubmission>> {
|
||||
async listReportsByStatus(
|
||||
status: number,
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
): Promise<{reports: Array<IARSubmission>; 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(
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user