@@ -18,7 +18,11 @@ export class FileService {
1818 private readonly logger : WinstonLoggerService ,
1919 ) { }
2020
21- async handleUpload ( file : Express . Multer . File , uploadType : FileUploadType ) {
21+ async handleUpload (
22+ file : Express . Multer . File ,
23+ uploadType : FileUploadType ,
24+ userId : number ,
25+ ) {
2226 const today = this . getDateString ( ) ;
2327 const targetDir = path . join ( this . basePath , uploadType , today ) ;
2428
@@ -30,7 +34,17 @@ export class FileService {
3034
3135 await fs . writeFile ( filePath , file . buffer ) ;
3236
33- return filePath ;
37+ const { originalname, mimetype, size } = file ;
38+ const savedFile = await this . fileRepository . save ( {
39+ originalName : originalname ,
40+ mimetype,
41+ size,
42+ path : filePath ,
43+ user : { id : userId } ,
44+ } ) ;
45+ const accessUrl = this . generateAccessUrl ( filePath ) ;
46+
47+ return UploadFileResponseDto . toResponseDto ( savedFile , accessUrl ) ;
3448 }
3549
3650 private async ensureDirectory ( dir : string ) {
@@ -42,23 +56,6 @@ export class FileService {
4256 return now . toISOString ( ) . split ( 'T' ) [ 0 ] ;
4357 }
4458
45- async create (
46- file : Express . Multer . File ,
47- userId : number ,
48- ) : Promise < UploadFileResponseDto > {
49- const { originalname, mimetype, size, path } = file ;
50- const savedFile = await this . fileRepository . save ( {
51- originalName : originalname ,
52- mimetype,
53- size,
54- path,
55- user : { id : userId } ,
56- } ) ;
57- const accessUrl = this . generateAccessUrl ( path ) ;
58-
59- return UploadFileResponseDto . toResponseDto ( savedFile , accessUrl ) ;
60- }
61-
6259 private generateAccessUrl ( filePath : string ) : string {
6360 return filePath . replace ( this . basePath , '/objects' ) ;
6461 }
0 commit comments