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,