feat: [document] 문서양식/문서 이미지를 R2 presigned URL로 전환
- 업로드 응답에 image_url 추가 - prepareTemplateData에서 file_id/image_path 기반 presigned URL 발급 - edit/preview에서 image_url 우선 사용 - show/print에서 api.sam.kr 하드코딩 제거
This commit is contained in:
@@ -130,6 +130,47 @@ public function blockEdit(int $id): View
|
||||
/**
|
||||
* 현재 선택된 테넌트 조회
|
||||
*/
|
||||
/**
|
||||
* API에서 presigned URL 발급
|
||||
*/
|
||||
private function getPresignedUrlFromApi(int $fileId): ?string
|
||||
{
|
||||
$baseUrl = config('services.api.base_url', 'https://api.sam.kr');
|
||||
$apiKey = config('services.api.key');
|
||||
$token = session('api_access_token', '');
|
||||
|
||||
$response = \Illuminate\Support\Facades\Http::baseUrl($baseUrl)
|
||||
->withoutVerifying()
|
||||
->withHeaders([
|
||||
'X-API-KEY' => $apiKey,
|
||||
'X-TENANT-ID' => session('selected_tenant_id', 1),
|
||||
])
|
||||
->withToken($token)
|
||||
->timeout(10)
|
||||
->get("/api/v1/files/{$fileId}/presigned-url");
|
||||
|
||||
return $response->successful() ? $response->json('data.url') : null;
|
||||
}
|
||||
|
||||
private function getPresignedUrlByPath(string $path): ?string
|
||||
{
|
||||
$baseUrl = config('services.api.base_url', 'https://api.sam.kr');
|
||||
$apiKey = config('services.api.key');
|
||||
$token = session('api_access_token', '');
|
||||
|
||||
$response = \Illuminate\Support\Facades\Http::baseUrl($baseUrl)
|
||||
->withoutVerifying()
|
||||
->withHeaders([
|
||||
'X-API-KEY' => $apiKey,
|
||||
'X-TENANT-ID' => session('selected_tenant_id', 1),
|
||||
])
|
||||
->withToken($token)
|
||||
->timeout(10)
|
||||
->post('/api/v1/files/presigned-url-by-path', ['path' => $path]);
|
||||
|
||||
return $response->successful() ? $response->json('data.url') : null;
|
||||
}
|
||||
|
||||
private function getCurrentTenant(): ?Tenant
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
@@ -244,10 +285,19 @@ private function prepareTemplateData(DocumentTemplate $template): array
|
||||
];
|
||||
})->toArray(),
|
||||
'sections' => $template->sections->map(function ($s) {
|
||||
$imageUrl = null;
|
||||
if ($s->file_id) {
|
||||
$imageUrl = $this->getPresignedUrlFromApi($s->file_id);
|
||||
} elseif ($s->image_path) {
|
||||
$imageUrl = $this->getPresignedUrlByPath($s->image_path);
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $s->id,
|
||||
'title' => $s->title,
|
||||
'image_path' => $s->image_path,
|
||||
'file_id' => $s->file_id,
|
||||
'image_url' => $imageUrl,
|
||||
'items' => $s->items->map(function ($i) {
|
||||
$fv = $i->field_values ?? [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user