@@ -11,6 +11,7 @@ import * as fs from "fs";
1111import * as mime from "mime-types" ;
1212import { ConfigService } from "src/config/config.service" ;
1313import { PrismaService } from "src/prisma/prisma.service" ;
14+ import { SHARE_DIRECTORY } from "../constants" ;
1415
1516@Injectable ( )
1617export class FileService {
@@ -39,7 +40,7 @@ export class FileService {
3940 let diskFileSize : number ;
4041 try {
4142 diskFileSize = fs . statSync (
42- `./data/uploads/shares /${ shareId } /${ file . id } .tmp-chunk`
43+ `${ SHARE_DIRECTORY } /${ shareId } /${ file . id } .tmp-chunk`
4344 ) . size ;
4445 } catch {
4546 diskFileSize = 0 ;
@@ -78,18 +79,18 @@ export class FileService {
7879 }
7980
8081 fs . appendFileSync (
81- `./data/uploads/shares /${ shareId } /${ file . id } .tmp-chunk` ,
82+ `${ SHARE_DIRECTORY } /${ shareId } /${ file . id } .tmp-chunk` ,
8283 buffer
8384 ) ;
8485
8586 const isLastChunk = chunk . index == chunk . total - 1 ;
8687 if ( isLastChunk ) {
8788 fs . renameSync (
88- `./data/uploads/shares /${ shareId } /${ file . id } .tmp-chunk` ,
89- `./data/uploads/shares /${ shareId } /${ file . id } `
89+ `${ SHARE_DIRECTORY } /${ shareId } /${ file . id } .tmp-chunk` ,
90+ `${ SHARE_DIRECTORY } /${ shareId } /${ file . id } `
9091 ) ;
9192 const fileSize = fs . statSync (
92- `./data/uploads/shares /${ shareId } /${ file . id } `
93+ `${ SHARE_DIRECTORY } /${ shareId } /${ file . id } `
9394 ) . size ;
9495 await this . prisma . file . create ( {
9596 data : {
@@ -111,9 +112,7 @@ export class FileService {
111112
112113 if ( ! fileMetaData ) throw new NotFoundException ( "File not found" ) ;
113114
114- const file = fs . createReadStream (
115- `./data/uploads/shares/${ shareId } /${ fileId } `
116- ) ;
115+ const file = fs . createReadStream ( `${ SHARE_DIRECTORY } /${ shareId } /${ fileId } ` ) ;
117116
118117 return {
119118 metaData : {
@@ -126,13 +125,13 @@ export class FileService {
126125 }
127126
128127 async deleteAllFiles ( shareId : string ) {
129- await fs . promises . rm ( `./data/uploads/shares /${ shareId } ` , {
128+ await fs . promises . rm ( `${ SHARE_DIRECTORY } /${ shareId } ` , {
130129 recursive : true ,
131130 force : true ,
132131 } ) ;
133132 }
134133
135134 getZip ( shareId : string ) {
136- return fs . createReadStream ( `./data/uploads/shares /${ shareId } /archive.zip` ) ;
135+ return fs . createReadStream ( `${ SHARE_DIRECTORY } /${ shareId } /archive.zip` ) ;
137136 }
138137}
0 commit comments