]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6563 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 8 Dec 2023 11:36:10 +0000 (12:36 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 8 Dec 2023 11:36:10 +0000 (12:36 +0100)
app/Http/Controllers/Admin/Operations/FluidbookCollection/DownloadOperation.php
app/Jobs/DownloadBase.php

index 21f4cfa5ee9da4473b4707eecc35db4b5519c167..8f2702c626ef075e7b9ce4ebd4e1602e136a09dc 100644 (file)
@@ -15,8 +15,9 @@ trait DownloadOperation
 {
     protected function setupDownloadRoutes($segment, $routeName, $controller)
     {
-        Route::match(['get'], $segment . '/{id}/download/{action}', $controller . '@download');
-        Route::match(['get'], $segment . '/{id}/downloadfile/{rand}/{path}', $controller . '@downloadFile')->withoutMiddleware([CheckIfAdmin::class]);
+
+        Route::match(['get'], $segment . '/{id}_{hash}/download/{file}', $controller . '@downloadFile')->withoutMiddleware([CheckIfAdmin::class]);;
+        Route::match(['get'], $segment . '/{id}/download/{action}', $controller . '@download')->whereNumber('id');
     }
 
     protected function setupDownloadDefaults()
@@ -39,9 +40,20 @@ trait DownloadOperation
         return redirect(backpack_url('fluidbook-collection'));
     }
 
-    protected function downloadFile($id, $rand, $path)
+    protected function downloadFile($id, $hash, $file)
     {
-        $file = protected_path('fluidbookcollection/final/' . $id . '/' . $rand . '/' . $path);
-        return XSendFileController::sendfile($file);
+        $e = explode('-', $file);
+        if ($e[1] != $id) {
+            abort(404, __('Erreur de correspondance du fichier'));
+        }
+        $collection = FluidbookCollection::where('id', $id)->where('hash', $hash)->first();
+        if (null === $collection) {
+            abort(404, __('Ce fichier est indisponible'));
+        }
+        $path = protected_path('fluidbookcollection/download/' . $id . '/' . $file);
+        if (!file_exists($path)) {
+            abort(404, __('Le fichier n\'existe pas'));
+        }
+        return XSendFileController::sendfile($path);
     }
 }
index da61686fa6257c521538a6061bffaf02f738db1d..ff8767393778b7d8c5bd0e2de2f730303e6b539a 100644 (file)
@@ -91,18 +91,18 @@ class DownloadBase extends Base
         if (null === $title) {
             $title = $this->_title();
         }
-        return Str::slugCase($this->getType() . '-' . date('Ymdhis') . '-' . md5(rand(10000, 100000000)) . '-' . Str::slug($title)) . '.' . $extension;
+        return Str::slugCase($this->getType() . '-' . $this->entry->id . '-' . date('Ymdhis') . '-' . Str::slug($title)) . '.' . $extension;
     }
 
 
     protected function _dest($fname)
     {
-        return Files::mkdir(protected_path($this->getBaseURL() . '/download/' . $this->entry->id . '/')) . $fname;
+        return Files::mkdir(protected_path($this->getType() . '/download/' . $this->entry->id . '/')) . $fname;
     }
 
     protected function _url($fname)
     {
-        return url('/' . $this->getBaseURL() . '/' . $this->entry->id . '_' . $this->entry->hash . '/download/' . $fname);
+        return url('/' . $this->getBaseURL() . '/' . $this->entry->id . '_' . $this->entry->hash . '/' . $fname);
     }
 
     protected function _title()
@@ -156,7 +156,7 @@ class DownloadBase extends Base
         $compilepath = $this->_compile();
         echo 'Compiled : ' . $compilepath . "\n";
         $fname = $this->_fname();
-        $dest = Files::mkdir(protected_path($this->getBaseURL() . '/download/' . $this->entry->id . '/')) . $fname;
+        $dest = $this->_dest($fname);
         echo 'Zip to ' . $dest . "\n";
         Zip::archive($compilepath, $dest);
         if (!file_exists($dest)) {
@@ -169,7 +169,7 @@ class DownloadBase extends Base
     protected function _compile()
     {
         $compilepath = $this->entry->getFinalPath();
-        echo 'Compile to '.$compilepath."\n";
+        echo 'Compile to ' . $compilepath . "\n";
         $this->entry->compile($compilepath);
         return $compilepath;
     }