]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7454 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 8 Apr 2025 08:43:07 +0000 (10:43 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 8 Apr 2025 08:43:07 +0000 (10:43 +0200)
app/Fluidbook/Packager/Download.php
app/Http/Controllers/API/FluidbookPublicationAPIController.php
app/Jobs/FluidbookEasyCreation.php
app/Models/FluidbookPublication.php

index 954a327222893fab19f3cdf9f8d565aaa27f1f41..a4cb226941dae60646ab7eaf7653059008626c09 100644 (file)
@@ -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 */
index 31022420d247e5f2bb02e1482bfdda801a2d3ebd..554a569a855bc6800841406109771db84fbf5f6f 100644 (file)
@@ -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);
index ff4be11bbdd25910215bab5fa5fc5f2e8829228c..8d5133100fd75229fc26ae05915c0ee17495e09f 100644 (file)
@@ -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;
index 3c155437fed823a4e709896287721bad8448fee3..15f44b7a158e336a9838ce706d750f21cdf794cc 100644 (file)
@@ -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
     {