0
Fork 0
mirror of https://github.com/stonith404/pingvin-share.git synced 2025-01-22 01:22:32 -05:00

fix: add validation for share id and zip compression config variables

This commit is contained in:
Elias Schneider 2024-11-25 12:41:03 +01:00
parent da54ce6ee0
commit 3160f90e1d
No known key found for this signature in database
GPG key ID: 07E623B294202B6C
2 changed files with 24 additions and 1 deletions

View file

@ -5,8 +5,8 @@ import {
NotFoundException,
} from "@nestjs/common";
import { Config } from "@prisma/client";
import { PrismaService } from "src/prisma/prisma.service";
import { EventEmitter } from "events";
import { PrismaService } from "src/prisma/prisma.service";
/**
* ConfigService extends EventEmitter to allow listening for config updates,
@ -100,6 +100,8 @@ export class ConfigService extends EventEmitter {
);
}
this.validateConfigVariable(key, value);
const updatedVariable = await this.prisma.config.update({
where: {
name_category: {
@ -116,4 +118,24 @@ export class ConfigService extends EventEmitter {
return updatedVariable;
}
validateConfigVariable(key: string, value: string | number | boolean) {
const validations = [
{
key: "share.shareIdLength",
condition: (value: number) => value >= 2 && value <= 50,
message: "Share ID length must be between 2 and 50",
},
{
key: "share.zipCompressionLevel",
condition: (value: number) => value >= 0 && value <= 9,
message: "Zip compression level must be between 0 and 9",
},
];
const validation = validations.find((validation) => validation.key == key);
if (validation && !validation.condition(value as any)) {
throw new BadRequestException(validation.message);
}
}
}

View file

@ -253,6 +253,7 @@ const CreateUploadModalBody = ({
</Group>
<Text
truncate
italic
size="xs"
sx={(theme) => ({