@@ -6,26 +6,27 @@ 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+ if ( ! imageName ) return ;
19+ let image : PNGWithMetadata ;
2020 try {
21- image = PNG . sync . read ( readFileSync ( this . getImagePath ( imageName ) ) )
21+ image = PNG . sync . read ( readFileSync ( this . getImagePath ( imageName ) ) ) ;
2222 } catch ( ex ) {
23- console . log ( `Cannot image: ${ imageName } . ${ ex } ` )
23+ console . log ( `Cannot image: ${ imageName } . ${ ex } ` ) ;
2424 }
2525 return image ;
2626 }
2727
2828 async deleteImage ( imageName : string ) : Promise < boolean > {
29+ if ( ! imageName ) return ;
2930 return new Promise ( ( resolvePromise , reject ) => {
3031 unlink ( this . getImagePath ( imageName ) , err => {
3132 if ( err ) {
@@ -37,18 +38,18 @@ export class StaticService {
3738 }
3839
3940 private getImagePath ( imageName : string ) : string {
40- const dir = this . configService . get ( 'IMG_UPLOAD_FOLDER' )
41- this . ensureDirectoryExistence ( dir )
41+ const dir = this . configService . get ( 'IMG_UPLOAD_FOLDER' ) ;
42+ this . ensureDirectoryExistence ( dir ) ;
4243 return path . resolve ( dir , imageName ) ;
4344 }
4445
4546 private ensureDirectoryExistence ( dir : string ) {
46- const filePath = path . resolve ( dir )
47+ const filePath = path . resolve ( dir ) ;
4748 if ( existsSync ( filePath ) ) {
4849 return true ;
4950 } else {
5051 mkdirSync ( dir , { recursive : true } ) ;
51- this . ensureDirectoryExistence ( dir )
52+ this . ensureDirectoryExistence ( dir ) ;
5253 }
5354 }
5455}
0 commit comments