mirror of
https://github.com/xtr-dev/rondevu-server.git
synced 2025-12-13 20:33:25 +00:00
Replace magic numbers with named constants in server
Refactoring: Extract magic numbers to named constants - MAX_BATCH_SIZE = 100 (batch request limit) - MAX_PAGE_SIZE = 100 (pagination limit) Replaced in: - app.ts: Batch size validation (line 68-69) - rpc.ts: Page size limit (line 184) Impact: Improves code clarity and makes limits configurable
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<string, RpcHandler> = {
|
||||
|
||||
// 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(
|
||||
|
||||
Reference in New Issue
Block a user