Skip to content

Commit 3160f90

Browse files
committed
fix: add validation for share id and zip compression config variables
1 parent da54ce6 commit 3160f90

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

backend/src/config/config.service.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
NotFoundException,
66
} from "@nestjs/common";
77
import { Config } from "@prisma/client";
8-
import { PrismaService } from "src/prisma/prisma.service";
98
import { EventEmitter } from "events";
9+
import { PrismaService } from "src/prisma/prisma.service";
1010

1111
/**
1212
* ConfigService extends EventEmitter to allow listening for config updates,
@@ -100,6 +100,8 @@ export class ConfigService extends EventEmitter {
100100
);
101101
}
102102

103+
this.validateConfigVariable(key, value);
104+
103105
const updatedVariable = await this.prisma.config.update({
104106
where: {
105107
name_category: {
@@ -116,4 +118,24 @@ export class ConfigService extends EventEmitter {
116118

117119
return updatedVariable;
118120
}
121+
122+
validateConfigVariable(key: string, value: string | number | boolean) {
123+
const validations = [
124+
{
125+
key: "share.shareIdLength",
126+
condition: (value: number) => value >= 2 && value <= 50,
127+
message: "Share ID length must be between 2 and 50",
128+
},
129+
{
130+
key: "share.zipCompressionLevel",
131+
condition: (value: number) => value >= 0 && value <= 9,
132+
message: "Zip compression level must be between 0 and 9",
133+
},
134+
];
135+
136+
const validation = validations.find((validation) => validation.key == key);
137+
if (validation && !validation.condition(value as any)) {
138+
throw new BadRequestException(validation.message);
139+
}
140+
}
119141
}

frontend/src/components/upload/modals/showCreateUploadModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ const CreateUploadModalBody = ({
253253
</Group>
254254

255255
<Text
256+
truncate
256257
italic
257258
size="xs"
258259
sx={(theme) => ({

0 commit comments

Comments
 (0)