Skip to content

Commit 3a3e1fd

Browse files
authored
fix: S3. Change name generation from Date.now to UUID (#331)
* fix: S3. Change name generation from Date.now to UUID closes Visual-Regression-Tracker/Visual-Regression-Tracker#462
1 parent bab7d58 commit 3a3e1fd

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ jobs:
5959
run: docker compose -f docker-compose.yml -f docker-compose.ldap.yml down
6060

6161
- name: SonarCloud Scan
62-
uses: SonarSource/sonarcloud-github-action@master
62+
uses: SonarSource/sonarqube-scan-action@v5
6363
env:
64-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6564
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
6665

6766
test-migrations:

src/static/aws/s3.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Static } from '../static.interface';
44
import { DeleteObjectCommand, GetObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
55
import { Readable } from 'stream';
66
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
7+
import { generateNewImageName } from '../utils';
78

89
export class AWSS3Service implements Static {
910
private readonly logger: Logger = new Logger(AWSS3Service.name);
@@ -26,7 +27,7 @@ export class AWSS3Service implements Static {
2627
}
2728

2829
async saveImage(type: 'screenshot' | 'diff' | 'baseline', imageBuffer: Buffer): Promise<string> {
29-
const imageName = `${Date.now()}.${type}.png`;
30+
const imageName = generateNewImageName(type);
3031
try {
3132
await this.s3Client.send(
3233
new PutObjectCommand({

src/static/hdd/hdd.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { Logger } from '@nestjs/common';
22
import path from 'path';
33
import { writeFileSync, readFileSync, unlink, mkdirSync, existsSync } from 'fs';
44
import { PNG, PNGWithMetadata } from 'pngjs';
5-
import uuidAPIKey from 'uuid-apikey';
65
import { Static } from '../static.interface';
76
import { HDD_IMAGE_PATH } from './constants';
7+
import { generateNewImageName } from '../utils';
88

99
export class HddService implements Static {
1010
private readonly logger: Logger = new Logger(HddService.name);
1111

1212
generateNewImage(type: 'screenshot' | 'diff' | 'baseline'): { imageName: string; imagePath: string } {
13-
const imageName = `${uuidAPIKey.create({ noDashes: true }).apiKey}.${type}.png`;
13+
const imageName = generateNewImageName(type);
1414
return {
1515
imageName,
1616
imagePath: this.getImagePath(imageName),

src/static/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import uuidAPIKey from 'uuid-apikey';
2+
13
export function isHddStaticServiceConfigured() {
24
return !process.env.STATIC_SERVICE || process.env.STATIC_SERVICE === 'hdd';
35
}
46

57
export function isS3ServiceConfigured() {
68
return !process.env.STATIC_SERVICE || process.env.STATIC_SERVICE === 's3';
79
}
10+
11+
export function generateNewImageName(type: 'screenshot' | 'diff' | 'baseline'): string {
12+
return `${uuidAPIKey.create({ noDashes: true }).apiKey}.${type}.png`;
13+
}

0 commit comments

Comments
 (0)