fix: [문서양식] 미리보기 이미지 MNG API 프록시 경유로 수정 (브라우저→MNG→API→R2)
This commit is contained in:
@@ -927,4 +927,39 @@ private function checkLinkedItemDuplicates(?string $category, array $newItemIds,
|
||||
'errors' => ['linked_items' => $messages],
|
||||
], 422);
|
||||
}
|
||||
|
||||
/**
|
||||
* R2 image_path → presigned URL 프록시 (미리보기용)
|
||||
*/
|
||||
public function presignedUrlByPath(Request $request): JsonResponse
|
||||
{
|
||||
$path = $request->input('path');
|
||||
if (empty($path)) {
|
||||
return response()->json(['url' => null], 400);
|
||||
}
|
||||
|
||||
$baseUrl = config('services.api.base_url', 'https://api.sam.kr');
|
||||
$internalUrl = config('services.api.internal_url');
|
||||
$apiKey = config('services.api.key');
|
||||
|
||||
$headers = [
|
||||
'X-API-KEY' => $apiKey,
|
||||
'X-TENANT-ID' => session('selected_tenant_id', 1),
|
||||
];
|
||||
|
||||
if ($internalUrl) {
|
||||
$headers['Host'] = parse_url($baseUrl, PHP_URL_HOST) ?: 'api.sam.kr';
|
||||
$baseUrl = $internalUrl;
|
||||
}
|
||||
|
||||
$response = Http::baseUrl($baseUrl)
|
||||
->withoutVerifying()
|
||||
->withHeaders($headers)
|
||||
->timeout(10)
|
||||
->post('/api/v1/files/presigned-url-by-path', ['path' => $path]);
|
||||
|
||||
return response()->json([
|
||||
'url' => $response->successful() ? $response->json('data.url') : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user