Skip to content

Commit fc24478

Browse files
zigzagdevclaude
andcommitted
feat: implement HeritageImageController with proxyImage
Fetches the UNESCO image URL from world_heritage_site_images via the Image model and streams the binary response back to the browser, bypassing CORS/CORP restrictions that block direct browser requests. Closes #471 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9f5357e commit fc24478

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Packages\Features\Controller;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Image;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Http\Response;
9+
use Illuminate\Http\JsonResponse;
10+
use Illuminate\Support\Facades\Http;
11+
12+
class HeritageImageController extends Controller
13+
{
14+
public function proxyImage(Request $request, int $id): Response|JsonResponse
15+
{
16+
$image = Image::find($id);
17+
18+
if ($image === null) {
19+
return response()->json(['error' => 'Image not found'], 404);
20+
}
21+
22+
$upstream = Http::withHeaders([
23+
'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',
24+
])->get($image->url);
25+
26+
if ($upstream->failed()) {
27+
return response()->json(['error' => 'Failed to fetch image from upstream'], 502);
28+
}
29+
30+
return response($upstream->body(), 200)
31+
->header('Content-Type', $upstream->header('Content-Type'))
32+
->header('Access-Control-Allow-Origin', '*');
33+
}
34+
}

0 commit comments

Comments
 (0)