42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use Illuminate\Support\Facades\Http;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* R2 파일 프록시 (MNG 세션 인증으로 API 파일 스트리밍)
|
||
|
|
*
|
||
|
|
* MNG는 Blade(서버사이드)이므로 API의 /files/{id}/view를 직접 호출 시
|
||
|
|
* sanctum 인증 문제가 발생. MNG 세션 인증으로 API를 프록시하여 파일 스트리밍.
|
||
|
|
*/
|
||
|
|
class FileViewController extends Controller
|
||
|
|
{
|
||
|
|
public function show(int $id)
|
||
|
|
{
|
||
|
|
$baseUrl = config('services.api.base_url', 'https://api.sam.kr');
|
||
|
|
$apiKey = config('services.api.key') ?: '42Jfwc6EaRQ04GNRmLR5kzJp5UudSOzGGqjmdk1a';
|
||
|
|
$token = session('api_access_token', '');
|
||
|
|
|
||
|
|
$response = Http::baseUrl($baseUrl)
|
||
|
|
->withoutVerifying()
|
||
|
|
->withHeaders([
|
||
|
|
'X-API-KEY' => $apiKey,
|
||
|
|
'X-TENANT-ID' => 287, // TODO: session('selected_tenant_id', 1) 로 복원
|
||
|
|
])
|
||
|
|
->withToken($token)
|
||
|
|
->timeout(15)
|
||
|
|
->get("/api/v1/files/{$id}/view");
|
||
|
|
|
||
|
|
if (! $response->successful()) {
|
||
|
|
abort(404);
|
||
|
|
}
|
||
|
|
|
||
|
|
return response($response->body(), 200, [
|
||
|
|
'Content-Type' => $response->header('Content-Type', 'image/png'),
|
||
|
|
'Content-Disposition' => 'inline',
|
||
|
|
'Cache-Control' => 'private, max-age=3600',
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|