Skip to content

Commit 9b53db2

Browse files
zigzagdevclaude
andcommitted
feat: add proxyImageById endpoint for detail page images
GET /api/v1/heritage-image/image/{imageId} fetches a single image by its own PK, allowing the detail page to proxy each image in the images[] array independently. - /heritage-image/{siteId} → primary image (list page) - /heritage-image/image/{imageId} → individual image by PK (detail page) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 457bb39 commit 9b53db2

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/app/Packages/Features/Controller/HeritageImageController.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,24 @@ public function proxyImage(Request $request, int $id): Response|JsonResponse
3333
return response($upstream->body(), 200)
3434
->header('Content-Type', $upstream->header('Content-Type'));
3535
}
36+
37+
public function proxyImageById(Request $request, int $imageId): Response|JsonResponse
38+
{
39+
$image = Image::find($imageId);
40+
41+
if ($image === null) {
42+
return response()->json(['error' => 'Image not found'], 404);
43+
}
44+
45+
$upstream = Http::withHeaders([
46+
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
47+
])->get($image->url);
48+
49+
if ($upstream->failed()) {
50+
return response()->json(['error' => 'Failed to fetch image from upstream'], 502);
51+
}
52+
53+
return response($upstream->body(), 200)
54+
->header('Content-Type', $upstream->header('Content-Type'));
55+
}
3656
}

src/routes/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
Route::get('heritages/region-count', [WorldHeritageController::class, 'getWorldHeritagesCountByRegion']);
1111
Route::get('/heritages/{id}', [WorldHeritageController::class, 'getWorldHeritageById']);
1212
Route::get('/heritage-image/{id}', [HeritageImageController::class, 'proxyImage']);
13+
Route::get('/heritage-image/image/{imageId}', [HeritageImageController::class, 'proxyImageById']);
1314
});

0 commit comments

Comments
 (0)