Skip to content
Open
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
15 changes: 1 addition & 14 deletions app/lib/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { defaultConfig } from '@/app/lib/config';
import { env } from '@/app/config/env';
import { type S3 } from '@/app/lib/storage/s3';
import { isValidPlaywrightVersion } from '@/app/lib/pw';
import { getTimestamp } from '@/app/lib/time';

class Service {
private static instance: Service;
Expand Down Expand Up @@ -79,13 +80,6 @@ class Service {
});
}

const getTimestamp = (date?: Date | string) => {
if (!date) return 0;
if (typeof date === 'string') return new Date(date).getTime();

return date.getTime();
};

reports.sort((a, b) => getTimestamp(b.createdAt) - getTimestamp(a.createdAt));
const currentReports = handlePagination<ReportHistory>(reports, input?.pagination);

Expand Down Expand Up @@ -215,13 +209,6 @@ class Service {
return await storage.readResults(input);
}

const getTimestamp = (date?: Date | string) => {
if (!date) return 0;
if (typeof date === 'string') return new Date(date).getTime();

return date.getTime();
};

cached.sort((a, b) => getTimestamp(b.createdAt) - getTimestamp(a.createdAt));

let filtered = input?.project
Expand Down
3 changes: 2 additions & 1 deletion app/lib/storage/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export async function readFile(targetPath: string, contentType: string | null) {

async function getResultsCount() {
const files = await fs.readdir(RESULTS_FOLDER);
const zipFilesCount = files.filter((file) => file.endsWith('.zip'));

return Math.round(files.length / 2);
return zipFilesCount.length;
}

export async function readResults(input?: ReadResultsInput) {
Expand Down
24 changes: 5 additions & 19 deletions app/lib/storage/s3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { randomUUID, type UUID } from 'crypto';
import fs from 'fs/promises';
import { randomUUID, type UUID } from 'node:crypto';
import fs from 'node:fs/promises';
import path from 'node:path';
import { PassThrough, Readable } from 'node:stream';

Expand Down Expand Up @@ -42,6 +42,7 @@ import { withError } from '@/app/lib/withError';
import { env } from '@/app/config/env';
import { SiteWhiteLabelConfig } from '@/app/types';
import { defaultConfig, isConfigValid } from '@/app/lib/config';
import { getTimestamp } from '@/app/lib/time';

const createClient = () => {
const endPoint = env.S3_ENDPOINT;
Expand Down Expand Up @@ -183,7 +184,7 @@ export class S3 implements Storage {
let resultCount = 0;
let indexCount = 0;
let totalSize = 0;
const stream = this.client.listObjects(this.bucket, folderPath, true);
const stream = this.client.listObjectsV2(this.bucket, folderPath, true);

return new Promise((resolve, reject) => {
stream.on('data', (obj) => {
Expand Down Expand Up @@ -287,14 +288,6 @@ export class S3 implements Storage {
total: 0,
};
}

const getTimestamp = (date?: Date | string) => {
if (!date) return 0;
if (typeof date === 'string') return new Date(date).getTime();

return date.getTime();
};

jsonFiles.sort((a, b) => getTimestamp(b.lastModified) - getTimestamp(a.lastModified));

// check if we can apply pagination early
Expand Down Expand Up @@ -423,13 +416,6 @@ export class S3 implements Storage {
});

reportsStream.on('end', async () => {
const getTimestamp = (date?: Date | string) => {
if (!date) return 0;
if (typeof date === 'string') return new Date(date).getTime();

return date.getTime();
};

reports.sort((a, b) => getTimestamp(b.createdAt) - getTimestamp(a.createdAt));

const currentReports = handlePagination<Report>(reports, input?.pagination);
Expand Down Expand Up @@ -691,7 +677,7 @@ export class S3 implements Storage {
console.error(`[s3] failed to create temporary folder: ${mkdirTempError.message}`);
}

const resultsStream = this.client.listObjects(this.bucket, RESULTS_BUCKET, true);
const resultsStream = this.client.listObjectsV2(this.bucket, RESULTS_BUCKET, true);

console.log(`[s3] start processing...`);
for await (const result of resultsStream) {
Expand Down
7 changes: 7 additions & 0 deletions app/lib/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ export const parseMilliseconds = (ms: number) => {

return `${leftMs}ms`;
};

export const getTimestamp = (date?: Date | string) => {
if (!date) return 0;
if (typeof date === 'string') return new Date(date).getTime();

return date.getTime();
};