]> _ Git - odl.git/commitdiff
wip #5184 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 29 Mar 2022 12:51:30 +0000 (14:51 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 29 Mar 2022 12:51:30 +0000 (14:51 +0200)
app/Http/Controllers/FrontController.php
app/Jobs/ProducePackage.php

index 1636c680bbc1338816cfedb13e5fe2657c445be7..4b89945e515e44060104a3fa79ba6a82ede7f15a 100644 (file)
@@ -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;
     }
index 17773d8912176f59df2a4cec6d54c12ee836271b..adfbe8271c7fce3dfbc3a7b6949f6409792a26db 100644 (file)
@@ -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');