@@ -6,26 +6,26 @@ import { ConfigService } from '@nestjs/config';
66
77@Injectable ( )
88export class StaticService {
9- constructor ( private configService : ConfigService ) {
10- }
9+ constructor ( private configService : ConfigService ) { }
1110
1211 saveImage ( type : 'screenshot' | 'diff' | 'baseline' , imageBuffer : Buffer ) : string {
13- const imageName = `${ Date . now ( ) } .${ type } .png`
12+ const imageName = `${ Date . now ( ) } .${ type } .png` ;
1413 writeFileSync ( this . getImagePath ( imageName ) , imageBuffer ) ;
15- return imageName
14+ return imageName ;
1615 }
1716
1817 getImage ( imageName : string ) : PNGWithMetadata {
19- let image : PNGWithMetadata
18+ let image : PNGWithMetadata ;
2019 try {
21- image = PNG . sync . read ( readFileSync ( this . getImagePath ( imageName ) ) )
20+ image = PNG . sync . read ( readFileSync ( this . getImagePath ( imageName ) ) ) ;
2221 } catch ( ex ) {
23- console . log ( `Cannot image: ${ imageName } . ${ ex } ` )
22+ console . log ( `Cannot image: ${ imageName } . ${ ex } ` ) ;
2423 }
2524 return image ;
2625 }
2726
2827 async deleteImage ( imageName : string ) : Promise < boolean > {
28+ if ( ! imageName ) return ;
2929 return new Promise ( ( resolvePromise , reject ) => {
3030 unlink ( this . getImagePath ( imageName ) , err => {
3131 if ( err ) {
@@ -37,18 +37,18 @@ export class StaticService {
3737 }
3838
3939 private getImagePath ( imageName : string ) : string {
40- const dir = this . configService . get ( 'IMG_UPLOAD_FOLDER' )
41- this . ensureDirectoryExistence ( dir )
40+ const dir = this . configService . get ( 'IMG_UPLOAD_FOLDER' ) ;
41+ this . ensureDirectoryExistence ( dir ) ;
4242 return path . resolve ( dir , imageName ) ;
4343 }
4444
4545 private ensureDirectoryExistence ( dir : string ) {
46- const filePath = path . resolve ( dir )
46+ const filePath = path . resolve ( dir ) ;
4747 if ( existsSync ( filePath ) ) {
4848 return true ;
4949 } else {
5050 mkdirSync ( dir , { recursive : true } ) ;
51- this . ensureDirectoryExistence ( dir )
51+ this . ensureDirectoryExistence ( dir ) ;
5252 }
5353 }
5454}
0 commit comments