Display CMS: Upload-Fehler abfangen und kaputte Bilder im Player überspringen.
Mediathek-Uploads legen keinen Datensatz mehr an, wenn der Datei-Write fehlschlägt (verhindert 404-Einträge auf den Displays). Der Player überspringt Bilder mit Ladefehler nach 2s statt Schwarzbild zu zeigen. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
2a34adc515
commit
193d37b1ce
6 changed files with 211 additions and 62 deletions
|
|
@ -69,8 +69,15 @@ class DisplayMediaPicker extends Component
|
|||
$service = app(DisplayMediaService::class);
|
||||
$lastMedia = null;
|
||||
|
||||
foreach ($this->quickUploads as $file) {
|
||||
$lastMedia = $service->storeUpload($file);
|
||||
try {
|
||||
foreach ($this->quickUploads as $file) {
|
||||
$lastMedia = $service->storeUpload($file);
|
||||
}
|
||||
} catch (\RuntimeException $exception) {
|
||||
$this->quickUploads = [];
|
||||
$this->addError('quickUploads', $exception->getMessage());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->quickUploads = [];
|
||||
|
|
|
|||
|
|
@ -7,12 +7,15 @@ use Illuminate\Http\UploadedFile;
|
|||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class DisplayMediaService
|
||||
{
|
||||
/**
|
||||
* Store an uploaded file and create a DisplayMedia record.
|
||||
*
|
||||
* @throws RuntimeException When the file cannot be written to storage.
|
||||
*/
|
||||
public function storeUpload(UploadedFile $file, ?string $collection = null): DisplayMedia
|
||||
{
|
||||
|
|
@ -22,7 +25,11 @@ class DisplayMediaService
|
|||
$datePath = now()->format('Y/m');
|
||||
$relativePath = "display-media/{$datePath}/{$storageName}";
|
||||
|
||||
Storage::disk('public')->putFileAs("display-media/{$datePath}", $file, $storageName);
|
||||
$storedPath = Storage::disk('public')->putFileAs("display-media/{$datePath}", $file, $storageName);
|
||||
|
||||
if ($storedPath === false || ! Storage::disk('public')->exists($relativePath)) {
|
||||
throw new RuntimeException("Die Datei \"{$filename}\" konnte nicht im Storage gespeichert werden. Bitte Schreibrechte und Speicherplatz prüfen.");
|
||||
}
|
||||
|
||||
$type = in_array($extension, ['mp4', 'webm', 'mov']) ? 'video' : 'image';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue