From d52453f8490a55b806c1f6df12f44acd3ecc0f0d Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 19 Jan 2023 09:53:10 +0100 Subject: [PATCH] wip #5661 @5 --- .docker/images/php/Dockerfile | 2 +- app/Fluidbook/Packager/ChromeOS.php | 15 +- app/Fluidbook/Packager/Download.php | 30 ++-- app/Fluidbook/Packager/MacOS.php | 2 + app/Fluidbook/Packager/OfflineHTML.php | 9 -- app/Fluidbook/Packager/Online.php | 3 + app/Fluidbook/Packager/Packager.php | 48 ++++++- app/Fluidbook/Packager/Precompiled.php | 1 - app/Fluidbook/Packager/USBKey.php | 4 +- app/Fluidbook/Packager/WindowsInstaller.php | 10 +- app/Slack/Slack.php | 7 +- config/app.php | 2 +- config/larabug.php | 146 -------------------- config/logging.php | 3 +- 14 files changed, 102 insertions(+), 180 deletions(-) delete mode 100644 config/larabug.php diff --git a/.docker/images/php/Dockerfile b/.docker/images/php/Dockerfile index 20aa07eee..6584c4752 100644 --- a/.docker/images/php/Dockerfile +++ b/.docker/images/php/Dockerfile @@ -87,7 +87,7 @@ RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true -RUN npm install --unsafe-perm --global uglify-js less sass puppeteer favicons nw-builder@^3 +RUN npm install --unsafe-perm --global uglify-js less sass puppeteer favicons crx3 nw-builder@^3 RUN pip3 install font-line RUN groupadd sudo;useradd -d /application -g 33 -G sudo -s /bin/bash -u 1001 toolbox diff --git a/app/Fluidbook/Packager/ChromeOS.php b/app/Fluidbook/Packager/ChromeOS.php index d778c42ca..9fcccc1a8 100644 --- a/app/Fluidbook/Packager/ChromeOS.php +++ b/app/Fluidbook/Packager/ChromeOS.php @@ -7,10 +7,10 @@ use Cubist\Util\CommandLine; class ChromeOS extends Online { - public $type='chormeos'; - public $cleanOnDestruct=true; + public $type = 'chormeos'; + public $cleanOnDestruct = true; - public $downloadExt='crx'; + public $downloadExt = 'crx'; protected function preparePackage() { @@ -37,10 +37,17 @@ class ChromeOS extends Online { $this->preparePackage(); + // + + $final = $this->getPathBase('crx'); + $chrome = new CommandLine('crx3'); - $chrome->setArg('o', WS_PACKAGER . '/download/' . $this->getBaseFile() . '.crx'); + $chrome->setArg('o', $final); $chrome->setArg(null, $this->vdir . '/m/'); $chrome->execute(); $chrome->debug(); + + $this->setFinalURL($this->getDownloadURL('crx')); + $this->setFinalPath($final); } } diff --git a/app/Fluidbook/Packager/Download.php b/app/Fluidbook/Packager/Download.php index c5d6d2e02..a57b5f2c7 100644 --- a/app/Fluidbook/Packager/Download.php +++ b/app/Fluidbook/Packager/Download.php @@ -5,6 +5,7 @@ namespace App\Fluidbook\Packager; use App\Jobs\DownloadBase; use App\Services\ScormCloud; use Cubist\Util\Files\Files; +use Illuminate\Support\Facades\Log; class Download extends DownloadBase { @@ -63,16 +64,18 @@ class Download extends DownloadBase $url = $this->_compileandpackage(); $subject = __($this->_subject, ['title' => $this->_title(), 'nb' => $this->_id()]); $text = ''; - $actions = ['Télécharger' => $url]; + if ($this->action === 'download' || $this->action === 'scormcloud') { + $actions = ['Télécharger' => $url]; - if ($this->action === 'scormcloud') { - try { - $scormURL = ScormCloud::send($url, 'toolbox_' . $this->type . '_' . $this->_id()); - $actions[__('Tester sur SCORM Cloud')] = $scormURL; - } catch (\Exception $e) { + if ($this->action === 'scormcloud') { + try { + $scormURL = ScormCloud::send($url, 'toolbox_' . $this->type . '_' . $this->_id()); + $actions[__('Tester sur SCORM Cloud')] = $scormURL; + } catch (\Exception $e) { + } + $text = __('Une erreur s\'est produite lors de l\'envoi sur SCORM Cloud (App ID :appid) : :error', ['error' => $e->getMessage(), 'appid' => env('SCORM_CLOUD_APP_ID')]); } - $text = __('Une erreur s\'est produite lors de l\'envoi sur SCORM Cloud (App ID :appid) : :error', ['error' => $e->getMessage(), 'appid' => env('SCORM_CLOUD_APP_ID')]); } } catch (\Exception $e) { $subject = __('Erreur lors de la compilation du :type :nb', ['nb' => $this->_id(), 'type' => $this->type]); @@ -85,9 +88,16 @@ class Download extends DownloadBase protected function _compileandpackage() { - if($this->action==='download' || $this->action===''){ - $zip=true; + if ($this->action === 'download' || $this->action === '') { + $zip = true; } - Packager::package($this->entry->id, $this->version); + $packager = Packager::package($this->entry->id, $this->version, $zip); + $packager->makePackage($zip); + Log::debug($this->action . '/' . $this->entry->id . '/' . $this->version . '/' . get_class($packager) . '///' . $packager->getFinalURL() . '//' . $packager->getFinalPath()); + $url = $packager->getFinalURL(); + if ($url) { + return $url; + } + return $packager->getFinalPath(); } } diff --git a/app/Fluidbook/Packager/MacOS.php b/app/Fluidbook/Packager/MacOS.php index 331721db4..b55c984e0 100644 --- a/app/Fluidbook/Packager/MacOS.php +++ b/app/Fluidbook/Packager/MacOS.php @@ -29,6 +29,8 @@ class MacOS extends WindowsZIP $res = $this->getFinalPackageDir(); } $this->postPackage(); + $this->setFinalURL(null); + $this->setFinalPath($res); return $res; } diff --git a/app/Fluidbook/Packager/OfflineHTML.php b/app/Fluidbook/Packager/OfflineHTML.php index 1d5e4d3a6..798f7a75a 100644 --- a/app/Fluidbook/Packager/OfflineHTML.php +++ b/app/Fluidbook/Packager/OfflineHTML.php @@ -6,13 +6,4 @@ class OfflineHTML extends Online { protected $_allowNetworking = 'internal'; public $type = 'win_html'; - - - protected function copyFluidbookFiles() - { - parent::copyFluidbookFiles(); - unlink($this->vdir . '/index.swf'); - unlink($this->vdir . '/player.swf'); - copy(WS_COMPILE_ASSETS . '/offline.swf', $this->vdir . '/index.swf'); - } } diff --git a/app/Fluidbook/Packager/Online.php b/app/Fluidbook/Packager/Online.php index 57b7b59a3..9d4dcd58b 100644 --- a/app/Fluidbook/Packager/Online.php +++ b/app/Fluidbook/Packager/Online.php @@ -68,6 +68,9 @@ class Online extends Packager if ($zip) { return $this->zip(); } + + $this->setFinalURL(null); + $this->setFinalPath($this->getFinalPackageDir()); return $this->getFinalPackageDir(); } diff --git a/app/Fluidbook/Packager/Packager.php b/app/Fluidbook/Packager/Packager.php index a351fc5ce..27c69b8ea 100644 --- a/app/Fluidbook/Packager/Packager.php +++ b/app/Fluidbook/Packager/Packager.php @@ -38,7 +38,17 @@ class Packager extends \App\Jobs\Base public $zipPackage = true; - public $downloadExt='zip'; + public $downloadExt = 'zip'; + + /** + * @var string + */ + protected $_finalPath = ''; + + /** + * @var string + */ + protected $_finalURL = ''; public static function package($book_id, $type, $zipPackage = true, $cleanOnDestruct = true, $options = []) @@ -235,6 +245,9 @@ class Packager extends \App\Jobs\Base if ($rename) { rename($zipfile, $final); } + + $this->setFinalPath($final); + $this->setFinalURL($this->getDownloadURL('zip')); return $final; } @@ -302,4 +315,37 @@ class Packager extends \App\Jobs\Base `find $dest -type f -name "*.html" -exec rename 's/\.html$/.$e/' '{}' \;`; } } + + /** + * @return string + */ + public function getFinalPath(): string + { + return $this->_finalPath; + } + + /** + * @param string $finalPath + */ + public function setFinalPath(string $finalPath): void + { + $this->_finalPath = $finalPath; + } + + /** + * @return string + */ + public function getFinalURL(): string + { + return $this->_finalURL; + } + + + /** + * @param string $finalURL + */ + public function setFinalURL(string $finalURL): void + { + $this->_finalURL = $finalURL; + } } diff --git a/app/Fluidbook/Packager/Precompiled.php b/app/Fluidbook/Packager/Precompiled.php index 6f2ce8364..09793520e 100644 --- a/app/Fluidbook/Packager/Precompiled.php +++ b/app/Fluidbook/Packager/Precompiled.php @@ -12,7 +12,6 @@ class Precompiled extends Online $this->book->parametres->embedAllLibraries = true; } - public function prepareHTML5() { $res = parent::prepareHTML5(); diff --git a/app/Fluidbook/Packager/USBKey.php b/app/Fluidbook/Packager/USBKey.php index 78e855e10..e7ea8d7b2 100644 --- a/app/Fluidbook/Packager/USBKey.php +++ b/app/Fluidbook/Packager/USBKey.php @@ -10,7 +10,7 @@ class USBKey extends MacOS $this->replaceAutorun(); // Package mac app - $win = ROOT . Packager::package($this->book_id, 'win_inss_html', false, false); + $win = Packager::package($this->book_id, 'win_inss_html', false, false); $dest = $this->getFinalPackageDir() . "/" . $this->exeName . '.exe'; $cp = "cp $win $dest"; @@ -19,7 +19,7 @@ class USBKey extends MacOS public function replaceAutorun() { - $inf = file_get_contents(WS_COMPILE_ASSETS . '/autorun-html.inf'); + $inf = file_get_contents($this->resource_path('fluidbook/packager') . '/autorun-html.inf'); $toReplace = array('title' => $this->book->parametres->title, 'exe' => $this->exeName . '.exe', 'nwplatform' => $this->nwplatform); $inf = $this->replaceContents($inf, $toReplace); file_put_contents($this->getFinalPackageDir() . '/autorun.inf', utf8_decode($inf)); diff --git a/app/Fluidbook/Packager/WindowsInstaller.php b/app/Fluidbook/Packager/WindowsInstaller.php index 9fde1e837..85cdf1931 100644 --- a/app/Fluidbook/Packager/WindowsInstaller.php +++ b/app/Fluidbook/Packager/WindowsInstaller.php @@ -58,15 +58,21 @@ class WindowsInstaller extends WindowsZIP $makensis->setArg(null, '-V4'); $makensis->setArg(null, $tmp); $makensis->execute(); - if (!file_exists($this->getPathBase('exe'))) { + + $out=$this->getPathBase('exe'); + + if (!file_exists($out) ){ die('Error while building the installer : ' . $this->getPathBase('exe')); } $this->signInstaller(); - if (!file_exists($this->getPathBase('exe'))) { + if (!file_exists($out)) { die('Error during the signing process : ' . $this->getPathBase('exe')); } + + $this->setFinalURL($this->getDownloadURL('exe')); + $this->setFinalPath($out); } public function signInstaller() diff --git a/app/Slack/Slack.php b/app/Slack/Slack.php index 574efd7da..7af07bb6b 100644 --- a/app/Slack/Slack.php +++ b/app/Slack/Slack.php @@ -57,12 +57,15 @@ class Slack $actionsText = ''; $i = 0; foreach ($actions as $label => $data) { - if (is_null($data)) { - $data = ['url' => '#nourl']; + if (!$data) { + $data = ['url' => '']; } if (is_string($data)) { $data = ['url' => $data]; } + if (!$data['url']) { + $data['url'] = 'https://toolbox.fluidbook.com/404'; + } if ($i < 6) { $a['elements'][] = array_merge([ 'type' => 'button', diff --git a/config/app.php b/config/app.php index 9ebb1a97c..335768003 100644 --- a/config/app.php +++ b/config/app.php @@ -39,7 +39,7 @@ return [ | */ - 'debug' => !isset($_SERVER['HTTP_X_REAL_IP']) || in_array($_SERVER['HTTP_X_REAL_IP'], ['130.180.213.67']), + 'debug' => !isset($_SERVER['HTTP_X_REAL_IP']) || in_array($_SERVER['HTTP_X_REAL_IP'], ['130.180.213.67']) ? env('APP_DEBUG') : false, /* |-------------------------------------------------------------------------- diff --git a/config/larabug.php b/config/larabug.php deleted file mode 100644 index c5796bb1f..000000000 --- a/config/larabug.php +++ /dev/null @@ -1,146 +0,0 @@ - env('LB_KEY', ''), - - /* - |-------------------------------------------------------------------------- - | Project key - |-------------------------------------------------------------------------- - | - | This is your project key which you receive when creating a project - | Retrieve your key from https://www.larabug.com - | - */ - - 'project_key' => env('LB_PROJECT_KEY', ''), - - /* - |-------------------------------------------------------------------------- - | Environment setting - |-------------------------------------------------------------------------- - | - | This setting determines if the exception should be send over or not. - | - */ - - 'environments' => [ - 'production', - 'staging', - ], - - /* - |-------------------------------------------------------------------------- - | Project version - |-------------------------------------------------------------------------- - | - | Set the project version, default: null. - | For git repository: shell_exec("git log -1 --pretty=format:'%h' --abbrev-commit") - | - */ - 'project_version' => null, - - /* - |-------------------------------------------------------------------------- - | Lines near exception - |-------------------------------------------------------------------------- - | - | How many lines to show near exception line. The more you specify the bigger - | the displayed code will be. Max value can be 50, will be defaulted to - | 12 if higher than 50 automatically. - | - */ - - 'lines_count' => 12, - - /* - |-------------------------------------------------------------------------- - | Prevent duplicates - |-------------------------------------------------------------------------- - | - | Set the sleep time between duplicate exceptions. This value is in seconds, default: 60 seconds (1 minute) - | - */ - - 'sleep' => 60, - - /* - |-------------------------------------------------------------------------- - | Skip exceptions - |-------------------------------------------------------------------------- - | - | List of exceptions to skip sending. - | - */ - - 'except' => [ - 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException', - ], - - /* - |-------------------------------------------------------------------------- - | Key filtering - |-------------------------------------------------------------------------- - | - | Filter out these variables before sending them to LaraBug - | - */ - - 'blacklist' => [ - '*authorization*', - '*password*', - '*token*', - '*auth*', - '*verification*', - '*credit_card*', - 'cardToken', // mollie card token - '*cvv*', - '*iban*', - '*name*', - '*email*' - ], - - /* - |-------------------------------------------------------------------------- - | Release git hash - |-------------------------------------------------------------------------- - | - | - */ - - // 'release' => trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')), - - /* - |-------------------------------------------------------------------------- - | Server setting - |-------------------------------------------------------------------------- - | - | This setting allows you to change the server. - | - */ - - 'server' => env('LB_SERVER', 'https://www.larabug.com/api/log'), - - /* - |-------------------------------------------------------------------------- - | Verify SSL setting - |-------------------------------------------------------------------------- - | - | Enables / disables the SSL verification when sending exceptions to LaraBug - | Never turn SSL verification off on production instances - | - */ - 'verify_ssl' => env('LB_VERIFY_SSL', true), - -]; diff --git a/config/logging.php b/config/logging.php index 5e6ab7fd4..a72b700b9 100644 --- a/config/logging.php +++ b/config/logging.php @@ -37,7 +37,7 @@ return [ 'channels' => [ 'stack' => [ 'driver' => 'stack', - 'channels' => ['daily', 'stderr', 'larabug'], + 'channels' => ['daily', 'stderr', 'slack'], 'ignore_exceptions' => false, ], @@ -102,6 +102,7 @@ return [ 'larabug' => [ 'driver' => 'larabug', + 'level' => 'debug', ], ], -- 2.39.5