From 05cf72b43782f2183a77f2aec0928be3298ac0a3 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 18 Oct 2023 09:31:44 +0200 Subject: [PATCH] wip #6407 @1.5 --- app/Fluidbook/Packager/Download.php | 16 +++++++-- .../API/FluidbookPublicationAPIController.php | 36 +++++++++++++++++++ routes/api.php | 3 ++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/API/FluidbookPublicationAPIController.php diff --git a/app/Fluidbook/Packager/Download.php b/app/Fluidbook/Packager/Download.php index 917532055..c9b1ef2c1 100644 --- a/app/Fluidbook/Packager/Download.php +++ b/app/Fluidbook/Packager/Download.php @@ -82,8 +82,14 @@ class Download extends DownloadBase } public function handle() + { + $this->package(); + } + + public function package($notify = true) { App::setLocale($this->user->preferredLocale()); + $res = []; try { $url = $this->_compileandpackage(); $translateVariables = ['title' => $this->_title(), 'nb' => $this->_id()]; @@ -94,11 +100,13 @@ class Download extends DownloadBase $actions = []; if ($this->action === 'download' || $this->action === 'scormcloud') { $actions = ['Télécharger' => $url]; + $res[] = $url; if ($this->action === 'scormcloud') { try { $scormURL = ScormCloud::send($url, 'toolbox_' . $this->type . '_' . $this->_id()); $actions[__('Tester sur SCORM Cloud')] = $scormURL; + $res[] = $url; } catch (\Exception $e) { } @@ -128,7 +136,7 @@ class Download extends DownloadBase if (null !== $url) { $actions = [__('Voir sur :server', ['server' => $server->name]) => $url]; } - + $res[] = $url; } else if ($this->action === 'loadbalancer') { $path = $this->_compileandpackage(false); $dest = protected_path('fluidbookpublication/loadbalancer/' . $this->entry->id . '_' . $this->entry->hash . '/'); @@ -148,10 +156,12 @@ class Download extends DownloadBase Log::error($e); } - $this->sendNotification($subject, $text, $actions, $showTextIfNotEmail); + if ($notify) { + $this->sendNotification($subject, $text, $actions, $showTextIfNotEmail); + } + return $res; } - protected function _compileandpackage($zip = true) { if ($this->entry->version == 3) { diff --git a/app/Http/Controllers/API/FluidbookPublicationAPIController.php b/app/Http/Controllers/API/FluidbookPublicationAPIController.php new file mode 100644 index 000000000..5f7a86477 --- /dev/null +++ b/app/Http/Controllers/API/FluidbookPublicationAPIController.php @@ -0,0 +1,36 @@ +user()); + $url = $download->package(false); + if (count($url)) { + return $url[0]; + } + return false; + } + + public function metadata($id) + { + if (!FluidbookPublication::hasPermission($id, 'read')) { + abort(401); + } + $fluidbook = FluidbookPublication::find($id); + return ['title' => $fluidbook->title, + 'lang' => $fluidbook->locale, + 'locale' => $fluidbook->locale, + 'date' => (new \DateTime($fluidbook->updated_at))->getTimestamp()]; + } +} diff --git a/routes/api.php b/routes/api.php index 986a5ec3d..a5095dc17 100644 --- a/routes/api.php +++ b/routes/api.php @@ -17,6 +17,9 @@ Route::group([ 'middleware' => ['auth:api'], 'excluded_middleware' => ['verifycsrftoken'] ], function () { + Route::get('fluidbook-publication/{id}/download/{version}', [\App\Http\Controllers\API\FluidbookPublicationAPIController::class, 'download']); + Route::get('fluidbook-publication/{id}/metadata', [\App\Http\Controllers\API\FluidbookPublicationAPIController::class, 'metadata']); + Route::post('fluidbook-theme/{id}/clone', [\App\Http\Controllers\API\FluidbookThemeAPIController::class, 'clonefromws2']); Route::put('fluidbook-theme/{id}', [\App\Http\Controllers\API\FluidbookThemeAPIController::class, 'updatefromws2']); Route::put('fluidbook-theme/{id}/rename', [\App\Http\Controllers\API\FluidbookThemeAPIController::class, 'renamefromws2']); -- 2.39.5