Feat: Moving File Handling To Core

This commit is contained in:
2026-09-25 13:47:58 +03:00
parent 540da1af24
commit a51e9456d6
11 changed files with 134 additions and 218 deletions
@@ -2,10 +2,12 @@
@include('checkout::partials.line-custom-fields', ['line' => $line])
A cart or order line's custom-field answers (meta.custom_fields, written by
CartController::customFieldsMeta()) — label/value pairs. A file answer links
to the file through a temporary signed URL (CustomFieldFileController),
minted fresh on every render, with a thumbnail when the browser can display
the format (HEIC can't be shown outside Safari, so it gets the name only).
CartController::customFieldsMeta()). A file answer only carries a File id
(Modules\Core\File\Models\File is the source of truth for name/mime/disk/
path — never duplicated into meta), resolved here and linked through
boboko-core's own signed download route (files.download), minted fresh on
every render, with a thumbnail when the browser can display the format
(HEIC can't be shown outside Safari, so it gets the name only).
--}}
@php
$fields = $line->meta['custom_fields'] ?? [];
@@ -20,18 +22,23 @@
<dd>
@if ($field['type'] === 'file')
@php
$fileUrl = \Illuminate\Support\Facades\URL::temporarySignedRoute(
'checkout.custom-field-file',
now()->addHours(2),
['locale' => app()->getLocale(), 'disk' => $field['disk'], 'path' => $field['path']],
);
$file = \Modules\Core\File\Models\File::find($field['file_id'] ?? null);
@endphp
<a href="{{ $fileUrl }}" class="bbk-line-field-file" target="_blank" rel="noopener">
@if (in_array($field['mime'] ?? null, $previewable, true))
<img src="{{ $fileUrl }}" alt="" width="40" height="40" loading="lazy">
@endif
<span>{{ $field['value'] }}</span>
</a>
@if ($file)
@php
$fileUrl = \Illuminate\Support\Facades\URL::temporarySignedRoute(
'files.download',
now()->addHours(2),
['file' => $file->id],
);
@endphp
<a href="{{ $fileUrl }}" class="bbk-line-field-file" target="_blank" rel="noopener">
@if (in_array($file->mime, $previewable, true))
<img src="{{ $fileUrl }}" alt="" width="40" height="40" loading="lazy">
@endif
<span>{{ $file->original_name }}</span>
</a>
@endif
@else
{{ $field['value'] }}
@endif
@@ -6,10 +6,11 @@
custom_fields[key]. text → input, textarea → textarea, file → photo upload.
A photo is uploaded as soon as it's picked (custom-field-upload-controller.js)
and only the returned reference is submitted with the form — the file input
itself has no name. It still carries `required`, so the browser's own
validation blocks add-to-cart until a photo is picked, and the controller
marks it invalid (setCustomValidity) while the upload is in flight.
and only the resulting File row's id (boboko-core's Modules\Core\File\
Models\File) is submitted with the form — the file input itself has no
name. It still carries `required`, so the browser's own validation blocks
add-to-cart until a photo is picked, and the controller marks it invalid
(setCustomValidity) while the upload is in flight.
--}}
@props(['fields' => []])