refactor: organize imports and enhance formatting across backend files
Optimized import order, applied consistent formatting, and improved readability in various modules, including `contents`, `media`, and `auth` services.
This commit is contained in:
@@ -3,12 +3,12 @@
|
|||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nest build",
|
"build": "nest build",
|
||||||
"lint": "biome check",
|
"lint": "biome check",
|
||||||
"lint:write": "biome check --write",
|
"lint:write": "biome check --write",
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Module } from "@nestjs/common";
|
|
||||||
import { CacheModule } from "@nestjs/cache-manager";
|
import { CacheModule } from "@nestjs/cache-manager";
|
||||||
|
import { Module } from "@nestjs/common";
|
||||||
import { ConfigModule, ConfigService } from "@nestjs/config";
|
import { ConfigModule, ConfigService } from "@nestjs/config";
|
||||||
import { redisStore } from "cache-manager-redis-yet";
|
|
||||||
import { ScheduleModule } from "@nestjs/schedule";
|
import { ScheduleModule } from "@nestjs/schedule";
|
||||||
import { ThrottlerModule } from "@nestjs/throttler";
|
import { ThrottlerModule } from "@nestjs/throttler";
|
||||||
|
import { redisStore } from "cache-manager-redis-yet";
|
||||||
import { ApiKeysModule } from "./api-keys/api-keys.module";
|
import { ApiKeysModule } from "./api-keys/api-keys.module";
|
||||||
import { AppController } from "./app.controller";
|
import { AppController } from "./app.controller";
|
||||||
import { AppService } from "./app.service";
|
import { AppService } from "./app.service";
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import type { Request, Response } from "express";
|
|||||||
import { getIronSession } from "iron-session";
|
import { getIronSession } from "iron-session";
|
||||||
import { AuthService } from "./auth.service";
|
import { AuthService } from "./auth.service";
|
||||||
import { LoginDto } from "./dto/login.dto";
|
import { LoginDto } from "./dto/login.dto";
|
||||||
import { RefreshDto } from "./dto/refresh.dto";
|
|
||||||
import { RegisterDto } from "./dto/register.dto";
|
import { RegisterDto } from "./dto/register.dto";
|
||||||
import { Verify2faDto } from "./dto/verify-2fa.dto";
|
import { Verify2faDto } from "./dto/verify-2fa.dto";
|
||||||
import { getSessionOptions, SessionData } from "./session.config";
|
import { getSessionOptions, SessionData } from "./session.config";
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export const envSchema = z.object({
|
|||||||
MAIL_FROM: z.string().email(),
|
MAIL_FROM: z.string().email(),
|
||||||
|
|
||||||
DOMAIN_NAME: z.string(),
|
DOMAIN_NAME: z.string(),
|
||||||
|
|
||||||
// Sentry
|
// Sentry
|
||||||
SENTRY_DSN: z.string().optional(),
|
SENTRY_DSN: z.string().optional(),
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { CacheInterceptor, CacheTTL } from "@nestjs/cache-manager";
|
||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
@@ -5,6 +6,7 @@ import {
|
|||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
Header,
|
Header,
|
||||||
|
NotFoundException,
|
||||||
Param,
|
Param,
|
||||||
ParseBoolPipe,
|
ParseBoolPipe,
|
||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
@@ -15,9 +17,7 @@ import {
|
|||||||
UploadedFile,
|
UploadedFile,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
NotFoundException,
|
|
||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
import { CacheInterceptor, CacheTTL } from "@nestjs/cache-manager";
|
|
||||||
import { FileInterceptor } from "@nestjs/platform-express";
|
import { FileInterceptor } from "@nestjs/platform-express";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||||
@@ -130,9 +130,10 @@ export class ContentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const userAgent = req.headers["user-agent"] || "";
|
const userAgent = req.headers["user-agent"] || "";
|
||||||
const isBot = /bot|googlebot|crawler|spider|robot|crawling|facebookexternalhit|twitterbot/i.test(
|
const isBot =
|
||||||
userAgent,
|
/bot|googlebot|crawler|spider|robot|crawling|facebookexternalhit|twitterbot/i.test(
|
||||||
);
|
userAgent,
|
||||||
|
);
|
||||||
|
|
||||||
if (isBot) {
|
if (isBot) {
|
||||||
const imageUrl = this.contentsService.getFileUrl(content.storageKey);
|
const imageUrl = this.contentsService.getFileUrl(content.storageKey);
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import {
|
|||||||
tags,
|
tags,
|
||||||
users,
|
users,
|
||||||
} from "../database/schemas";
|
} from "../database/schemas";
|
||||||
import { MediaService } from "../media/media.service";
|
|
||||||
import type { MediaProcessingResult } from "../media/interfaces/media.interface";
|
import type { MediaProcessingResult } from "../media/interfaces/media.interface";
|
||||||
|
import { MediaService } from "../media/media.service";
|
||||||
import { S3Service } from "../s3/s3.service";
|
import { S3Service } from "../s3/s3.service";
|
||||||
import { CreateContentDto } from "./dto/create-content.dto";
|
import { CreateContentDto } from "./dto/create-content.dto";
|
||||||
|
|
||||||
@@ -43,7 +43,12 @@ export class ContentsService {
|
|||||||
async uploadAndProcess(
|
async uploadAndProcess(
|
||||||
userId: string,
|
userId: string,
|
||||||
file: Express.Multer.File,
|
file: Express.Multer.File,
|
||||||
data: { title: string; type: "meme" | "gif"; categoryId?: string; tags?: string[] },
|
data: {
|
||||||
|
title: string;
|
||||||
|
type: "meme" | "gif";
|
||||||
|
categoryId?: string;
|
||||||
|
tags?: string[];
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
// 0. Validation du format et de la taille
|
// 0. Validation du format et de la taille
|
||||||
const allowedMimeTypes = [
|
const allowedMimeTypes = [
|
||||||
@@ -304,7 +309,8 @@ export class ContentsService {
|
|||||||
getFileUrl(storageKey: string): string {
|
getFileUrl(storageKey: string): string {
|
||||||
const endpoint = this.configService.get("S3_ENDPOINT");
|
const endpoint = this.configService.get("S3_ENDPOINT");
|
||||||
const port = this.configService.get("S3_PORT");
|
const port = this.configService.get("S3_PORT");
|
||||||
const protocol = this.configService.get("S3_USE_SSL") === true ? "https" : "http";
|
const protocol =
|
||||||
|
this.configService.get("S3_USE_SSL") === true ? "https" : "http";
|
||||||
const bucket = this.configService.get("S3_BUCKET_NAME");
|
const bucket = this.configService.get("S3_BUCKET_NAME");
|
||||||
|
|
||||||
if (endpoint === "localhost" || endpoint === "127.0.0.1") {
|
if (endpoint === "localhost" || endpoint === "127.0.0.1") {
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
import { IsEnum, IsNotEmpty, IsOptional, IsString, IsUUID } from "class-validator";
|
import {
|
||||||
|
IsEnum,
|
||||||
|
IsNotEmpty,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
IsUUID,
|
||||||
|
} from "class-validator";
|
||||||
import { ContentType } from "./create-content.dto";
|
import { ContentType } from "./create-content.dto";
|
||||||
|
|
||||||
export class UploadContentDto {
|
export class UploadContentDto {
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import { readFile, unlink, writeFile } from "node:fs/promises";
|
||||||
|
import { tmpdir } from "node:os";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { Readable } from "node:stream";
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
Injectable,
|
Injectable,
|
||||||
@@ -7,10 +11,6 @@ import {
|
|||||||
import { ConfigService } from "@nestjs/config";
|
import { ConfigService } from "@nestjs/config";
|
||||||
import * as NodeClam from "clamscan";
|
import * as NodeClam from "clamscan";
|
||||||
import ffmpeg from "fluent-ffmpeg";
|
import ffmpeg from "fluent-ffmpeg";
|
||||||
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import { Readable } from "node:stream";
|
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import type {
|
import type {
|
||||||
@@ -19,7 +19,9 @@ import type {
|
|||||||
} from "./interfaces/media.interface";
|
} from "./interfaces/media.interface";
|
||||||
|
|
||||||
interface ClamScanner {
|
interface ClamScanner {
|
||||||
scanStream(stream: Readable): Promise<{ isInfected: boolean; viruses: string[] }>;
|
scanStream(
|
||||||
|
stream: Readable,
|
||||||
|
): Promise<{ isInfected: boolean; viruses: string[] }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -34,7 +36,7 @@ export class MediaService {
|
|||||||
|
|
||||||
private async initClamScan() {
|
private async initClamScan() {
|
||||||
try {
|
try {
|
||||||
// @ts-ignore
|
// @ts-expect-error
|
||||||
const scanner = await new NodeClam().init({
|
const scanner = await new NodeClam().init({
|
||||||
clamdscan: {
|
clamdscan: {
|
||||||
host: this.configService.get<string>("CLAMAV_HOST", "localhost"),
|
host: this.configService.get<string>("CLAMAV_HOST", "localhost"),
|
||||||
|
|||||||
Reference in New Issue
Block a user