]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7062 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 5 Sep 2024 14:40:03 +0000 (16:40 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 5 Sep 2024 14:40:03 +0000 (16:40 +0200)
app/Http/Controllers/API/FluidbookPublicationAPIController.php
app/Http/Controllers/API/FluidbookThemeAPIController.php [deleted file]
app/Jobs/FluidbookEasyCreation.php
routes/api.php

index 5f7a864770c1bc32aaa8523dc449cc4e8884cf7b..7157607527f9a9bc879b5ff027dab31f788b3c7c 100644 (file)
@@ -4,8 +4,10 @@ namespace App\Http\Controllers\API;
 
 use App\Fluidbook\Packager\Download;
 use App\Http\Controllers\Controller;
+use App\Jobs\FluidbookEasyCreation;
 use App\Models\FluidbookPublication;
 use App\Models\User;
+use Cubist\Util\Files\Files;
 
 class FluidbookPublicationAPIController extends Controller
 {
@@ -33,4 +35,15 @@ class FluidbookPublicationAPIController extends Controller
             'locale' => $fluidbook->locale,
             'date' => (new \DateTime($fluidbook->updated_at))->getTimestamp()];
     }
+
+    public function create()
+    {
+        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();
+    }
+
 }
diff --git a/app/Http/Controllers/API/FluidbookThemeAPIController.php b/app/Http/Controllers/API/FluidbookThemeAPIController.php
deleted file mode 100644 (file)
index 3506997..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-<?php
-
-
-namespace App\Http\Controllers\API;
-
-
-use App\Http\Controllers\Controller;
-use App\Models\FluidbookTheme;
-use Cubist\Backpack\Magic\Fields\Checkbox;
-use Cubist\Backpack\Magic\Fields\Color;
-use Cubist\Backpack\Magic\Fields\Files;
-use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Auth;
-
-class FluidbookThemeAPIController extends Controller
-{
-
-    /**
-     * @param $theme FluidbookTheme
-     * @param $data array
-     * @return FluidbookTheme
-     */
-    public static function _prepareData($theme, $data)
-    {
-        $map = ['theme_id' => 'id', 'proprietaire' => 'owner', 'nom' => 'name'];
-        foreach ($data as $k => $v) {
-            if (isset($map[$k])) {
-                $k = $map[$k];
-            }
-            if (!$theme->hasField($k)) {
-                continue;
-            }
-            $field = $theme->getField($k);
-            if ($field instanceof Checkbox) {
-                if ($v === 'true' || $v == 1) {
-                    $v = 1;
-                } else if ($v == 0 || $v === 'false' || !$v) {
-                    $v = 0;
-                }
-            } else if ($field instanceof Color) {
-                if ($v === '' && $field->getAttribute('allows_empty')) {
-
-                } else {
-                    $v = FluidbookTheme::_colorToWS3($v);
-                }
-            } else if ($field instanceof Files) {
-                continue;
-            }
-            $theme->setAttribute($k, $v);
-        }
-        return $theme;
-    }
-
-    /**
-     * @param $theme FluidbookTheme
-     * @param $data array
-     * @return FluidbookTheme
-     */
-    public static function _handleFiles($theme, $data)
-    {
-        // $oldRoot = '/home/extranet/www/fluidbook/themes/' . $theme->getAttribute('id') . '/';
-        foreach ($theme->getFields() as $field) {
-            if (!($field instanceof Files)) {
-                continue;
-            }
-            $k = $field->getName();
-            $v = $data[$k] ?? null;
-
-            if (!$v) {
-                $theme->deleteMediaInField($k);
-                //continue;
-            }
-//            $path = $oldRoot . $v;
-//            if (!file_exists($path)) {
-//                $opath = str_replace('.svg', '.o.svg', $path);
-//                if (file_exists($opath)) {
-//                    copy($opath, $path);
-//                } else {
-//                    continue;
-//                }
-//            }
-//
-//            $media = $theme->getMediaInField($k);
-//            $upload = false;
-//
-//            if ($media->count() === 0) {
-//                $upload = true;
-//            } else {
-//                /** @var Media $m */
-//                $m = $media->get(0);
-//
-//                if ($m->getAttribute('file_name') !== $k) {
-//                    $upload = true;
-//                } else {
-//                    $mpath = $m->getPath();
-//                    if (filesize($path) !== filesize($mpath)) {
-//                        $upload = true;
-//                    }
-//                }
-//            }
-//
-//            if (!$upload) {
-//                continue;
-//            }
-//            $s = storage_path('themes/' . $theme->getAttribute('id'));
-//            if (!file_exists($s)) {
-//                mkdir($s);
-//            }
-//            $f = $s . '/' . $v;
-//            copy($path, $f);
-//            $theme->addMediaToField($k, $f);
-        }
-    }
-
-
-    /**
-     * Update the specified resource in storage.
-     *
-     * @param \Illuminate\Http\Request $request
-     * @param int $id
-     * @return \Illuminate\Http\Response
-     */
-    public function updatefromws2(Request $request, $id)
-    {
-        FluidbookTheme::$updateWS2SyncViewOnChange = true;
-        $theme = FluidbookTheme::find($id);
-        self::_prepareData($theme, $request->get('data'));
-        $theme->save();
-        self::_handleFiles($theme, $request->get('data'));
-    }
-
-    public function clonefromws2(Request $request, $id)
-    {
-        FluidbookTheme::$updateWS2SyncViewOnChange = true;
-        $theme = FluidbookTheme::find($id);
-        $newtheme = $theme->replicate();
-        $newtheme->name .= ' (copy)';
-        $newtheme->owner = Auth::id();
-        $newtheme->push();
-
-        return $newtheme->id;
-    }
-
-    public function renamefromws2(Request $request, $id)
-    {
-        FluidbookTheme::$updateWS2SyncViewOnChange = true;
-        $theme = FluidbookTheme::find($id);
-        $theme->name = $request->get('newname');
-        $theme->save();
-    }
-
-    public function deletefromws2(Request $request, $id)
-    {
-        FluidbookTheme::$updateWS2SyncViewOnChange = true;
-        /** @var FluidbookTheme $theme */
-        $theme = FluidbookTheme::find($id);
-        $theme->delete();
-    }
-
-    public function uploadfile(Request $request, $id, $fieldname)
-    {
-        FluidbookTheme::$updateWS2SyncViewOnChange = true;
-        /** @var FluidbookTheme $theme */
-        $theme = FluidbookTheme::find($id);
-        $theme->replaceMediaInField($fieldname, $request->get('path'), true);
-        $theme->save();
-    }
-}
index a78cdcf8f0f4b97efceef6b5544454101193cff5..ff4be11bbdd25910215bab5fa5fc5f2e8829228c 100644 (file)
@@ -74,6 +74,8 @@ class FluidbookEasyCreation extends \App\Jobs\Tools\Base
         $fluidbook->save();
 
         $download = new Download($fluidbook, 'online', $install ? 'install' : 'download', $this->user);
-        $download->package($this->notify);
+        $url = $download->package($this->notify);
+
+        return ['fluidbook' => $fluidbook, 'url' => $url];
     }
 }
index a5095dc178c8feb4f54d5ddb9aa1e0ec1745b7d3..2f535c910394758e01011d1946abf104652699cb 100644 (file)
@@ -19,12 +19,7 @@ Route::group([
 ], 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']);
-    Route::put('fluidbook-theme/{id}/uploadfile/{fieldname}', [\App\Http\Controllers\API\FluidbookThemeAPIController::class, 'uploadfile']);
-    Route::delete('fluidbook-theme/{id}', [\App\Http\Controllers\API\FluidbookThemeAPIController::class, 'deletefromws2']);
+    Route::get('fluidbook-publication/create', [\App\Http\Controllers\API\FluidbookPublicationAPIController::class, 'create']);
     Route::post('cache/clear/{tag?}', [\App\Http\Controllers\API\CacheAPIController::class, 'clear']);
 });