--- /dev/null
+<?php
+
+namespace App\Http\Controllers\Tools;
+
+use App\Jobs\ProcessFluidbook;
+use Cubist\Util\Files\Files;
+
+trait FluidbookPreview
+{
+ protected function fluidbookpreview($args)
+ {
+ if (count($args) > 0) {
+ $path = implode('/', $args);
+ }
+ $path = storage_path('fluidbook/out') . '/' . $path;
+ if(file_exists($path)){
+ return response(null)->header('Content-Type', Files::_getMimeType($path))->header('X-Sendfile', $path);
+ }else{
+ return response(null)->setStatusCode(404);
+ }
+ }
+}
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Jobs\SyncJob;
use Illuminate\Queue\SerializesModels;
+use JsonException;
class ProcessFluidbook implements ShouldQueue, ShouldBeUnique
{
*/
protected $in;
protected $out;
+ protected $stub;
/** @var VirtualDirectory */
protected $vdir;
{
$this->in = new Document(storage_path('fluidbook/in/in.pdf'));
$this->out = storage_path('fluidbook/out/');
+
+ $this->stub = resource_path('fluidbook/');
}
/**
start_measure('Compile fluidbook');
$this->vdir = new VirtualDirectory($this->out);
- $this->vdir->copyDirectory(resource_path('fluidbook/'), '/');
+ $this->vdir->copyDirectory($this->stub, '/');
$this->compileContents();
- $this->compileLinks();
$this->compileSearch();
$this->compileConfig();
{
$cp = $this->getConvertPath();
for ($i = 1; $i <= $this->in->getPages(); $i++) {
- $this->vdir->copy($cp . 'html/t' . $i . '-150.jpg', 'data/background/150/t' . $i . '.jpg');
+ $this->vdir->copy($cp . 'html/t' . $i . '-150.jpg', 'data/background/150/p' . $i . '.jpg');
$this->vdir->copy($cp . 'html/to' . $i . '.svg', 'data/contents/p' . $i . '.svg');
$this->vdir->copy($cp . 'html/p' . $i . '.jpg', 'data/thumbnails/p' . $i . '.jpg');
}
public function compileLinks()
{
-
+ return [];
}
public function compileSearch()
$this->vdir->file_put_contents('data/search.index.js', 'var INDEX=' . json_encode($index->compileIndex()) . ';');
}
+ /**
+ * @throws JsonException
+ */
public function compileConfig()
{
+ $settings = mb_substr(file_get_contents($this->stub . '/data/datas.js'), 13, -2);
+ $config = json_decode($settings, false, 512, JSON_THROW_ON_ERROR);
+ $w = $this->in->getWidth();
+ $h = $this->in->getHeight();
+
+ $config->pages = $this->in->getPages();
+ $config->width = $w;
+ $config->height = $h;
+ $config->pagesDimensions = [];
+ for ($i = 1; $i <= $this->in->getPages(); $i++) {
+ $config->pagesDimensions[$i] = [$w, $h];
+ }
+ $config->links = $this->compileLinks();
+ $this->vdir->file_put_contents('data/datas.js', 'var SETTINGS=' . json_encode($config, JSON_THROW_ON_ERROR) . ';');
}