website cleanup

This commit is contained in:
2025-12-25 00:19:36 +01:00
parent d78854a4c6
commit 9486455b9e
82 changed files with 1223 additions and 363 deletions

View File

@@ -12,6 +12,8 @@ import { DeleteMediaOutputDTO } from './dtos/DeleteMediaOutputDTO';
import { GetAvatarOutputDTO } from './dtos/GetAvatarOutputDTO';
import { UpdateAvatarInputDTO } from './dtos/UpdateAvatarInputDTO';
import { UpdateAvatarOutputDTO } from './dtos/UpdateAvatarOutputDTO';
import { ValidateFaceInputDTO } from './dtos/ValidateFaceInputDTO';
import { ValidateFaceOutputDTO } from './dtos/ValidateFaceOutputDTO';
import type { MulterFile } from './types/MulterFile';
type RequestAvatarGenerationInput = RequestAvatarGenerationInputDTO;
@@ -118,4 +120,20 @@ export class MediaController {
res.status(HttpStatus.OK).json(dto);
}
@Post('avatar/validate-face')
@ApiOperation({ summary: 'Validate face photo for avatar generation' })
@ApiResponse({ status: 200, description: 'Face validation result', type: ValidateFaceOutputDTO })
async validateFacePhoto(
@Body() input: ValidateFaceInputDTO,
@Res() res: Response,
): Promise<void> {
const dto: ValidateFaceOutputDTO = await this.mediaService.validateFacePhoto(input);
if (dto.isValid) {
res.status(HttpStatus.OK).json(dto);
} else {
res.status(HttpStatus.BAD_REQUEST).json(dto);
}
}
}

View File

@@ -8,6 +8,8 @@ import type { GetMediaOutputDTO } from './dtos/GetMediaOutputDTO';
import type { DeleteMediaOutputDTO } from './dtos/DeleteMediaOutputDTO';
import type { GetAvatarOutputDTO } from './dtos/GetAvatarOutputDTO';
import type { UpdateAvatarOutputDTO } from './dtos/UpdateAvatarOutputDTO';
import type { ValidateFaceInputDTO } from './dtos/ValidateFaceInputDTO';
import type { ValidateFaceOutputDTO } from './dtos/ValidateFaceOutputDTO';
import type { RacingSuitColor } from '@core/media/domain/types/AvatarGenerationRequest';
import type { MulterFile } from './types/MulterFile';
@@ -179,4 +181,24 @@ export class MediaService {
return this.updateAvatarPresenter.responseModel;
}
async validateFacePhoto(input: ValidateFaceInputDTO): Promise<ValidateFaceOutputDTO> {
this.logger.debug('[MediaService] Validating face photo.');
// Simple validation: check if it's a valid base64 image
if (!input.imageData || !input.imageData.startsWith('data:image/')) {
return { isValid: false, errorMessage: 'Invalid image data' };
}
// Check file size (rough estimate from base64 length)
const base64Length = input.imageData.length;
const fileSizeInBytes = (base64Length * 3) / 4; // Rough estimate
const maxSize = 5 * 1024 * 1024; // 5MB
if (fileSizeInBytes > maxSize) {
return { isValid: false, errorMessage: 'Image too large (max 5MB)' };
}
return { isValid: true };
}
}

View File

@@ -0,0 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsOptional } from 'class-validator';
export class AvatarDTO {
@ApiProperty()
@IsString()
driverId!: string;
@ApiProperty({ required: false })
@IsOptional()
@IsString()
avatarUrl?: string;
}

View File

@@ -0,0 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNotEmpty } from 'class-validator';
export class ValidateFaceInputDTO {
@ApiProperty()
@IsString()
@IsNotEmpty()
imageData: string = '';
}

View File

@@ -0,0 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
export class ValidateFaceOutputDTO {
@ApiProperty()
isValid: boolean = false;
@ApiProperty({ required: false })
errorMessage?: string;
}