Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: add opt-in pagination to remaining list routes (#4903)

Adam Eivyb5b6d846db9d
diff --git a/server/routes/loraDatasets.js b/server/routes/loraDatasets.js
index 89bcf90695..01a0055117 100644
--- a/server/routes/loraDatasets.js
+++ b/server/routes/loraDatasets.js
@@ -11,7 +11,7 @@
import { Router } from 'express';
import { z } from 'zod';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
-import { validateRequest } from '../lib/validation.js';
+import { validateRequest, isPaginationRequested, paginateArray } from '../lib/validation.js';
import { uploadFields } from '../lib/multipart.js';
import {
addUploadedImage,
@@ -44,7 +44,9 @@ const listQuerySchema = z.object({
});
router.get('/', asyncHandler(async (req, res) => {
const filters = validateRequest(listQuerySchema, req.query);
- res.json(await listDatasets(filters));
+ const datasets = await listDatasets(filters);
+ if (!isPaginationRequested(req.query)) return res.json(datasets);
+ res.json(paginateArray(datasets, req.query, { defaultLimit: 50, maxLimit: 500 }));
}));
const createSchema = z.object({
diff --git a/server/routes/loraDatasets.pagination.test.js b/server/routes/loraDatasets.pagination.test.js
new file mode 100644
index 0000000000..5e404b5bc9
--- /dev/null
+++ b/server/routes/loraDatasets.pagination.test.js
@@ -0,0 +1,69 @@
+import { describe, it, expect, vi } from 'vitest';
+import express from 'express';
+import { request } from '../lib/testHelper.js';
+
+const datasets = Array.from({ length: 5 }, (_, i) => ({ id: `dataset-${i}` }));
+
+vi.mock('../services/loraDatasets.js', () => ({
+ addUploadedImage: vi.fn(),
+ createDataset: vi.fn(),
+ deleteDataset: vi.fn(),
+ deleteImage: vi.fn(),
+ getDataset: vi.fn(),
+ importGalleryImages: vi.fn(),
+ listDatasets: vi.fn(async () => datasets),
+ patchDataset: vi.fn(),
+ reconcileRenderingImages: vi.fn(),
+ stripSharedCaptionFragments: vi.fn(),
+ updateImageCaption: vi.fn(),
+}));
+
+vi.mock('../services/loraDatasetGenerate.js', () => ({
+ generateDatasetImages: vi.fn(),
+ getDatasetVariationAxes: vi.fn(),
+ sliceReferenceSheet: vi.fn(),
+}));
+
+vi.mock('../services/loraDatasetCaption.js', () => ({
+ attachCaptionSseClient: vi.fn(),
+ startCaptionRun: vi.fn(),
+}));
+
+vi.mock('../lib/multipart.js', () => ({
+ uploadFields: () => (_req, _res, next) => next(),
+}));
+
+vi.mock('../lib/loraDataset.js', () => ({
+ LORA_DATASET_ENTRY_KINDS: ['characters', 'objects', 'places', 'ingredients'],
+ computeDatasetReadiness: vi.fn(() => ({})),
+}));
+
+import { errorMiddleware } from '../lib/errorHandler.js';
+import loraDatasetRoutes from './loraDatasets.js';
+
+function makeApp() {
+ const app = express();
+ app.use(express.json());
+ app.use('/api/lora-datasets', loraDatasetRoutes);
+ app.use(errorMiddleware);
+ return app;
+}
+
+describe('LoRA dataset list pagination', () => {
+ it('preserves the bare array when pagination is not requested', async () => {
+ const response = await request(makeApp()).get('/api/lora-datasets');
+ expect(response.status).toBe(200);
+ expect(response.body).toEqual(datasets);
+ });
+
+ it('returns a bounded envelope when pagination is requested', async () => {
+ const response = await request(makeApp()).get('/api/lora-datasets?limit=2&offset=1');
+ expect(response.status).toBe(200);
+ expect(response.body).toEqual({
+ items: [{ id: 'dataset-1' }, { id: 'dataset-2' }],
+ total: 5,
+ limit: 2,
+ offset: 1,
+ });
+ });
+});
diff --git a/server/routes/pipeline.test.js b/server/routes/pipeline.test.js
index bb2bd29f48..c4d69f1f46 100644
--- a/server/routes/pipeline.test.js
+++ b/server/routes/pipeline.test.js
@@ -483,6 +483,25 @@ describe('pipeline routes', () => {
expect(nullUni.status).toBe(400);
});
+ it('GET /series preserves the bare array and supports bounded pagination', async () => {
+ const app = makeApp();
+ await request(app).post('/api/pipeline/series').send({ name: 'Alpha', universeId: 'u-test' });
+ await request(app).post('/api/pipeline/series').send({ name: 'Beta', universeId: 'u-test' });
+ await request(app).post('/api/pipeline/series').send({ name: 'Gamma', universeId: 'u-test' });
+
+ const unpaged = await request(app).get('/api/pipeline/series');
+ expect(unpaged.status).toBe(200);
+ expect(Array.isArray(unpaged.body)).toBe(true);
+ expect(unpaged.body).toHaveLength(3);
+
+ const paged = await request(app).get('/api/pipeline/series?limit=1&offset=1');
+ expect(paged.status).toBe(200);
+ expect(paged.body.items).toHaveLength(1);
+ expect(paged.body.total).toBe(3);
+ expect(paged.body.limit).toBe(1);
+ expect(paged.body.offset).toBe(1);
+ });
+
it('GET /series/duplicates returns grouped shape (static path not swallowed by /:id)', async () => {
const app = makeApp();
const res = await request(app).get('/api/pipeline/series/duplicates');
diff --git a/server/routes/pipeline/series.js b/server/routes/pipeline/series.js
index a615bf9542..fdb8abec58 100644
--- a/server/routes/pipeline/series.js
+++ b/server/routes/pipeline/series.js
@@ -7,7 +7,9 @@
import { Router } from 'express';
import { z } from 'zod';
import { asyncHandler, ServerError } from '../../lib/errorHandler.js';
-import { validateRequest, optionalBooleanMap, llmSchema } from '../../lib/validation.js';
+import {
+ validateRequest, optionalBooleanMap, llmSchema, isPaginationRequested, paginateArray,
+} from '../../lib/validation.js';
import { recordRenderPinFields } from '../../lib/sharedSchemas.js';
import * as seriesSvc from '../../services/pipeline/series.js';
import { TRIM_SIZES, INTERIOR_FONTS } from '../../lib/proseExportSettings.js';
@@ -344,8 +346,10 @@ const issueCreateSchema = z.object({
// Series routes
// =====================
-router.get('/series', asyncHandler(async (_req, res) => {
- res.json(await seriesSvc.listSeries());
+router.get('/series', asyncHandler(async (req, res) => {
+ const series = await seriesSvc.listSeries();
+ if (!isPaginationRequested(req.query)) return res.json(series);
+ res.json(paginateArray(series, req.query, { defaultLimit: 50, maxLimit: 500 }));
}));
router.post('/series', asyncHandler(async (req, res) => {
diff --git a/server/routes/videoDownload.js b/server/routes/videoDownload.js
index 4eee730b94..81420ce9fc 100644
--- a/server/routes/videoDownload.js
+++ b/server/routes/videoDownload.js
@@ -12,7 +12,9 @@
import { Router } from 'express';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
-import { validateRequest, videoDownloadSchema } from '../lib/validation.js';
+import {
+ validateRequest, videoDownloadSchema, isPaginationRequested, paginateArray,
+} from '../lib/validation.js';
import {
startVideoDownload,
attachDownloadSseClient,
@@ -30,8 +32,10 @@ router.post('/', asyncHandler(async (req, res) => {
// `downloads` is a distinct first segment from a job's `:jobId` (whose routes
// are always two-segment — `:jobId/events`, `:jobId/cancel`), so no collision.
-router.get('/downloads', asyncHandler(async (_req, res) => {
- res.json(await listDownloads());
+router.get('/downloads', asyncHandler(async (req, res) => {
+ const downloads = await listDownloads();
+ if (!isPaginationRequested(req.query)) return res.json(downloads);
+ res.json(paginateArray(downloads, req.query, { defaultLimit: 50, maxLimit: 500 }));
}));
router.delete('/downloads/:id', asyncHandler(async (req, res) => {
diff --git a/server/routes/videoDownload.test.js b/server/routes/videoDownload.test.js
index e78c31a4a0..8b7230c86a 100644
--- a/server/routes/videoDownload.test.js
+++ b/server/routes/videoDownload.test.js
@@ -47,6 +47,23 @@ describe('video download routes (#1946)', () => {
expect(svc.attachDownloadSseClient).not.toHaveBeenCalled();
});
+ it('GET /downloads returns a bounded envelope when pagination is requested', async () => {
+ svc.listDownloads.mockResolvedValueOnce(
+ Array.from({ length: 5 }, (_, i) => ({ id: `dl-${i}`, source: 'download' })),
+ );
+ const r = await request(app).get('/api/devtools/video-download/downloads?limit=2&offset=1');
+ expect(r.status).toBe(200);
+ expect(r.body).toEqual({
+ items: [
+ { id: 'dl-1', source: 'download' },
+ { id: 'dl-2', source: 'download' },
+ ],
+ total: 5,
+ limit: 2,
+ offset: 1,
+ });
+ });
+
it('DELETE /downloads/:id deletes a download', async () => {
const r = await request(app).delete('/api/devtools/video-download/downloads/dl-1');
expect(r.status).toBe(200);