feat: restrict upload directory

This commit is contained in:
Nevo David 2025-07-11 18:55:29 +07:00
parent 6785a9ec6d
commit 93b419f6bb
4 changed files with 22 additions and 9 deletions

View File

@ -1,5 +0,0 @@
import { createContext, useContext } from 'react';
import { type CreatePostDto } from '@gitroom/nestjs-libraries/dtos/posts/create.post.dto';
export const SetContext = createContext<{set?: CreatePostDto}>({});
export const useSet = () => useContext(SetContext);

View File

@ -2,7 +2,6 @@
import 'reflect-metadata';
import { useLaunchStore } from '@gitroom/frontend/components/new-launch/store';
import dayjs from 'dayjs';
import type { CreatePostDto } from '@gitroom/nestjs-libraries/dtos/posts/create.post.dto';
import { FC, useEffect } from 'react';
import { makeId } from '@gitroom/nestjs-libraries/services/make.is';
import { ManageModal } from '@gitroom/frontend/components/new-launch/manage.modal';
@ -16,7 +15,7 @@ export interface AddEditModalProps {
integrations: Integrations[];
allIntegrations?: Integrations[];
selectedChannels?: string[];
set?: CreatePostDto;
set?: any;
focusedChannel?: string;
addEditSets?: (data: any) => void;
reopenModal: () => void;
@ -162,7 +161,7 @@ export const AddEditModalInnerInner: FC<AddEditModalProps> = (props) => {
media: p.image || [],
}))
: props.set?.posts?.length
? props.set.posts[0].value.map((p) => ({
? props.set.posts[0].value.map((p: any) => ({
id: makeId(10),
content: p.content,
// @ts-ignore

View File

@ -0,0 +1,17 @@
import { ValidationArguments, ValidatorConstraintInterface, ValidatorConstraint } from "class-validator";
@ValidatorConstraint({ name: 'checkValidPath', async: false })
export class ValidUrlPath implements ValidatorConstraintInterface {
validate(text: string, args: ValidationArguments) {
if (!process.env.RESTRICT_UPLOAD_DOMAINS) {
return true;
}
return text.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;
}
}

View File

@ -1,4 +1,5 @@
import { IsDefined, IsString, IsUrl, ValidateIf } from 'class-validator';
import { IsDefined, IsString, IsUrl, ValidateIf, Validate } from 'class-validator';
import { ValidUrlPath } from '@gitroom/helpers/utils/valid.url.path';
export class MediaDto {
@IsString()
@ -7,6 +8,7 @@ export class MediaDto {
@IsString()
@IsDefined()
@Validate(ValidUrlPath)
path: string;
@ValidateIf((o) => o.alt)