Skip to content

Commit 3f2d84b

Browse files
committed
🐛(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
1 parent 7b9c362 commit 3f2d84b

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to
2424
- ✅(frontend) Improve tests coverage
2525
- ⬆️(docker) upgrade backend image to python 3.13 #973
2626
- ⬆️(docker) upgrade node images to alpine 3.21
27+
- 🐛(y-provider) increase JSON size limits for transcription conversion
2728

2829

2930
### Removed

src/frontend/servers/y-provider/__tests__/server.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import request from 'supertest';
22

3+
import { routes } from '@/routes';
4+
35
const port = 5557;
46
const origin = 'http://localhost:3000';
57

@@ -36,4 +38,34 @@ describe('Server Tests', () => {
3638
expect(response.body.error).toBe('Forbidden');
3739
});
3840
});
41+
42+
it('should allow JSON payloads up to 500kb for the CONVERT_MARKDOWN route', async () => {
43+
const largePayload = 'a'.repeat(400 * 1024); // 400kb payload
44+
const response = await request(app)
45+
.post(routes.CONVERT_MARKDOWN)
46+
.send({ data: largePayload })
47+
.set('Content-Type', 'application/json');
48+
49+
expect(response.status).not.toBe(413);
50+
});
51+
52+
it('should reject JSON payloads larger than 500kb for the CONVERT_MARKDOWN route', async () => {
53+
const oversizedPayload = 'a'.repeat(501 * 1024); // 501kb payload
54+
const response = await request(app)
55+
.post(routes.CONVERT_MARKDOWN)
56+
.send({ data: oversizedPayload })
57+
.set('Content-Type', 'application/json');
58+
59+
expect(response.status).toBe(413);
60+
});
61+
62+
it('should use the default JSON limit for other routes', async () => {
63+
const largePayload = 'a'.repeat(150 * 1024);
64+
const response = await request(app)
65+
.post('/some-other-route')
66+
.send({ data: largePayload })
67+
.set('Content-Type', 'application/json');
68+
69+
expect(response.status).toBe(413);
70+
});
3971
});

src/frontend/servers/y-provider/src/servers/appServer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ import { logger } from '../utils';
2121
*/
2222
export const initServer = () => {
2323
const { app } = expressWebsockets(express());
24-
app.use(express.json());
24+
app.use((req, res, next) => {
25+
if (req.path === routes.CONVERT_MARKDOWN) {
26+
// Large transcript files are bigger than the default '100kb' limit
27+
return express.json({ limit: '500kb' })(req, res, next);
28+
}
29+
express.json()(req, res, next);
30+
});
2531
app.use(corsMiddleware);
2632

2733
/**

0 commit comments

Comments
 (0)