From 1231ee63024f663eeb4a04107516abfa488bc6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Fri, 20 Mar 2026 12:37:23 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20[document]=20=EA=B2=80=EC=82=AC=20?= =?UTF-8?q?=ED=85=9C=ED=94=8C=EB=A6=BF=20=EC=84=B9=EC=85=98=EC=97=90=20ima?= =?UTF-8?q?ge=5Furl(presigned=20URL)=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DocumentService: 섹션 데이터에 image_url 반환 - QmsLotAuditService: 동일하게 image_url 반환 - file_id 또는 image_path 기반으로 R2 presigned URL 생성 --- app/Services/DocumentService.php | 15 +++++++++++++-- app/Services/QmsLotAuditService.php | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/Services/DocumentService.php b/app/Services/DocumentService.php index bf11cef9..d70b47f2 100644 --- a/app/Services/DocumentService.php +++ b/app/Services/DocumentService.php @@ -977,12 +977,22 @@ public function formatTemplateForReact(DocumentTemplate $template): array 'is_required' => $field->is_required, 'sort_order' => $field->sort_order, ])->toArray(), - 'sections' => $template->sections->map(fn ($section) => [ + 'sections' => $template->sections->map(function ($section) { + $imageUrl = null; + if ($section->file_id) { + $file = \App\Models\Commons\File::withoutGlobalScopes()->find($section->file_id); + $imageUrl = $file?->presignedUrl(); + } elseif ($section->image_path) { + $imageUrl = \Illuminate\Support\Facades\Storage::disk('r2')->temporaryUrl($section->image_path, now()->addMinutes(30)); + } + + return [ 'id' => $section->id, 'name' => $section->title, 'title' => $section->title, 'image_path' => $section->image_path, 'file_id' => $section->file_id, + 'image_url' => $imageUrl, 'sort_order' => $section->sort_order, 'items' => $section->items->map(function ($item) use ($methodCodes) { // method 코드를 한글 이름으로 변환 @@ -1007,7 +1017,8 @@ public function formatTemplateForReact(DocumentTemplate $template): array 'sort_order' => $item->sort_order, ]; })->toArray(), - ])->toArray(), + ]; + })->toArray(), 'columns' => $template->columns->map(fn ($col) => [ 'id' => $col->id, 'label' => $col->label, diff --git a/app/Services/QmsLotAuditService.php b/app/Services/QmsLotAuditService.php index 626ff052..1f08ca25 100644 --- a/app/Services/QmsLotAuditService.php +++ b/app/Services/QmsLotAuditService.php @@ -787,12 +787,23 @@ private function formatFqcTemplate($template): ?array 'is_required' => $f->is_required, 'sort_order' => $f->sort_order, ])->all(), - 'sections' => $template->sections->map(fn ($s) => [ + 'sections' => $template->sections->map(function ($s) { + $imageUrl = null; + if ($s->file_id) { + $file = \App\Models\Commons\File::withoutGlobalScopes()->find($s->file_id); + $imageUrl = $file?->presignedUrl(); + } elseif ($s->image_path) { + $imageUrl = \Illuminate\Support\Facades\Storage::disk('r2')->temporaryUrl($s->image_path, now()->addMinutes(30)); + } + + return [ 'id' => $s->id, 'name' => $s->name, 'title' => $s->title, 'description' => $s->description, 'image_path' => $s->image_path, + 'file_id' => $s->file_id, + 'image_url' => $imageUrl, 'sort_order' => $s->sort_order, 'items' => $s->items->map(fn ($i) => [ 'id' => $i->id, @@ -806,7 +817,8 @@ private function formatFqcTemplate($template): ?array 'category' => $i->category, 'method' => $i->method, ])->all(), - ])->all(), + ]; + })->all(), 'columns' => $template->columns->map(fn ($c) => [ 'id' => $c->id, 'label' => $c->label,