diff --git a/bun.lockb b/bun.lockb index 2097a75..c1c18f3 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 19c7b16..cc22cae 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "argon2": "^0.41.1", "dotenv": "^16.4.5", "dotenv-expand": "^11.0.6", - "file-type": "^19.5.0", + "file-type": "16.5.4", "ioredis": "^5.4.1", "nestjs-s3": "^2.0.1", "nestjs-zod": "^3.0.0", @@ -66,7 +66,7 @@ "@nestjs/schematics": "^10.1.4", "@nestjs/testing": "^10.4.4", "@swc/cli": "^0.1.65", - "@swc/core": "^1.7.35", + "@swc/core": "1.7.25", "@swc/jest": "^0.2.36", "@types/jest": "^29.5.13", "@types/node": "^20.16.11", diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 76d7768..2f2a78d 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -56,6 +56,12 @@ export class UserService { attachments: true, createdAt: true, updatedAt: true, + _count: { + select: { + comments: true, + likes: true, + }, + }, }, }, }, diff --git a/src/validators/buffer.validator.ts b/src/validators/buffer.validator.ts index f3460bc..d5a5003 100644 --- a/src/validators/buffer.validator.ts +++ b/src/validators/buffer.validator.ts @@ -1,5 +1,6 @@ import { File } from "@nest-lab/fastify-multer"; import { BadRequestException, Injectable, PipeTransform } from "@nestjs/common"; +import { fromBuffer } from "file-type"; /** * Magic Number validation with `file-type` module. @@ -7,12 +8,8 @@ import { BadRequestException, Injectable, PipeTransform } from "@nestjs/common"; @Injectable() export class BufferValidator implements PipeTransform { async transform(value: File) { - const { fileTypeFromBuffer } = await (eval( - 'import("file-type")', - ) as Promise); - const ALLOWED_MIMES = ["image/jpeg", "image/png", "image/webp"]; - const buffer_type = await fileTypeFromBuffer(value.buffer); + const buffer_type = await fromBuffer(value.buffer); if (!buffer_type || !ALLOWED_MIMES.includes(buffer_type.mime)) { throw new BadRequestException( diff --git a/src/validators/multi_file.validator.ts b/src/validators/multi_file.validator.ts index 62f6988..3d61be9 100644 --- a/src/validators/multi_file.validator.ts +++ b/src/validators/multi_file.validator.ts @@ -1,5 +1,6 @@ import { File } from "@nest-lab/fastify-multer"; import { BadRequestException, Injectable, PipeTransform } from "@nestjs/common"; +import { fromBuffer } from "file-type"; @Injectable() export class MultiFileValidation implements PipeTransform { @@ -8,16 +9,12 @@ export class MultiFileValidation implements PipeTransform { const errors = []; - const { fileTypeFromBuffer } = await (eval( - 'import("file-type")', - ) as Promise); - for (let i = 0; i < value.length; i++) { const file = value[i]; const { buffer, size } = file; try { - const buffer_type = await fileTypeFromBuffer(buffer); + const buffer_type = await fromBuffer(buffer); if (!buffer_type || !ALLOWED_MIMES.includes(buffer_type.mime)) { errors.push({