]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5661 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Jan 2023 17:08:44 +0000 (18:08 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Jan 2023 17:08:44 +0000 (18:08 +0100)
app/Fluidbook/Packager/Download.php
app/Fluidbook/Packager/Packager.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php
resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php

index a57b5f2c7c9785dc0fa45adb25e98f52298679e2..1e98be2f542b36d1642b583ff11438eccd9418bb 100644 (file)
@@ -93,7 +93,6 @@ class Download extends DownloadBase
         }
         $packager = Packager::package($this->entry->id, $this->version, $zip);
         $packager->makePackage($zip);
-        Log::debug($this->action . '/' . $this->entry->id . '/' . $this->version . '/' . get_class($packager) . '///' . $packager->getFinalURL() . '//' . $packager->getFinalPath());
         $url = $packager->getFinalURL();
         if ($url) {
             return $url;
index 27c69b8ea12454246940cbfadaf9bd7c80d979cf..555c4510c7a81b9807442820d118a13b41ca1493 100644 (file)
@@ -185,16 +185,16 @@ class Packager extends \App\Jobs\Base
 
     protected function getBaseFile()
     {
-        return $this->type . '-' . date('Ymdhis', $this->_time) . '-' . $this->escapeTitle();
+        return $this->type . '-' . $this->book_id . '-' . date('Ymdhis', $this->_time) . '-' . $this->escapeTitle();
     }
 
     protected function getDownloadURL($ext = '')
     {
-        $res = '/download/' . $this->getBaseFile();
+        $res = $this->getBaseFile();
         if ($ext != '') {
             $res .= '.' . $ext;
         }
-        return url('packager' . $res);
+        return url('fluidbook-publication/' . $this->book_id . '/download/' . $res);
     }
 
     protected function escapeTitle()
index d95eeb8131669d385167a134d2cd53ec7b23c1b2..6318db3bb4706cb8a88d2cebf773280d20f07abd 100644 (file)
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin\Operations\FluidbookPublication;
 
 use App\Fluidbook\Packager\Download;
 use App\Models\FluidbookPublication;
+use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
 use Illuminate\Support\Facades\Route;
 use Prologue\Alerts\Facades\Alert;
 
@@ -12,7 +13,8 @@ trait DownloadOperation
     protected function setupDownloadRoutes($segment, $routeName, $controller)
     {
         Route::match(['get'], $segment . '/{id}/delivery', $controller . '@delivery');
-        Route::match(['get'], $segment . '/{id}/{action}/{version}', $controller . '@download');
+        Route::match(['get'], $segment . '/{id}/package/{action}/{version}', $controller . '@package');
+        Route::match(['get'], $segment . '/{id}/download/{file}', $controller . '@download');
     }
 
     protected function setupDownloadDefaults()
@@ -27,10 +29,26 @@ trait DownloadOperation
         }
     }
 
+    protected function download($id, $file)
+    {
+        $e = explode('-', $file);
+        if ($e[1] != $id) {
+            abort(404, __('Erreur de correspondance du fichier'));
+        }
+        if (!FluidbookPublication::hasPermission($id)) {
+            abort(401, __('Ce fichier ne peut pas être téléchargée'));
+        }
+        $path = protected_path('fluidbookpublication/packager/download/' . $file);
+        if (!file_exists($path)) {
+            abort(404, __('Le fichier n\'existe pas'));
+        }
+        return XSendFileController::sendfile($path);
+    }
+
     /**
      * @throws \Exception
      */
-    protected function download($id, $action, $version)
+    protected function package($id, $action, $version)
     {
         if (!in_array($action, ['download', 'install_hosting', 'install_ftp', 'scormcloud'])) {
             abort(404, __('Cette action n\'est pas disponible'));
index 4913a9951236fc2a35875b6d47549e7aba588953..6a831304374d15cb5fc1abd0bfa4918fd8883afb 100644 (file)
@@ -1,10 +1,12 @@
 @php
     $allVersions=can('fluidbook-publication:download:all-versions');
+    $base=$crud->route.'/'.$entry->id;
+    $basePackage=$base.'/package';
     $actions=[
         'delivery'=>
             [
                 'label'=>__('Page de téléchargement'),
-                'url'=>$crud->route.'/'.$entry->id.'/delivery',
+                'url'=>$base.'/delivery',
                 ],
         ];
     foreach (\App\Models\FluidbookPublication::getDownloadVersions() as $k=>$v) {
@@ -12,7 +14,7 @@
         if($allVersions || $entry->{'download_'.$k}){
             $actions['download_'.$k]=[
                 'label'=>$v['label'],
-                'url'=>$crud->route.'/'.$entry->id.'/download/'.$k
+                'url'=>$basePackage.'/download/'.$k
                 ];
         }
     }
         $actions['sep_install']='---------';
         $actions['install_hosting']=[
             'label'=>__('Installer sur le serveur d\'hébergement'),
-            'url'=>$crud->route.'/'.$entry->id.'/install_hosting/online',
+            'url'=> $basePackage.'/install_hosting/online',
             ];
 
         $actions['install_ftp']=[
             'label'=>__('Installer sur un serveur FTP'),
-            'url'=>$crud->route.'/'.$entry->id.'/install_ftp/online',
+            'url'=> $basePackage.'/install_ftp/online',
             ];
 
         if($entry->scorm_enable){
             $actions['scormcloud']=['label'=>__('Tester sur SCORM Cloud'),
-            'url'=>$crud->route.'/'.$entry->id.'/scormcloud/scorm'
+            'url'=> $basePackage.'/scormcloud/scorm'
             ];
         }
     }