refactor source code

This commit is contained in:
2024-10-29 17:42:54 +07:00
parent 3b23d9e0b7
commit 152bb50da8
83 changed files with 8473 additions and 7577 deletions

View File

@@ -1,6 +1,6 @@
import { Module, Global } from '@nestjs/common';
import { MinioService } from './minio.service';
import { NestMinioModule } from 'nestjs-minio';
import { Module, Global } from '@nestjs/common'
import { MinioService } from './minio.service'
import { NestMinioModule } from 'nestjs-minio'
@Global()
@Module({
imports: [

View File

@@ -1,9 +1,9 @@
import { Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { FileUpload } from 'graphql-upload/processRequest.js';
import { Client } from 'minio';
import { MINIO_CONNECTION } from 'nestjs-minio';
import { v4 as uuidv4 } from 'uuid';
import { Inject, Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { FileUpload } from 'graphql-upload/processRequest.js'
import { Client } from 'minio'
import { MINIO_CONNECTION } from 'nestjs-minio'
import { v4 as uuidv4 } from 'uuid'
@Injectable()
export class MinioService {
constructor(
@@ -13,10 +13,10 @@ export class MinioService {
async uploadFile(file: FileUpload, category: string) {
// sonar ignore next
const { mimetype, createReadStream, filename: actualFileName } = await file;
const filename = this.fileName();
const Name = `${category}/${filename}`;
const fileBuffer = createReadStream();
const { mimetype, createReadStream, filename: actualFileName } = await file
const filename = this.fileName()
const Name = `${category}/${filename}`
const fileBuffer = createReadStream()
const result = await this.minioClient.putObject(
this.configService.get('BUCKET_NAME') ?? 'epess',
@@ -26,15 +26,15 @@ export class MinioService {
{
'Content-Type': mimetype,
},
);
return { result, filename, mimetype, actualFileName };
)
return { result, filename, mimetype, actualFileName }
}
async getFileUrl(id: string, category: string) {
if (!id) {
return null;
return null
}
let url = null;
let url = null
try {
url = await this.minioClient.presignedUrl(
@@ -42,23 +42,23 @@ export class MinioService {
this.configService.get('BUCKET_NAME') ?? 'epess',
`${category}/${id}`,
60 * 60 * 24 * 7,
);
)
} catch (error) {
console.log(error);
console.log(error)
}
console.log(url);
return url;
console.log(url)
return url
}
async deleteFile(id: string, category: string) {
return await this.minioClient.removeObject(
this.configService.get('BUCKET_NAME') ?? 'epess',
`${category}/${id}`,
);
)
}
fileName() {
// generate a unique file name using uuid
return uuidv4();
return uuidv4()
}
}