feat: CHUNKS_ENABLED config

This commit is contained in:
diced 2023-04-03 22:36:32 -07:00
parent 5178f762eb
commit 0ac81c887e
No known key found for this signature in database
GPG key ID: 370BD1BA142842D1
5 changed files with 10 additions and 1 deletions

View file

@ -136,6 +136,7 @@ export interface ConfigOAuth {
export interface ConfigChunks { export interface ConfigChunks {
max_size: number; max_size: number;
chunks_size: number; chunks_size: number;
enabled: boolean;
} }
export interface ConfigMfa { export interface ConfigMfa {

View file

@ -158,6 +158,7 @@ export default function readConfig() {
map('CHUNKS_MAX_SIZE', 'human-to-byte', 'chunks.max_size'), map('CHUNKS_MAX_SIZE', 'human-to-byte', 'chunks.max_size'),
map('CHUNKS_CHUNKS_SIZE', 'human-to-byte', 'chunks.chunks_size'), map('CHUNKS_CHUNKS_SIZE', 'human-to-byte', 'chunks.chunks_size'),
map('CHUNKS_ENABLED', 'boolean', 'chunks.enabled'),
map('MFA_TOTP_ISSUER', 'string', 'mfa.totp_issuer'), map('MFA_TOTP_ISSUER', 'string', 'mfa.totp_issuer'),
map('MFA_TOTP_ENABLED', 'boolean', 'mfa.totp_enabled'), map('MFA_TOTP_ENABLED', 'boolean', 'mfa.totp_enabled'),

View file

@ -201,10 +201,12 @@ const validator = s.object({
.object({ .object({
max_size: s.number.default(humanToBytes('90MB')), max_size: s.number.default(humanToBytes('90MB')),
chunks_size: s.number.default(humanToBytes('20MB')), chunks_size: s.number.default(humanToBytes('20MB')),
enabled: s.boolean.default(true),
}) })
.default({ .default({
max_size: humanToBytes('90MB'), max_size: humanToBytes('90MB'),
chunks_size: humanToBytes('20MB'), chunks_size: humanToBytes('20MB'),
enabled: true,
}), }),
mfa: s mfa: s
.object({ .object({

View file

@ -79,7 +79,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
if (fileMaxViews < 0) return res.badRequest('invalid max views (max views < 0)'); if (fileMaxViews < 0) return res.badRequest('invalid max views (max views < 0)');
// handle partial uploads before ratelimits // handle partial uploads before ratelimits
if (req.headers['content-range']) { if (req.headers['content-range'] && zconfig.chunks.enabled) {
// parses content-range header (bytes start-end/total) // parses content-range header (bytes start-end/total)
const [start, end, total] = req.headers['content-range'] const [start, end, total] = req.headers['content-range']
.replace('bytes ', '') .replace('bytes ', '')

View file

@ -44,6 +44,11 @@ if (!file.lastchunk) {
process.exit(1); process.exit(1);
} }
if (!config.chunks.enabled) {
logger.error('chunks are not enabled, worker should not have been started');
process.exit(1);
}
start(); start();
async function start() { async function start() {