mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-15 16:05:49 +01:00
relocate special roles to api request
This commit is contained in:
6
backend/src/models/requests/authrequest.dto.ts
Normal file
6
backend/src/models/requests/authrequest.dto.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { FastifyRequest } from 'fastify';
|
||||
import { EUserBackend } from '../entities/user.entity';
|
||||
|
||||
export default interface AuthFasityRequest extends FastifyRequest {
|
||||
user: EUserBackend;
|
||||
}
|
||||
10
backend/src/models/requests/imageroute.dto.ts
Normal file
10
backend/src/models/requests/imageroute.dto.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsDefined, ValidateNested } from 'class-validator';
|
||||
import { MultiPartFileDto } from './multipart.dto';
|
||||
|
||||
export class ImageUploadDto {
|
||||
@IsDefined()
|
||||
@ValidateNested()
|
||||
@Type(() => MultiPartFileDto)
|
||||
image: MultiPartFileDto;
|
||||
}
|
||||
64
backend/src/models/requests/multipart.dto.ts
Normal file
64
backend/src/models/requests/multipart.dto.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { BusboyFileStream } from '@fastify/busboy';
|
||||
import { HttpException } from '@nestjs/common';
|
||||
import { IsDefined, IsNotEmpty, IsString } from 'class-validator';
|
||||
import { MultipartFile } from 'fastify-multipart';
|
||||
|
||||
export class MultiPartFileDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
fieldname: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
encoding: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
filename: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
mimetype: string;
|
||||
|
||||
@IsDefined()
|
||||
toBuffer: () => Promise<Buffer>;
|
||||
|
||||
@IsDefined()
|
||||
file: BusboyFileStream;
|
||||
|
||||
constructor(file: MultipartFile, exceptionOnFail: HttpException) {
|
||||
this.fieldname = file.fieldname;
|
||||
this.encoding = file.encoding;
|
||||
this.filename = file.filename;
|
||||
this.mimetype = file.mimetype;
|
||||
this.toBuffer = async () => {
|
||||
try {
|
||||
return await file.toBuffer();
|
||||
} catch (e) {
|
||||
throw exceptionOnFail;
|
||||
}
|
||||
};
|
||||
|
||||
this.file = file.file;
|
||||
}
|
||||
}
|
||||
|
||||
export class MultiPartFieldDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
fieldname: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
encoding: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
value: string;
|
||||
|
||||
constructor(file: MultipartFile) {
|
||||
this.fieldname = file.fieldname;
|
||||
this.encoding = file.encoding;
|
||||
this.value = (file as any).value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user