Download libraries/helpers/src/utils/valid.url.path.ts from Leon4gr45/postio: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/Leon4gr45/postio/resolve/main/libraries/helpers/src/utils/valid.url.path.ts
- Command line
-
hf download hf://spaces/Leon4gr45/postio/libraries/helpers/src/utils/valid.url.path.ts
-
curl -L -o valid.url.path.ts https://huggingface.co/spaces/Leon4gr45/postio/resolve/main/libraries/helpers/src/utils/valid.url.path.ts
1.51 kB
| import { | |
| ValidationArguments, | |
| ValidatorConstraintInterface, | |
| ValidatorConstraint, | |
| } from 'class-validator'; | |
| ({ name: 'checkValidExtension', async: false }) | |
| export class ValidUrlExtension implements ValidatorConstraintInterface { | |
| validate(text: string, args: ValidationArguments) { | |
| return ( | |
| !!text?.split?.('?')?.[0].endsWith('.png') || | |
| !!text?.split?.('?')?.[0].endsWith('.jpg') || | |
| !!text?.split?.('?')?.[0].endsWith('.jpeg') || | |
| !!text?.split?.('?')?.[0].endsWith('.gif') || | |
| !!text?.split?.('?')?.[0].endsWith('.webp') || | |
| !!text?.split?.('?')?.[0].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, .webp, or .mp4' | |
| ); | |
| } | |
| } | |
| ({ name: 'checkValidPath', async: false }) | |
| export class ValidUrlPath implements ValidatorConstraintInterface { | |
| validate(text: string, args: ValidationArguments) { | |
| if (!process.env.RESTRICT_UPLOAD_DOMAINS) { | |
| return true; | |
| } | |
| 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 + ' Make sure you first use the upload API route.' | |
| ); | |
| } | |
| } | |