Skip to content

Commit 53d613a

Browse files
committed
🐛(y-provider) use CONVERSION_FILE_MAX_SIZE settings
The settings CONVERSION_FILE_MAX_SIZE was not used in the y-provider, which caused a 413 Payload Too Large error when trying to convert a file larger than 500kb. This commit updates the y-provider to use the CONVERSION_FILE_MAX_SIZE settings, allowing it to handle larger files without throwing an error. CONVERSION_FILE_MAX_SIZE should follow the same value as the one defined in the backend settings, which is 20mb by default.
1 parent 9f9f269 commit 53d613a

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

src/backend/impress/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ class Base(Configuration):
736736

737737
# Imported file settings
738738
CONVERSION_FILE_MAX_SIZE = values.IntegerValue(
739-
20 * MB, # 10MB
739+
20 * MB,
740740
environ_name="CONVERSION_FILE_MAX_SIZE",
741741
environ_prefix=None,
742742
)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ vi.mock('../src/env', async (importOriginal) => {
99
...(await importOriginal()),
1010
COLLABORATION_SERVER_ORIGIN: 'http://localhost:3000',
1111
Y_PROVIDER_API_KEY: 'yprovider-api-key',
12+
CONVERSION_FILE_MAX_SIZE: 500 * 1024, // 500kb
1213
};
1314
});
1415

@@ -54,7 +55,7 @@ describe('Server Tests', () => {
5455
expect(response.status).not.toBe(413);
5556
});
5657

57-
it('rejects payloads larger than 500kb for the CONVERT route', async () => {
58+
it('rejects payloads larger than CONVERSION_FILE_MAX_SIZE for the CONVERT route', async () => {
5859
const app = initApp();
5960

6061
const oversizedPayload = 'a'.repeat(501 * 1024); // 501kb payload

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export const COLLABORATION_SERVER_SECRET = process.env
88
.COLLABORATION_SERVER_SECRET_FILE
99
? readFileSync(process.env.COLLABORATION_SERVER_SECRET_FILE, 'utf-8')
1010
: process.env.COLLABORATION_SERVER_SECRET || 'secret-api-key';
11+
export const CONVERSION_FILE_MAX_SIZE = process.env.CONVERSION_FILE_MAX_SIZE
12+
? Number(process.env.CONVERSION_FILE_MAX_SIZE)
13+
: 20971520; // 20 MB default
1114
export const Y_PROVIDER_API_KEY = process.env.Y_PROVIDER_API_KEY_FILE
1215
? readFileSync(process.env.Y_PROVIDER_API_KEY_FILE, 'utf-8')
1316
: process.env.Y_PROVIDER_API_KEY || 'yprovider-api-key';

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Sentry from '@sentry/node';
55
import express from 'express';
66
import expressWebsockets from 'express-ws';
77

8+
import { CONVERSION_FILE_MAX_SIZE } from '@/env';
89
import {
910
collaborationResetConnectionsHandler,
1011
collaborationWSHandler,
@@ -55,7 +56,7 @@ export const initApp = () => {
5556
routes.CONVERT,
5657
httpSecurity,
5758
express.raw({
58-
limit: '500kb',
59+
limit: CONVERSION_FILE_MAX_SIZE,
5960
type: '*/*',
6061
}),
6162
convertHandler,

0 commit comments

Comments
 (0)