Skip to content
Open
Changes from 3 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
21 changes: 12 additions & 9 deletions src/controllers/cdnController.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ export const proxyReportsFile = async (req, res, filePath) => {
const bucket = storage.bucket(BUCKET_NAME);
const file = bucket.file(objectPath);

// Check if file exists
const [exists] = await file.exists();
if (!exists) {
res.statusCode = 404;
res.end(JSON.stringify({ error: 'File not found' }));
return;
}

// Get file metadata for content type and caching
const [metadata] = await file.getMetadata();
// This implicitly checks if the file exists, saving a network request
let metadata;
try {
[metadata] = await file.getMetadata();
Comment on lines +57 to +60
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description mentions adding a benchmark at src/benchmarks/gcs_metadata.benchmark.js, but that file/directory isn’t included in this change set (and doesn’t appear to exist in src/). Either add the benchmark file as described or update the PR description to match what’s actually being changed.

Copilot uses AI. Check for mistakes.
} catch (error) {
if (error.code === 404) {
res.statusCode = 404;
res.end(JSON.stringify({ error: 'File not found' }));
return;
}
Comment on lines 56 to +66
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests for the /v1/static/* route are currently mocking file.exists() to drive the 404 path (e.g. mockFileExists.mockResolvedValue([false])), but this controller no longer calls exists(). As a result, the non-existent-file test will now hit getMetadata() (which isn’t mocked there) and likely fail with a 500 instead of 404. Update the tests to mock getMetadata() rejecting with a 404-shaped error for missing objects, and adjust/remove the exists()-failure test since that call no longer happens.

Copilot uses AI. Check for mistakes.
throw error;
}

// Determine content type
const contentType = metadata.contentType || getMimeType(objectPath);
Expand Down
Loading