mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-29 01:28:59 -05:00
fix: add validation for share id and zip compression config variables
This commit is contained in:
parent
da54ce6ee0
commit
3160f90e1d
2 changed files with 24 additions and 1 deletions
|
@ -5,8 +5,8 @@ import {
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
import { Config } from "@prisma/client";
|
import { Config } from "@prisma/client";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConfigService extends EventEmitter to allow listening for config updates,
|
* 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({
|
const updatedVariable = await this.prisma.config.update({
|
||||||
where: {
|
where: {
|
||||||
name_category: {
|
name_category: {
|
||||||
|
@ -116,4 +118,24 @@ export class ConfigService extends EventEmitter {
|
||||||
|
|
||||||
return updatedVariable;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,6 +253,7 @@ const CreateUploadModalBody = ({
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<Text
|
<Text
|
||||||
|
truncate
|
||||||
italic
|
italic
|
||||||
size="xs"
|
size="xs"
|
||||||
sx={(theme) => ({
|
sx={(theme) => ({
|
||||||
|
|
Loading…
Add table
Reference in a new issue