From 6143e03b438cdd2559add16d39afe0ce87ea9f5e Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 19 Jan 2023 18:08:44 +0100 Subject: [PATCH] wip #5661 @4 --- app/Fluidbook/Packager/Download.php | 1 - app/Fluidbook/Packager/Packager.php | 6 ++--- .../DownloadOperation.php | 22 +++++++++++++++++-- .../fluidbook_publication/download.blade.php | 12 +++++----- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/Fluidbook/Packager/Download.php b/app/Fluidbook/Packager/Download.php index a57b5f2c7..1e98be2f5 100644 --- a/app/Fluidbook/Packager/Download.php +++ b/app/Fluidbook/Packager/Download.php @@ -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; diff --git a/app/Fluidbook/Packager/Packager.php b/app/Fluidbook/Packager/Packager.php index 27c69b8ea..555c4510c 100644 --- a/app/Fluidbook/Packager/Packager.php +++ b/app/Fluidbook/Packager/Packager.php @@ -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() diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php index d95eeb813..6318db3bb 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php @@ -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')); diff --git a/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php b/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php index 4913a9951..6a8313043 100644 --- a/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php +++ b/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php @@ -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 ]; } } @@ -20,17 +22,17 @@ $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' ]; } } -- 2.39.5