🐛(y-provider) increase JSON size limits for transcription conversion
Problem: - Default Express JSON parser limit (100kb) is insufficient for larger transcription files - 2-hour audio transcriptions slightly exceed the 100kb limit, causing request failures Solution: - Implemented custom middleware to apply different JSON parser configurations based on route - Applied 500kb limit specifically for transcription conversion endpoints - Maintained default limits for all other routes to preserve security Technical notes: - Could not find a built-in Express solution to specify parser config per route - Custom middleware conditionally applies the appropriate parser configuration
This commit is contained in:
@@ -24,6 +24,7 @@ and this project adheres to
|
||||
- ✅(frontend) Improve tests coverage
|
||||
- ⬆️(docker) upgrade backend image to python 3.13 #973
|
||||
- ⬆️(docker) upgrade node images to alpine 3.21
|
||||
- 🐛(y-provider) increase JSON size limits for transcription conversion
|
||||
|
||||
|
||||
### Removed
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import request from 'supertest';
|
||||
|
||||
import { routes } from '@/routes';
|
||||
|
||||
const port = 5557;
|
||||
const origin = 'http://localhost:3000';
|
||||
|
||||
@@ -36,4 +38,34 @@ describe('Server Tests', () => {
|
||||
expect(response.body.error).toBe('Forbidden');
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow JSON payloads up to 500kb for the CONVERT_MARKDOWN route', async () => {
|
||||
const largePayload = 'a'.repeat(400 * 1024); // 400kb payload
|
||||
const response = await request(app)
|
||||
.post(routes.CONVERT_MARKDOWN)
|
||||
.send({ data: largePayload })
|
||||
.set('Content-Type', 'application/json');
|
||||
|
||||
expect(response.status).not.toBe(413);
|
||||
});
|
||||
|
||||
it('should reject JSON payloads larger than 500kb for the CONVERT_MARKDOWN route', async () => {
|
||||
const oversizedPayload = 'a'.repeat(501 * 1024); // 501kb payload
|
||||
const response = await request(app)
|
||||
.post(routes.CONVERT_MARKDOWN)
|
||||
.send({ data: oversizedPayload })
|
||||
.set('Content-Type', 'application/json');
|
||||
|
||||
expect(response.status).toBe(413);
|
||||
});
|
||||
|
||||
it('should use the default JSON limit for other routes', async () => {
|
||||
const largePayload = 'a'.repeat(150 * 1024);
|
||||
const response = await request(app)
|
||||
.post('/some-other-route')
|
||||
.send({ data: largePayload })
|
||||
.set('Content-Type', 'application/json');
|
||||
|
||||
expect(response.status).toBe(413);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,7 +21,13 @@ import { logger } from '../utils';
|
||||
*/
|
||||
export const initServer = () => {
|
||||
const { app } = expressWebsockets(express());
|
||||
app.use(express.json());
|
||||
app.use((req, res, next) => {
|
||||
if (req.path === routes.CONVERT_MARKDOWN) {
|
||||
// Large transcript files are bigger than the default '100kb' limit
|
||||
return express.json({ limit: '500kb' })(req, res, next);
|
||||
}
|
||||
express.json()(req, res, next);
|
||||
});
|
||||
app.use(corsMiddleware);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user