protected function _compileandpackage($zip = true)
{
- $packager = Packager::package($this->entry->id, $this->version, $zip, true, $this->_params);
+ if ($this->entry->version == 3) {
+ $packager = Packager::package($this->entry->id, $this->version, $zip, true, $this->_params);
+ } else {
+ $packager = new WorkshopPackager($this->entry->id, $this->version, null, $this->_params);
+ $packager->zipPackage = $zip;
+ $packager->cleanOnDestruct = true;
+ $packager->setUser($this->getUser());
+ }
$packager->makePackage($zip);
$url = $packager->getFinalURL();
if ($url) {
--- /dev/null
+<?php
+
+namespace App\Fluidbook\Packager;
+
+use App\Services\WorkshopV2;
+
+class WorkshopPackager extends Packager
+{
+ protected $version;
+
+ protected static $_versionMap = [
+ 'online' => 'html',
+ ];
+
+ public function __construct($book_id, $version, $vdir = null, $options = [])
+ {
+ parent::__construct($book_id, $vdir, $options);
+ $this->version = $version;
+ }
+
+ public function makePackage($zip)
+ {
+
+ $ws = new WorkshopV2();
+ $ws->login($this->getUser()->email, $this->getUser()->api_token);
+ $version = self::$_versionMap[$this->version] ?? $this->version;
+ $this->setFinalURL($ws->getDownloadBookURL($this->book_id, $version));
+ }
+}
use GuzzleHttp\Cookie\FileCookieJar;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Utils;
+use Illuminate\Support\Facades\Log;
use SplFileInfo;
use stdClass;
protected $_http;
/** @var string */
- protected $_domain = 'https://workshop.fluidbook.com/';
+ const BASE_URL = 'https://workshop.fluidbook.com/';
public function __construct()
{
$this->_cookies = new FileCookieJar(Files::mkdir(protected_path('ws2cookies/')) . Str::random(5), true);
- $this->_http = new Client(['base_uri' => $this->_domain, 'timeout' => 60000, 'read_timeout' => 60000, 'cookies' => $this->_cookies]);
+ $this->_http = new Client(['base_uri' => self::BASE_URL, 'timeout' => 60000, 'read_timeout' => 60000, 'cookies' => $this->_cookies]);
}
public function login($username, $api_key)
public function installBook($id, $dir, $options = [], $version = 'online', $tries = 3, $beforeInstallCallback = null, $function = 'downloadBookAndInstall')
{
- $url = 'ajax/exportbookExe';
-
$action = 'download';
if (isset($options['action'])) {
$action = $options['action'];
unset($options['action']);
}
- $reqData = ['version' => $version, 'book_id' => $id, 'action' => $action, 'options' => $options];
- if ($action === 'install_hosting') {
- $destination = [];
- if (isset($options['dir'])) {
- $destination['dir'] = $options['dir'];
- unset($options['dir']);
- }
- $reqData['destination'] = $destination;
- }
-
- $response = $this->_request($url, 'POST', $reqData);
-
-
- $xml = $this->_getXMLFromResponse($response);
+ $xml = $this->_actionDownloadBook($id, $version, $action, $options);
if ($action === 'install_hosting') {
return (string)$xml->truepopup->url;
}
}
+ protected function _actionDownloadBook($id, $version, $action, $options = [])
+ {
+ $url = 'ajax/exportbookExe';
+ $reqData = ['version' => $version, 'book_id' => $id, 'action' => $action, 'options' => $options];
+ if ($action === 'install_hosting') {
+ $destination = [];
+ if (isset($options['dir'])) {
+ $destination['dir'] = $options['dir'];
+ unset($options['dir']);
+ }
+ $reqData['destination'] = $destination;
+ }
+
+ $response = $this->_request($url, 'POST', $reqData);
+ return $this->_getXMLFromResponse($response);
+ }
+
+ public function getDownloadBookURL($id, $version)
+ {
+ $xml = $this->_actionDownloadBook($id, $version, 'download');
+
+ if ($xml !== false && isset($xml->redirection) && !is_null($xml->redirection)) {
+ return self::BASE_URL . ltrim((string)$xml->redirection, '/');
+ }
+ return null;
+ }
+
public function downloadBookExport($id, $dir, $options = [], $version = 'online', $tries = 3, $beforeInstallCallback = null)
{
return $this->installBook($id, $dir, $options, $version, $tries, $beforeInstallCallback, 'downloadBook');
Files::rmdir($tdir);
}
+
public function createBook($title, $from = null)
{
$params = ['title' => $title];
$options['timeout'] = $options['read_timeout'] = 60000;
$options['cookies'] = $this->_cookies;
- $uri = $this->_domain . ltrim($uri, '/');
+ $uri = self::BASE_URL . ltrim($uri, '/');
$request = new Request($method, $uri);
try {
return $this->_http->send($request, $options);