Ajoute des composants UI et des packages Radix

Ajout des nouveaux composants UI : Alert, Badge, Form, Sheet, Tabs et Input dans le répertoire frontend. Mise à jour du fichier package.json avec des nouvelles dépendances Radix UI et des autres bibliothèques nécessaires. Ajout d'une configuration pour TailwindCSS dans components.json.
This commit is contained in:
2024-08-22 15:24:18 +02:00
parent 53c7938304
commit 25fc0127b2
61 changed files with 9094 additions and 927 deletions

View File

@@ -6,3 +6,7 @@ export class AppService {
return { message: "Hello API" };
}
}
const hello: object = {
name: "ABC",
};

View File

@@ -1,13 +1,17 @@
import { BadRequestException, Injectable, InternalServerErrorException, NotFoundException } from "@nestjs/common";
import * as crypto from "node:crypto";
import { readFile, writeFile } from 'node:fs/promises';
import { join } from "node:path";
import * as console from "node:console";
import FileType from 'file-type';
import * as crypto from "node:crypto";
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import {
BadRequestException,
Injectable,
InternalServerErrorException,
NotFoundException,
} from "@nestjs/common";
import FileType from "file-type";
@Injectable()
export class StorageService {
/**
* Saves the given file with a generated file name that includes a prefix,
* the checksum of the file, and the file type extension.
@@ -17,10 +21,10 @@ export class StorageService {
* @returns {Promise<string>} A promise that resolves with the generated file name after the file is saved.
*/
private async save(prefix: string, file: Buffer) {
const checksum = await this.checkConditions(file)
const fileType = await FileType.fileTypeFromBuffer(file)
const checksum = await this.checkConditions(file);
const fileType = await FileType.fileTypeFromBuffer(file);
const fileName = `${prefix.toLowerCase()}-${checksum}.${fileType.ext.toLowerCase()}`;
await this.saveFile(fileName, file)
await this.saveFile(fileName, file);
return fileName;
//SEC TODO Catch case
}
@@ -32,7 +36,7 @@ export class StorageService {
* @return {string} - The hexadecimal representation of the checksum.
*/
private getChecksum(file: Buffer): string {
return crypto.createHash('sha256').update(file).digest('hex').toLowerCase();
return crypto.createHash("sha256").update(file).digest("hex").toLowerCase();
}
/**
@@ -47,10 +51,10 @@ export class StorageService {
*/
private async saveFile(fileName: string, file: Buffer): Promise<void> {
try {
await writeFile(join(process.cwd(), 'files/', fileName), file, 'utf8');
await writeFile(join(process.cwd(), "files/", fileName), file, "utf8");
} catch (err) {
console.error(err);
throw new InternalServerErrorException("File save failed !")
throw new InternalServerErrorException("File save failed !");
}
}
@@ -62,17 +66,21 @@ export class StorageService {
* @throws BadRequestException - If the file type is invalid or the file size exceeds the limit.
*/
private async checkConditions(file: Buffer): Promise<string> {
const checksum = this.getChecksum(file)
const fileType = await FileType.fileTypeFromBuffer(file)
const checksum = this.getChecksum(file);
const fileType = await FileType.fileTypeFromBuffer(file);
//TODO make file type configurable by admin
if (!fileType || !fileType.mime.startsWith('image/')) {
throw new BadRequestException('Invalid file type. Only images are allowed.');
if (!fileType || !fileType.mime.startsWith("image/")) {
throw new BadRequestException(
"Invalid file type. Only images are allowed.",
);
}
//check file size is less than 2mb
const fileSize = file.byteLength;
//TODO make file size configurable by admin
if (fileSize > 2 * 1024 * 1024) {
throw new BadRequestException('File size exceeds the limit. Maximum file size allowed is 2MB.');
throw new BadRequestException(
"File size exceeds the limit. Maximum file size allowed is 2MB.",
);
}
return checksum;
}
@@ -86,10 +94,9 @@ export class StorageService {
*/
private async getFile(fileName: string): Promise<Buffer> {
try {
return await readFile(join(process.cwd(), 'files/', fileName));
return await readFile(join(process.cwd(), "files/", fileName));
} catch (err) {
throw new NotFoundException("File not found")
throw new NotFoundException("File not found");
}
}
}