Skip to content
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
23 changes: 12 additions & 11 deletions src/shared/static/static.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@ import { ConfigService } from '@nestjs/config';

@Injectable()
export class StaticService {
constructor(private configService: ConfigService) {
}
constructor(private configService: ConfigService) {}

saveImage(type: 'screenshot' | 'diff' | 'baseline', imageBuffer: Buffer): string {
const imageName = `${Date.now()}.${type}.png`
const imageName = `${Date.now()}.${type}.png`;
writeFileSync(this.getImagePath(imageName), imageBuffer);
return imageName
return imageName;
}

getImage(imageName: string): PNGWithMetadata {
let image: PNGWithMetadata
if (!imageName) return;
let image: PNGWithMetadata;
try {
image = PNG.sync.read(readFileSync(this.getImagePath(imageName)))
image = PNG.sync.read(readFileSync(this.getImagePath(imageName)));
} catch (ex) {
console.log(`Cannot image: ${imageName}. ${ex}`)
console.log(`Cannot image: ${imageName}. ${ex}`);
}
return image;
}

async deleteImage(imageName: string): Promise<boolean> {
if (!imageName) return;
return new Promise((resolvePromise, reject) => {
unlink(this.getImagePath(imageName), err => {
if (err) {
Expand All @@ -37,18 +38,18 @@ export class StaticService {
}

private getImagePath(imageName: string): string {
const dir = this.configService.get('IMG_UPLOAD_FOLDER')
this.ensureDirectoryExistence(dir)
const dir = this.configService.get('IMG_UPLOAD_FOLDER');
this.ensureDirectoryExistence(dir);
return path.resolve(dir, imageName);
}

private ensureDirectoryExistence(dir: string) {
const filePath = path.resolve(dir)
const filePath = path.resolve(dir);
if (existsSync(filePath)) {
return true;
} else {
mkdirSync(dir, { recursive: true });
this.ensureDirectoryExistence(dir)
this.ensureDirectoryExistence(dir);
}
}
}
2 changes: 1 addition & 1 deletion src/test-runs/diffResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TestStatus } from '@prisma/client';

export interface DiffResult {
status: TestStatus;
imageName: string;
diffName: string;
pixelMisMatchCount: number;
diffPercent: number;
isSameDimension: boolean;
Expand Down
8 changes: 8 additions & 0 deletions src/test-runs/test-runs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export class TestRunsController {
return this.testRunsService.findMany(buildId);
}

@Get('recalculateDiff/:id')
@ApiParam({ name: 'id', required: true })
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
recalculateDiff(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestRun> {
return this.testRunsService.recalculateDiff(id);
}

@Get('approve/:id')
@ApiParam({ name: 'id', required: true })
@ApiBearerAuth()
Expand Down
Loading