]> _ Git - fluidbook-toolbox.git/commitdiff
wait #7634 @0:20
authorsoufiane <soufiane@cubedesigners.com>
Mon, 28 Jul 2025 13:33:50 +0000 (15:33 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 28 Jul 2025 13:33:50 +0000 (15:33 +0200)
app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php

index 25fd881e11f758d2260ee2956c3d5dd0c83f9f50..cd1c090c028bdc1fd9cc8ae247e04faa355ee5e3 100644 (file)
@@ -30,17 +30,28 @@ trait MarkdownOperation
         }
 
         $token = Str::random(10);
-        $dir = self::getMarkdownsDir($id);
-        $file = $dir . 'latest.markdown3.gz';
-        $basefile = $dir . 'latest.markdown.gz';
-        $latest = json_decode(gzdecode(file_get_contents($file))) == "[]" ? gzdecode(file_get_contents($basefile)) : gzdecode(file_get_contents($file));
+        $contents = $this->getLatestMarkdown($id);
         $fluidbook=FluidbookPublication::find($id);
-        $isArray = gettype(json_decode($latest,true));
-        $contents=($isArray === "array" ? json_decode($latest,true) : json_decode(json_decode($latest, true),true)) ?? $fluidbook->getAccessibleContents()['pages'];
 
         return view('fluidbook_publication.markdown_editor', ['contents' => $contents, 'version' => 'stable', 'id' => $id, 'fluidbook' => $fluidbook, 'access' => "", 'token' => $token]);
     }
 
+    protected function getLatestMarkdown($book_id) {
+        $fluidbook=FluidbookPublication::find($book_id);
+        $dir = self::getMarkdownsDir($book_id);
+        $filePath = $dir . 'latest.markdown3.gz';
+        if(file_exists($filePath)) {
+            $file = gzdecode(file_get_contents($filePath));
+            $typeOf = gettype($file);
+
+            if($typeOf === "string") {
+                return json_decode($file,true);
+            }
+        }
+
+        return $fluidbook->getAccessibleContents()['pages'];
+    }
+
     protected function saveMarkdown($fluidbook_id, $message = '', $md = '[]')
     {
         if (!FluidbookPublication::hasPermission($fluidbook_id)) {