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);
+ }
}
}
}
$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();
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;
}
$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;
}
$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']);
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' => []];
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;
}
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)
}
},
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();