From ee30c0a2496a437c2662a9220fafa1cc01db7a3f Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 29 Mar 2022 14:51:30 +0200 Subject: [PATCH] wip #5184 @0.25 --- app/Http/Controllers/FrontController.php | 41 +++++++++++++----------- app/Jobs/ProducePackage.php | 3 -- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index 1636c68..4b89945 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -11,6 +11,7 @@ use App\Models\Settings; use Cubist\Backpack\Magic\PageData; use Cubist\Util\Files\Files; use FFMpeg\FFProbe; +use Illuminate\Support\Facades\Cache; use SplFileInfo; class FrontController extends Controller @@ -89,35 +90,37 @@ class FrontController extends Controller 'audio' => 'Podcast', ]; - $media=[]; + $media = []; $ffprobe = FFProbe::create(); foreach ($res['medialibrary']['assets'] as $a) { /** @var $a \Cubist\Backpack\Magic\PageData */ - $file=$a->getMediaPathsByCollection($a->get('file_upload'))[0]??null; - if(null===$file){ + $file = $a->getMediaPathsByCollection($a->get('file_upload'))[0] ?? null; + if (null === $file) { continue; } - $spf=new SplFileInfo($file); - $ext=mb_strtolower($spf->getExtension()); - if(in_array($ext,['pdf','jpg','jpeg','gif','png'])){ + $spf = new SplFileInfo($file); + $ext = mb_strtolower($spf->getExtension()); + if (in_array($ext, ['pdf', 'jpg', 'jpeg', 'gif', 'png'])) { continue; } - $map=['mp3'=>'audio','mp4'=>'video']; - $type=$map[$ext]??$a->get('type'); - - $media[$a['id']]=[ - 'id'=>$a->get('id'), - 'type'=>$type, - 'theme'=>$a->get('theme'), - 'code'=>$a->get('code'), - 'title'=>$a->get('title'), - 'file'=>$a->getImageURLbyCollection($a->get('file_upload')), - 'image'=>$a->getImageURLbyCollection($a->get('file_thumb'))??$a->getImageURLbyCollection($a->get('file_upload'),'poster'), - 'duration'=>$ffprobe->format($file)->get('duration') + $map = ['mp3' => 'audio', 'mp4' => 'video']; + $type = $map[$ext] ?? $a->get('type'); + + $media[$a['id']] = [ + 'id' => $a->get('id'), + 'type' => $type, + 'theme' => $a->get('theme'), + 'code' => $a->get('code'), + 'title' => $a->get('title'), + 'file' => $a->getImageURLbyCollection($a->get('file_upload')), + 'image' => $a->getImageURLbyCollection($a->get('file_thumb')) ?? $a->getImageURLbyCollection($a->get('file_upload'), 'poster'), + 'duration' => Cache::get('media_duration_' . Files::hashFileAttributes($file), function () use ($ffprobe, $file) { + return $ffprobe->format($file)->get('duration'); + }) ]; } - $res['media']=$media; + $res['media'] = $media; return $res; } diff --git a/app/Jobs/ProducePackage.php b/app/Jobs/ProducePackage.php index 17773d8..adfbe82 100644 --- a/app/Jobs/ProducePackage.php +++ b/app/Jobs/ProducePackage.php @@ -35,9 +35,6 @@ class ProducePackage implements ShouldQueue, ShouldBeUnique $this->vdir = new VirtualDirectory($this->dir); $zipfile = $this->dir . '.zip'; - if (file_exists($zipfile)) { - unlink($zipfile); - } self::precomile(); $this->vdir->copyDirectory(storage_path('fluidbook/out'), 'coeur'); -- 2.39.5