diff --git a/src/app/api/github/blob/[owner]/[repository]/[...path]/route.ts b/src/app/api/blob/[owner]/[repository]/[...path]/route.ts similarity index 79% rename from src/app/api/github/blob/[owner]/[repository]/[...path]/route.ts rename to src/app/api/blob/[owner]/[repository]/[...path]/route.ts index 9c8b595c..2dd2d532 100644 --- a/src/app/api/github/blob/[owner]/[repository]/[...path]/route.ts +++ b/src/app/api/blob/[owner]/[repository]/[...path]/route.ts @@ -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 }) } diff --git a/src/features/projects/data/GitHubProjectDataSource.ts b/src/features/projects/data/GitHubProjectDataSource.ts index f001549e..e055b4e3 100644 --- a/src/features/projects/data/GitHubProjectDataSource.ts +++ b/src/features/projects/data/GitHubProjectDataSource.ts @@ -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}` } }