driver_opts:
sshcmd: "fluidbook@kingkong.cubedesigners.com:/home/fluidbook/data"
allow_other: ""
+ cache: "no"
+ uid: 1001
+ gid: 33
password: "Qu2E9uq48bBzsqGiZA"
docs:
driver_opts:
sshcmd: "fluidbook@dracula.cubedesigners.com:/data/fluidbook/docs"
allow_other: ""
+ cache: "no"
+ uid: 1001
+ gid: 33
password: "Qu2E9uq48bBzsqGiZA"
fluidbookpublication/seo
fluidbookpublication/pdf
fluidbookcollection/final
+fluidbookcollection/download
collection/final
elearningpackage/final
elearningmedia/final
app/public/fluidbookcollection
app/public/quiz
protected/youtube
+
namespace App\Fluidbook;
+use Cubist\PDF\PDFTools;
use Cubist\Util\Files\Files;
use Fluidbook\Tools\Jobs\ProcessFile;
use hollodotme\FastCGI\Client;
class Farm
{
protected static $_outPDF = [];
- protected static $_forceServer = false;
+ //protected static $_forceServer = false;
- //protected static $_forceServer = 'alphaville';
+ protected static $_forceServer = 'alphaville';
protected static $_region = Region::EUROPE;
public static function getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $resolutionRatio, $mobileFirstRatio, $path, $force = false)
{
- $params = ['toolbox' => 1,
+ $params = [
+ 'operation' => 'documentfile',
'page' => $page,
'format' => $format,
'resolution' => $resolution,
$out = self::_getOutDirFromPDF($pdf);
}
- $attrs = ['pdf' => $pdf,
+ $attrs = [
+ 'operation' => 'pdffile',
+ 'pdf' => $pdf,
'page' => $page,
'format' => $format,
'resolution' => $resolution,
$cachekey = 'filefrompdf_' . hash('sha256', print_r($attrs, true));
- $params = array_merge($attrs, ['toolbox' => 1,
+ $params = array_merge($attrs, [
'force' => $force,
]);
return $res;
}
+ public static function fixPDF($pdf, $out)
+ {
+ return self::_getFile(['operation' => 'fixpdf',
+ 'pdf' => $pdf,
+ 'out' => $out], 0,false);
+ }
+
+ public static function cutPDF($pdf, $mode, $out)
+ {
+ return self::_getFile(['operation' => 'cutpdf',
+ 'pdf' => $pdf,
+ 'out' => $out,
+ 'mode' => $mode,
+ ], 0,false);
+ }
+
+ public static function trimPDF($pdf, $out)
+ {
+ return self::_getFile(['operation' => 'trimpdf',
+ 'pdf' => $pdf,
+ 'out' => $out,
+ ], 0,false);
+ }
+
+ public static function splitPDF($pdf, $out)
+ {
+ return self::_getFile(['operation' => 'splitpdf',
+ 'pdf' => $pdf,
+ 'out' => $out], 0,false);
+ }
+
+ public static function extractLinks($pdf, $out)
+ {
+ return self::_getFile(['operation' => 'extractlinks',
+ 'pdf' => $pdf,
+ 'out' => $out], 0,false);
+ }
+
+ public static function extractTexts($pdf, $out, $mode, $extractionMethod, $ignoreSeparators)
+ {
+ return self::_getFile(
+ ['operation' => 'extracttexts',
+ 'pdf' => $pdf,
+ 'out' => $out,
+ 'mode' => $mode,
+ 'method' => $extractionMethod,
+ 'ignoreseparators' => $ignoreSeparators], 0,false);
+ }
+
+ public static function extractHighlightsData($pdf, $out, $mode, $ignoreSeparators)
+ {
+ return self::_getFile(
+ ['operation' => 'extracthightlightsdata',
+ 'pdf' => $pdf,
+ 'out' => $out,
+ 'mode' => $mode,
+ 'ignoreseparators' => $ignoreSeparators], 0,false);
+ }
+
/**
* @throws \Exception
*/
- protected static function _getFile($params, $attempts = 3)
+ protected static function _getFile($params, $attempts = 3, $checkOutput = true)
{
$start = microtime(true);
$farmer = self::pickOneServer();
+ $params['toolbox'] = '1';
+
try {
$output = self::sendRequest($farmer, 'process.php', $params);
} catch (\Exception $e) {
Log::error('Farm server error ' . $farmer['name'] . ' : ' . json_encode($params) . ' : ' . $e->getMessage());
if ($attempts > 0) {
- return static::_getFile($params, $attempts - 1);
+ return static::_getFile($params, $attempts - 1, $checkOutput);
}
return false;
}
- $output = trim($output);
+ if ($checkOutput) {
+ $output = trim($output);
- if (file_exists($output)) {
- $res = $output;
+ if (file_exists($output)) {
+ $res = $output;
+ } else {
+ $res = false;
+ }
} else {
- $res = false;
+ $res = true;
}
$time = round(microtime(true) - $start, 4);
if (!$res) {
if ($attempts > 0) {
Log::warning('Farm failure (' . $farmer['name'] . ') : ' . $output . ' // ' . $log);
- return static::_getFile($params, $attempts - 1);
+ return static::_getFile($params, $attempts - 1, $checkOutput);
}
throw new \Exception('Farm failure (' . $farmer['name'] . ') : ' . $output . ' // ' . $log);
}
public function extractTexts()
{
- PDFTools::extractTexts($this->getPDFSource(), $this->path(), 'standard', 'fluidbook', '');
- PDFTools::extractHighlightsData($this->getPDFSource(), $this->path(), 'standard');
+ Farm::extractTexts($this->getPDFSource(), $this->path(), 'standard', 'fluidbook', '');
+ Farm::extractHighlightsData($this->getPDFSource(), $this->path(), 'standard', 'standard');
}
public function extractLinks()
{
- PDFTools::extractLinks($this->getPDFSource(), $this->path());
+ Farm::extractLinks($this->getPDFSource(), $this->path());
}
protected function _checkJobs($uploadID, $jobs, $nbfiles)
public function fixPDF()
{
- $fixed = $this->getPDFSource('fixed',false);
+ $fixed = $this->getPDFSource('fixed');
$original = $this->getPDFSource('original');
if (!file_exists($fixed) || filesize($fixed) === 0 || filemtime($fixed) < filemtime($original)) {
- PDFTools::fixPDF($original, $fixed);
+ Farm::fixPDF($original, $fixed);
}
return $fixed;
}
public function splitPDF()
{
- PDFTools::split($this->getPDFSource(), $this->path('pdf'));
+ Farm::splitPDF($this->getPDFSource(), $this->path('pdf'));
}
/**
{
$path = $this->_getTextPath($page, $type, $mode, $extractionMethod, $ignoreSeparators);
if (!$this->_checkTextFile($path)) {
- PDFTools::extractTexts($this->getPDFSource(), $this->path(), $mode, $extractionMethod, $ignoreSeparators);
+ Farm::extractTexts($this->getPDFSource(), $this->path(), $mode, $extractionMethod, $ignoreSeparators);
+ if (!Gzip::file_exists($path)) {
+ throw new \Exception('An error occured while producing file ' . $path);
+ }
}
return Gzip::path($path);
}
{
$path = $this->_getHightlightFilePath($page, $mode, $ignoreSeparators);
if (!$this->_checkTextFile($path)) {
- PDFTools::extractHighlightsData($this->getPDFSource(), $this->path(), $mode, $ignoreSeparators);
+ Farm::extractHighlightsData($this->getPDFSource(), $this->path(), $mode, $ignoreSeparators);
if (!Gzip::file_exists($path)) {
throw new \Exception('An error occured while producing file ' . $path);
}
}
public function _getHightlightFilePath($page, $mode = 'standard', $ignoreSeparators = '')
+ {
+ return $this->_getTextBasePath($mode, $ignoreSeparators) . 'p' . $page . '.fby';
+ }
+
+ public function _getTextBasePath($mode = 'standard', $ignoreSeparators = '')
{
$sepFolder = '';
if ($ignoreSeparators) {
$sepFolder = 'sep_' . md5($ignoreSeparators) . '/';
}
$dir = $mode !== 'standard' ? $mode . '/' : '';
- return $this->path('texts/' . $dir . $sepFolder) . 'p' . $page . '.fby';
+ return $this->path('texts/' . $dir . $sepFolder);
}
public function _getTextPath($page, $type = self::TEXT_PLAIN, $mode = 'standard', $extractionMethod = 'fluidbook', $ignoreSeparators = '')
{
- $sepFolder = '';
- if ($ignoreSeparators) {
- $sepFolder = 'sep_' . md5($ignoreSeparators) . '/';
- }
-
if ($mode === 'robust') {
$extractionMethod = 'fluidbook';
}
$prefix = self::_getTextFilePrefix($extractionMethod);
- $dir = $mode !== 'standard' ? $mode . '/' : '';
- return $this->path('texts/' . $dir . $sepFolder) . $prefix . $type . $page . '.txt';
+ return $this->_getTextBasePath($mode, $ignoreSeparators) . $prefix . $type . $page . '.txt';
}
- public function getPDFSource($type = 'crop', $checkIfExists = true): string
+ public function getPDFSource($type = 'crop'): string
{
- $res = $this->path() . $type . '.pdf';
- if ($checkIfExists && !file_exists($res)) {
- if ($type === 'original') {
- throw new \Exception('Missing original PDF file ' . $res);
- } else if ($type === 'fixed') {
- $this->fixPDF();
- } else if ($type === 'crop') {
- $this->cropAndCut();
- }
- }
- return $res;
+ return $this->path() . $type . '.pdf';
}
public function cutDocument($mode)
{
- $fwstk = new FWSTK();
- $fwstk->setArg('--input ' . $this->getPDFSource('fixed'));
- $fwstk->setArg('--cut ' . $mode);
- $fwstk->setArg('--output ' . $this->getPDFSource('crop', false));
- $fwstk->execute();
+ Farm::cutPDF($this->getPDFSource('fixed'), $mode, $this->getPDFSource());
}
public function trimDocument()
{
-
- $fwstk = new FWSTK();
- $fwstk->setArg('--input ' . $this->getPDFSource('fixed'));
- $fwstk->setArg('--trim');
- $fwstk->setArg('--output ' . $this->getPDFSource('crop', false));
- $fwstk->execute();
+ Farm::trimPDF($this->getPDFSource('fixed'), $this->getPDFSource());
}
public function lnCrop()
{
- link($this->getPDFSource('fixed'), $this->getPDFSource('crop', false));
+ link($this->getPDFSource('fixed'), $this->getPDFSource());
}
protected function isCropped()
$infos = $this->_getInfos('fixed');
$this->detectSpreads($infos);
- $this->detectPageDifferences($infos);
+ //$this->detectPageDifferences($infos);
if (!$this->isCropped()) {
$this->lnCrop();
use App\Jobs\FluidbookSocialImage;
use App\Jobs\GenerateDeliveryThumbnailsPreview;
use App\Models\Base\ToolboxDownloadable;
-use App\Models\Base\ToolboxSettingsModel;
use App\Models\Base\ToolboxStatusModel;
use App\Models\Traits\CheckHash;
use App\Models\Traits\PublicationSettings;
return $this->composition_updated_at->getTimestamp();
}
- public function getPDFSource($page, $type = 'crop', $checkIfExist = true): string
+ public function getPDFSource($page, $type = 'crop'): string
{
$compo = $this->getComposition()[$page];
if ($type == 'crop') {
- return self::_getDocument($compo[0])->getPDFSource($type, $checkIfExist);
+ return self::_getDocument($compo[0])->getPDFSource($type);
}
}
:
else
#sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -o cache=no -o sshfs_sync -o uid=1002 -o gid=33 -o allow_other root@godzilla.cubedesigners.com:/data/fluidbook/docs /application/protected/fluidbookpublication/docs
- sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -o cache=no -o sshfs_sync -o uid=1002 -o gid=33 -o allow_other root@dracula.cubedesigners.com:/data/fluidbook/docs /application/protected/fluidbookpublication/docs
+ sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -o cache=no -o uid=1002 -o gid=33 -o allow_other root@dracula.cubedesigners.com:/data/fluidbook/docs /application/protected/fluidbookpublication/docs
fi
# Launch PHP
/application/scripts/updatenpm.sh
sudo chown -R 1001:33 /application/storage/framework
sudo chown -R 1001:33 /application/storage/framework
-php artisan optimize:clear
+#php artisan optimize:clear
php artisan cubist:magic:precache
php artisan toolbox:precache
sudo chown -R 1001:33 /application/storage/framework