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:
Kevin Adametz 2026-07-07 08:57:31 +00:00
parent 2a34adc515
commit 193d37b1ce
6 changed files with 211 additions and 62 deletions

View file

@ -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';