mirror of
https://github.com/hknsh/project-knedita.git
synced 2024-11-28 09:31:16 +00:00
feat: downgraded swc and file-type, added field count on user info
This commit is contained in:
parent
007def701e
commit
10701c16be
5 changed files with 12 additions and 12 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -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",
|
||||
|
|
|
@ -56,6 +56,12 @@ export class UserService {
|
|||
attachments: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
_count: {
|
||||
select: {
|
||||
comments: true,
|
||||
likes: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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<typeof import("file-type")>);
|
||||
|
||||
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(
|
||||
|
|
|
@ -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<typeof import("file-type")>);
|
||||
|
||||
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({
|
||||
|
|
Loading…
Reference in a new issue