From: soufiane Date: Wed, 30 Jul 2025 15:21:50 +0000 (+0200) Subject: wip #7634 @3:00 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=625faec64bbfb793a20eb66113cd429de12fab37;p=fluidbook-toolbox.git wip #7634 @3:00 --- diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php index bb23fe7ed..3c2ff7627 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php @@ -39,13 +39,15 @@ trait MarkdownOperation protected function getLatestMarkdown($book_id) { $fluidbook=FluidbookPublication::find($book_id); $dir = self::getMarkdownsDir($book_id); - $filePath = $dir . 'latest.markdown3.gz'; + $filePath = $dir . 'latest.accessible.gz'; if(file_exists($filePath)) { - $file = gzdecode(file_get_contents($filePath)); - $typeOf = gettype($file); + if (is_file($filePath)) { + $file = gzdecode(file_get_contents($filePath)); + $typeOf = gettype($file); - if($typeOf === "string") { - return json_decode($file,true); + if ($typeOf === "string") { + return json_decode($file, true); + } } } @@ -59,20 +61,21 @@ trait MarkdownOperation } $markdowns = request('markdowns', $md); + $markdowns = ['pages' => $markdowns]; $comments = request('message', $message); $user_id = backpack_user()->id; /** @var FluidbookPublication $fluidbook */ $fluidbook = FluidbookPublication::withoutGlobalScopes()->find($fluidbook_id); - $meta = ['comments' => $comments, 'user' => $user_id]; + $meta = ['comment' => $comments, 'user' => $user_id]; $base = self::getMarkdownsDir($fluidbook_id) . '/' . time(); - $latestMarkdown = self::getMarkdownsDir($fluidbook_id) . '/latest.markdown3.gz'; - $latestMeta = self::getMarkdownsDir($fluidbook_id) . '/latest.meta3.gz'; - file_put_contents($base . '.markdown3.gz', gzencode(json_encode($markdowns, JSON_UNESCAPED_SLASHES ))); - file_put_contents($base . '.meta3.gz', gzencode(json_encode($meta))); - copy($base . '.markdown3.gz', $latestMarkdown); - copy($base . '.meta3.gz', $latestMeta); + $latestMarkdown = self::getMarkdownsDir($fluidbook_id) . '/latest.accessible.gz'; + $latestMeta = self::getMarkdownsDir($fluidbook_id) . '/latest.meta.gz'; + file_put_contents($base . '.accessible.gz', gzencode(json_encode($markdowns, JSON_UNESCAPED_SLASHES ))); + file_put_contents($base . '.meta.gz', gzencode(json_encode($meta))); + copy($base . '.accessible.gz', $latestMarkdown); + copy($base . '.meta.gz', $latestMeta); $fluidbook->touch(); @@ -94,7 +97,7 @@ trait MarkdownOperation continue; } $e = explode('.', $f, 2); - if (($e[1] !== 'meta.gz' && $e[1] !== 'meta3.gz') || $e[0] === 'latest') { + if ($e[1] !== 'meta.gz' || $e[0] === 'latest') { continue; } @@ -105,7 +108,7 @@ trait MarkdownOperation $res = []; foreach ($updates as $timestamp => $u) { - $u['name'] = self::getName($u['user']); + $u['name'] = isset($u['user']) ? self::getName($u['user']) : '-'; $u['date'] = date('Y-m-d H:i:s', $timestamp); $u['timestamp'] = $timestamp; $res[] = $u; @@ -145,9 +148,9 @@ trait MarkdownOperation } $dir = self::getMarkdownsDir($fluidbook_id); - $markdowns = Files::firstThatExists($dir . '/' . $version . '.markdown3.gz', $dir . '/' . $version . '.markdown.gz'); + $markdowns = Files::firstThatExists($dir . '/' . $version . '.accessible.gz'); $markdowns = gzdecode(file_get_contents($markdowns)); - $markdowns = json_decode($markdowns, true); + $markdowns = json_decode($markdowns, true)['pages']; $this->saveMarkdown($fluidbook_id, __('Restaurer la sauvegarde du markdown :date', ['date' => date('Y-m-d H:i:s', $version)]), $markdowns); return response()->json(['success' => 'ok']); diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index 38799e3cd..d2282b80c 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -472,8 +472,8 @@ class FluidbookPublication extends ToolboxStatusModel public function getAccessibleContents($revision = 'latest') { $base = $this->protected_path('fluidbookpublication/accessible/' . $this->id . '/'); - $file = Files::mkdir($base . $revision . '.accessible.gz'); - $meta = Files::mkdir($base . $revision . '.meta.gz'); + $file = Files::mkdir($base) .'/'. $revision . '.accessible.gz'; + $meta = Files::mkdir($base) .'/'. $revision . '.meta.gz'; if (!file_exists($file)) { if ($revision === 'latest') { $json = ['pages' => []]; @@ -484,8 +484,8 @@ class FluidbookPublication extends ToolboxStatusModel file_put_contents($file, gzencode(json_encode($json))); file_put_contents($meta, gzencode(json_encode(['comment' => 'Initial extraction from PDF']))); - copy($file, Files::mkdir($base . time() . '.accessible.gz')); - copy($meta, Files::mkdir($base . time() . '.meta.gz')); + copy($file, Files::mkdir($base) . '/'.time() . '.accessible.gz'); + copy($meta, Files::mkdir($base) . '/'.time() . '.meta.gz'); return $json; } diff --git a/resources/markdowneditor/js/markdowneditor.js b/resources/markdowneditor/js/markdowneditor.js index 0cf870de9..83d76aad0 100644 --- a/resources/markdowneditor/js/markdowneditor.js +++ b/resources/markdowneditor/js/markdowneditor.js @@ -189,7 +189,7 @@ MarkdownEditor.prototype = { this.editor.setMarkdown(state[lastKey],false) this.editor.moveCursorToStart(true) }else { - this.contentMarkdown = MARKDOWN_DATA[this.currentPage] ?? '' + this.contentMarkdown = MARKDOWN_DATA['pages'][this.currentPage] ?? '' this.editor.setMarkdown(this.contentMarkdown, false) this.editor.moveCursorToStart(true) } @@ -215,7 +215,7 @@ MarkdownEditor.prototype = { }, setCurrentState: function (state) { - MARKDOWN_DATA[this.currentPage] = state; + MARKDOWN_DATA['pages'][this.currentPage] = state; let scroll = this.editor.getScrollTop(); this.editor.setMarkdown(state, false); this.savedScroll = $(".toastui-editor-md-preview").scrollTop(); diff --git a/resources/markdowneditor/js/markdowneditor.save.js b/resources/markdowneditor/js/markdowneditor.save.js index 6ac7cfe2d..0812fede6 100644 --- a/resources/markdowneditor/js/markdowneditor.save.js +++ b/resources/markdowneditor/js/markdowneditor.save.js @@ -61,7 +61,7 @@ MarkdowneditorSave.prototype = { url: '/fluidbook-publication/' + FLUIDBOOK_DATA.id + '/save/markdown', method: 'post', data: { _method: 'put', message: message, - markdowns: MARKDOWN_DATA, + markdowns: MARKDOWN_DATA['pages'], }, success: function (data) { if (notify) { diff --git a/resources/markdowneditor/js/markdowneditor.undo.js b/resources/markdowneditor/js/markdowneditor.undo.js index 52d682cc8..dd81a6893 100644 --- a/resources/markdowneditor/js/markdowneditor.undo.js +++ b/resources/markdowneditor/js/markdowneditor.undo.js @@ -79,7 +79,7 @@ MarkdowneditorUndo.prototype = { if (index > 0 && index < this.states[this.markdowneditor.getCurrentPage()].length) { this.states[this.markdowneditor.getCurrentPage()] = this.states[this.markdowneditor.getCurrentPage()].slice(0, index); } - MARKDOWN_DATA[this.markdowneditor.getCurrentPage()] = cs + MARKDOWN_DATA['pages'][this.markdowneditor.getCurrentPage()] = cs this.states[this.markdowneditor.getCurrentPage()].push(cs); this.scrolls[this.markdowneditor.getCurrentPage()].push($(".toastui-editor-md-preview").scrollTop()); this.indexes[this.markdowneditor.getCurrentPage()]++; diff --git a/resources/markdowneditor/js/markdowneditor.versions.js b/resources/markdowneditor/js/markdowneditor.versions.js index 9cc57492a..b88e8a2b0 100644 --- a/resources/markdowneditor/js/markdowneditor.versions.js +++ b/resources/markdowneditor/js/markdowneditor.versions.js @@ -27,7 +27,7 @@ MarkdownVersions.prototype = { item += '
'; item += '
' + version.date + '
'; item += '
' + version.name + '
'; - item += '
' + version.comments + '
'; + item += '
' + version.comment + '
'; item += '
'; item += '
'; item += '
'