feat: downgraded swc and file-type, added field count on user info

This commit is contained in:
Hackntosh 2024-10-12 17:51:02 +01:00
parent 007def701e
commit 10701c16be
5 changed files with 12 additions and 12 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -46,7 +46,7 @@
"argon2": "^0.41.1", "argon2": "^0.41.1",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"dotenv-expand": "^11.0.6", "dotenv-expand": "^11.0.6",
"file-type": "^19.5.0", "file-type": "16.5.4",
"ioredis": "^5.4.1", "ioredis": "^5.4.1",
"nestjs-s3": "^2.0.1", "nestjs-s3": "^2.0.1",
"nestjs-zod": "^3.0.0", "nestjs-zod": "^3.0.0",
@ -66,7 +66,7 @@
"@nestjs/schematics": "^10.1.4", "@nestjs/schematics": "^10.1.4",
"@nestjs/testing": "^10.4.4", "@nestjs/testing": "^10.4.4",
"@swc/cli": "^0.1.65", "@swc/cli": "^0.1.65",
"@swc/core": "^1.7.35", "@swc/core": "1.7.25",
"@swc/jest": "^0.2.36", "@swc/jest": "^0.2.36",
"@types/jest": "^29.5.13", "@types/jest": "^29.5.13",
"@types/node": "^20.16.11", "@types/node": "^20.16.11",

View file

@ -56,6 +56,12 @@ export class UserService {
attachments: true, attachments: true,
createdAt: true, createdAt: true,
updatedAt: true, updatedAt: true,
_count: {
select: {
comments: true,
likes: true,
},
},
}, },
}, },
}, },

View file

@ -1,5 +1,6 @@
import { File } from "@nest-lab/fastify-multer"; import { File } from "@nest-lab/fastify-multer";
import { BadRequestException, Injectable, PipeTransform } from "@nestjs/common"; import { BadRequestException, Injectable, PipeTransform } from "@nestjs/common";
import { fromBuffer } from "file-type";
/** /**
* Magic Number validation with `file-type` module. * Magic Number validation with `file-type` module.
@ -7,12 +8,8 @@ import { BadRequestException, Injectable, PipeTransform } from "@nestjs/common";
@Injectable() @Injectable()
export class BufferValidator implements PipeTransform { export class BufferValidator implements PipeTransform {
async transform(value: File) { async transform(value: File) {
const { fileTypeFromBuffer } = await (eval(
'import("file-type")',
) as Promise<typeof import("file-type")>);
const ALLOWED_MIMES = ["image/jpeg", "image/png", "image/webp"]; 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)) { if (!buffer_type || !ALLOWED_MIMES.includes(buffer_type.mime)) {
throw new BadRequestException( throw new BadRequestException(

View file

@ -1,5 +1,6 @@
import { File } from "@nest-lab/fastify-multer"; import { File } from "@nest-lab/fastify-multer";
import { BadRequestException, Injectable, PipeTransform } from "@nestjs/common"; import { BadRequestException, Injectable, PipeTransform } from "@nestjs/common";
import { fromBuffer } from "file-type";
@Injectable() @Injectable()
export class MultiFileValidation implements PipeTransform { export class MultiFileValidation implements PipeTransform {
@ -8,16 +9,12 @@ export class MultiFileValidation implements PipeTransform {
const errors = []; const errors = [];
const { fileTypeFromBuffer } = await (eval(
'import("file-type")',
) as Promise<typeof import("file-type")>);
for (let i = 0; i < value.length; i++) { for (let i = 0; i < value.length; i++) {
const file = value[i]; const file = value[i];
const { buffer, size } = file; const { buffer, size } = file;
try { try {
const buffer_type = await fileTypeFromBuffer(buffer); const buffer_type = await fromBuffer(buffer);
if (!buffer_type || !ALLOWED_MIMES.includes(buffer_type.mime)) { if (!buffer_type || !ALLOWED_MIMES.includes(buffer_type.mime)) {
errors.push({ errors.push({