From bd5313861681f8dbe5495543ccf7ca994bf664dd Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 8 Apr 2025 10:43:07 +0200 Subject: [PATCH] wip #7454 @2 --- app/Fluidbook/Packager/Download.php | 6 ++++-- .../API/FluidbookPublicationAPIController.php | 21 ++++++++----------- app/Jobs/FluidbookEasyCreation.php | 11 +++++++++- app/Models/FluidbookPublication.php | 13 ++++++++++++ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/app/Fluidbook/Packager/Download.php b/app/Fluidbook/Packager/Download.php index 954a32722..a4cb22694 100644 --- a/app/Fluidbook/Packager/Download.php +++ b/app/Fluidbook/Packager/Download.php @@ -90,7 +90,9 @@ class Download extends DownloadBase public function package($notify = true) { - App::setLocale($this->user->preferredLocale()); + //if (null !== $this->user) { + App::setLocale($this->user->preferredLocale()); + //} $res = []; // try { $url = $this->_compileandpackage(); @@ -116,7 +118,7 @@ class Download extends DownloadBase } } } else if ($this->action === 'install') { - echo 'Install on ' . json_encode($this->entry->install_online) . "\n"; + //echo 'Install on ' . json_encode($this->entry->install_online) . "\n"; $s = $this->entry->install_online; $dest = Driver::cleanInstallDir($s['path']); /** @var FluidbookExternalInstallServer $server */ diff --git a/app/Http/Controllers/API/FluidbookPublicationAPIController.php b/app/Http/Controllers/API/FluidbookPublicationAPIController.php index 31022420d..554a569a8 100644 --- a/app/Http/Controllers/API/FluidbookPublicationAPIController.php +++ b/app/Http/Controllers/API/FluidbookPublicationAPIController.php @@ -16,12 +16,10 @@ class FluidbookPublicationAPIController extends Controller if (!FluidbookPublication::hasPermission($id, 'read')) { abort(401); } - $download = new Download(FluidbookPublication::find($id), $version, $action, auth()->user()); - $url = $download->package(false); - if (count($url)) { - return $url[0]; - } - return false; + $fluidbook = FluidbookPublication::find($id); + $download = new Download($fluidbook, $version, $action, auth()->user()); + $download->package(false); + return $this->metadata($fluidbook); } public function metadata($fluidbook) @@ -33,13 +31,13 @@ class FluidbookPublicationAPIController extends Controller abort(401); } - return [ + return response()->json([ 'id' => $fluidbook->id, 'reference' => $fluidbook->reference, 'title' => $fluidbook->title, 'lang' => $fluidbook->locale, 'locale' => $fluidbook->locale, - 'date' => (new \DateTime($fluidbook->updated_at))->getTimestamp()]; + 'date' => (new \DateTime($fluidbook->updated_at))->getTimestamp()]); } public function create() @@ -47,12 +45,11 @@ class FluidbookPublicationAPIController extends Controller if (!can('fluidbook-publication:write')) { abort(401); } - - $job = new FluidbookEasyCreation(request('base'), Files::move_uploaded_file(request()->file('file')), request('title'), request('export'), backpack_user(), request('notify', false)); - return $job->handle(); + $job = new FluidbookEasyCreation(request('base'), Files::move_uploaded_file(request()->file('file')), request('title'), request('export'), json_decode(request('attributes', '[]')), auth()->user(), request('notify', false)); + return $this->metadata($job->handle()['fluidbook']); } - public function findByReference($reference): ?array + public function findByReference($reference) { if ($fluidbook = FluidbookPublication::where('reference', $reference)->first()) { return $this->metadata($fluidbook); diff --git a/app/Jobs/FluidbookEasyCreation.php b/app/Jobs/FluidbookEasyCreation.php index ff4be11bb..8d5133100 100644 --- a/app/Jobs/FluidbookEasyCreation.php +++ b/app/Jobs/FluidbookEasyCreation.php @@ -29,13 +29,18 @@ class FluidbookEasyCreation extends \App\Jobs\Tools\Base */ protected $export; + /** + * @var array + */ + protected $attributes = []; + /** * @var bool */ protected $notify = false; - public function __construct($base, $file, $title, $export, $user = null, $notify = false) + public function __construct($base, $file, $title, $export, $attributes = [], $user = null, $notify = false) { parent::__construct(); @@ -43,6 +48,7 @@ class FluidbookEasyCreation extends \App\Jobs\Tools\Base $this->base = $base; $this->title = $title; $this->export = $export; + $this->attributes = $attributes; $this->user = $user ?? backpack_user(); $this->notify = $notify; } @@ -54,6 +60,9 @@ class FluidbookEasyCreation extends \App\Jobs\Tools\Base $fluidbook = $base->replicateSettings(); $fluidbook->setOwner($base->owner); $fluidbook->title = $this->title; + foreach ($this->attributes as $k => $v) { + $fluidbook->setAttribute($k, $v); + } $install = false; if ($this->export['server']) { $install = true; diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index 3c155437f..15f44b7a1 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -333,6 +333,19 @@ class FluidbookPublication extends ToolboxStatusModel $this->install_online = $o; } + public function getOnlineURL() + { + $this->checkExternalServers(); + if (!$this->install_online->server) { + return null; + } + $servers = \App\Models\FluidbookExternalInstallServer::getAllServers(); + $server = $servers[$this->install_online->server]; + if (!$this->install_online->path && !$server['allows_root']) { + return null; + } + return $server['base_url'] . $this->install_online->path; + } public function onSaved(): bool { -- 2.39.5