Skip to content

fix: S3. Change name generation from Date.now to UUID #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ jobs:
run: docker compose -f docker-compose.yml -f docker-compose.ldap.yml down

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
uses: SonarSource/sonarqube-scan-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}

test-migrations:
Expand Down
3 changes: 2 additions & 1 deletion src/static/aws/s3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Static } from '../static.interface';
import { DeleteObjectCommand, GetObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { Readable } from 'stream';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { generateNewImageName } from '../utils';

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

async saveImage(type: 'screenshot' | 'diff' | 'baseline', imageBuffer: Buffer): Promise<string> {
const imageName = `${Date.now()}.${type}.png`;
const imageName = generateNewImageName(type);
try {
await this.s3Client.send(
new PutObjectCommand({
Expand Down
4 changes: 2 additions & 2 deletions src/static/hdd/hdd.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Logger } from '@nestjs/common';
import path from 'path';
import { writeFileSync, readFileSync, unlink, mkdirSync, existsSync } from 'fs';
import { PNG, PNGWithMetadata } from 'pngjs';
import uuidAPIKey from 'uuid-apikey';
import { Static } from '../static.interface';
import { HDD_IMAGE_PATH } from './constants';
import { generateNewImageName } from '../utils';

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

generateNewImage(type: 'screenshot' | 'diff' | 'baseline'): { imageName: string; imagePath: string } {
const imageName = `${uuidAPIKey.create({ noDashes: true }).apiKey}.${type}.png`;
const imageName = generateNewImageName(type);
return {
imageName,
imagePath: this.getImagePath(imageName),
Expand Down
6 changes: 6 additions & 0 deletions src/static/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import uuidAPIKey from 'uuid-apikey';

export function isHddStaticServiceConfigured() {
return !process.env.STATIC_SERVICE || process.env.STATIC_SERVICE === 'hdd';
}

export function isS3ServiceConfigured() {
return !process.env.STATIC_SERVICE || process.env.STATIC_SERVICE === 's3';
}

export function generateNewImageName(type: 'screenshot' | 'diff' | 'baseline'): string {
return `${uuidAPIKey.create({ noDashes: true }).apiKey}.${type}.png`;
}