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
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ export async function GET(req: NextRequest, { params }: { params: GetBlobParams
})
const url = new URL(item.downloadURL)
const imageRegex = /\.(jpg|jpeg|png|webp|avif|gif)$/;

const file = await fetch(url).then(r => r.blob())
const headers = new Headers()
if (new RegExp(imageRegex).exec(path)) {
const file = await fetch(url).then(r => r.blob());
const headers = new Headers();
const cacheExpirationInSeconds = 60 * 60 * 24 * 30 // 30 days

headers.set("Content-Type", "image/*");
headers.set("Cache-Control", `max-age=${cacheExpirationInSeconds}`);

return new NextResponse(file, { status: 200, headers })
} else {
return NextResponse.redirect(url)
headers.set("Cache-Control", `max-age=${cacheExpirationInSeconds}`)
}
return new NextResponse(file, { status: 200, headers })
}
2 changes: 1 addition & 1 deletion src/features/projects/data/GitHubProjectDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,6 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
}

private getGitHubBlobURL(owner: string, repository: string, path: string, ref: string): string {
return `/api/github/blob/${owner}/${repository}/${path}?ref=${ref}`
return `/api/blob/${owner}/${repository}/${path}?ref=${ref}`
}
}