feat: public api valid extensions
This commit is contained in:
parent
ba2e22f8e6
commit
fa8738e1f6
|
|
@ -8,9 +8,11 @@ export default async function IntegrationLayout({
|
|||
const t = await getT();
|
||||
|
||||
return (
|
||||
<div className="text-6xl text-center mt-[50px]">
|
||||
{t('adding_channel_redirecting_you', 'Adding channel, Redirecting You')}
|
||||
{children}
|
||||
<div className="bg-newBgColorInner p-[20px] flex flex-col transition-all flex-1">
|
||||
<div className="text-6xl text-center mt-[50px]">
|
||||
{t('adding_channel_redirecting_you', 'Adding channel, Redirecting You')}
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,28 @@
|
|||
import { ValidationArguments, ValidatorConstraintInterface, ValidatorConstraint } from "class-validator";
|
||||
import {
|
||||
ValidationArguments,
|
||||
ValidatorConstraintInterface,
|
||||
ValidatorConstraint,
|
||||
} from 'class-validator';
|
||||
|
||||
@ValidatorConstraint({ name: 'checkValidExtension', async: false })
|
||||
export class ValidUrlExtension implements ValidatorConstraintInterface {
|
||||
validate(text: string, args: ValidationArguments) {
|
||||
return (
|
||||
text.endsWith('.png') ||
|
||||
text.endsWith('.jpg') ||
|
||||
text.endsWith('.jpeg') ||
|
||||
text.endsWith('.gif') ||
|
||||
text.endsWith('.mp4')
|
||||
);
|
||||
}
|
||||
|
||||
defaultMessage(args: ValidationArguments) {
|
||||
// here you can provide default error message if validation failed
|
||||
return (
|
||||
'File must have a valid extension: .png, .jpg, .jpeg, .gif, or .mp4'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ValidatorConstraint({ name: 'checkValidPath', async: false })
|
||||
export class ValidUrlPath implements ValidatorConstraintInterface {
|
||||
|
|
@ -7,11 +31,15 @@ export class ValidUrlPath implements ValidatorConstraintInterface {
|
|||
return true;
|
||||
}
|
||||
|
||||
return (text || 'invalid url').indexOf(process.env.RESTRICT_UPLOAD_DOMAINS) > -1;
|
||||
return (
|
||||
(text || 'invalid url').indexOf(process.env.RESTRICT_UPLOAD_DOMAINS) > -1
|
||||
);
|
||||
}
|
||||
|
||||
defaultMessage(args: ValidationArguments) {
|
||||
// here you can provide default error message if validation failed
|
||||
return 'URL must contain the domain: ' + process.env.RESTRICT_UPLOAD_DOMAINS;
|
||||
return (
|
||||
'URL must contain the domain: ' + process.env.RESTRICT_UPLOAD_DOMAINS
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { IsDefined, IsString, IsUrl, ValidateIf, Validate } from 'class-validator';
|
||||
import { ValidUrlPath } from '@gitroom/helpers/utils/valid.url.path';
|
||||
import { ValidUrlExtension, ValidUrlPath } from '@gitroom/helpers/utils/valid.url.path';
|
||||
|
||||
export class MediaDto {
|
||||
@IsString()
|
||||
|
|
@ -9,6 +9,7 @@ export class MediaDto {
|
|||
@IsString()
|
||||
@IsDefined()
|
||||
@Validate(ValidUrlPath)
|
||||
@Validate(ValidUrlExtension)
|
||||
path: string;
|
||||
|
||||
@ValidateIf((o) => o.alt)
|
||||
|
|
|
|||
Loading…
Reference in New Issue