diff --git a/src/app.ts b/src/app.ts index e1f6ad9..70547be 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,6 +4,9 @@ import { Storage } from './storage/types.ts'; import { Config } from './config.ts'; import { handleRpc, RpcRequest } from './rpc.ts'; +// Constants +const MAX_BATCH_SIZE = 100; + /** * Creates the Hono application with RPC interface */ @@ -62,8 +65,8 @@ export function createApp(storage: Storage, config: Config) { return c.json({ error: 'Empty request array' }, 400); } - if (requests.length > 100) { - return c.json({ error: 'Too many requests in batch (max 100)' }, 400); + if (requests.length > MAX_BATCH_SIZE) { + return c.json({ error: `Too many requests in batch (max ${MAX_BATCH_SIZE})` }, 400); } // Handle RPC diff --git a/src/rpc.ts b/src/rpc.ts index 3b4b1e4..00714c8 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -12,6 +12,9 @@ import { validateUsername, } from './crypto.ts'; +// Constants +const MAX_PAGE_SIZE = 100; + /** * RPC request format */ @@ -178,7 +181,7 @@ const handlers: Record = { // Paginated discovery mode if (limit !== undefined) { - const pageLimit = Math.min(Math.max(1, limit), 100); + const pageLimit = Math.min(Math.max(1, limit), MAX_PAGE_SIZE); const pageOffset = Math.max(0, offset || 0); const allServices = await storage.getServicesByName(