feat: enhance configuration and rate limiting

- Added new configuration options: trustProxy, uploadConcurrency, batchMaxItems, batchMaxSizeBytes, and maxRequestBodyBytes to AppConfig.
- Implemented utility functions for parsing environment variables and masking sensitive data.
- Updated rate limiting logic to use configurable window size and maximum requests per window.
- Introduced a middleware for rate limiting on specific routes.
- Refactored file handling routes to support streaming downloads instead of redirects.
- Improved error handling and response formatting in file routes.
- Added support for oversized request rejection based on Content-Length header.
- Updated Swagger documentation to reflect changes in API behavior and responses.
- Enhanced tests to cover new features and ensure proper functionality.
This commit is contained in:
MythEclipse
2026-05-29 03:33:39 +07:00
parent be813b1c0e
commit 5425f6d33d
16 changed files with 466 additions and 201 deletions
+4 -4
View File
@@ -6,19 +6,19 @@ import { handleHealth } from './routes/health';
import { handleSwaggerHtml, handleSwaggerJson } from './routes/swagger';
import { handleUpload } from './routes/upload';
import logger from './utils/logger';
import { cleanupRateLimitCache } from './utils/rateLimit';
import { cleanupRateLimitCache, withRateLimit } from './utils/rateLimit';
const server = serve({
port: config.port,
routes: {
'/api/upload': {
POST: handleUpload,
POST: withRateLimit(handleUpload),
},
'/f/:public_id': {
GET: handleFileRedirect,
GET: withRateLimit(handleFileRedirect),
},
'/file/:public_id/info': {
GET: handleFileInfo,
GET: withRateLimit(handleFileInfo),
},
'/health': {
GET: handleHealth,