trait StaticSiteUploader
{
- protected function _getSites()
+ public static function getSites()
{
return [
- 'cubedesigners-v8' => ['label' => __('Cubedesigners V8'), 'server' => 'godzilla.cubedesigners.com', 'url' => 'https://v8.cubedesigners.com/']
+ 'cubedesigners-v8' => ['id' => 'cubedesigners-v8', 'label' => __('Cubedesigners V8'), 'server' => 'godzilla.cubedesigners.com', 'url' => 'https://v8.cubedesigners.com/']
];
}
$form->setSubmitLabel(__('Charger'));
$form->setSubmitIcon('lab la-js-square');
$form->addField('file', StandardFile::class, __('Fichier zip'), ['accept' => '.zip', 'hint' => __('La racine du zip doit correspondre à la racine du site')]);
- $s = $this->_getSites();
+ $s = static::getSites();
$sites = [];
foreach ($s as $k => $item) {
$sites[$k] = $item['label'];
rename($file->getPathname(), $zip);
$tmp = Files::tmpdir();
Zip::extract($zip, $tmp);
- $dest = 'staticupload@' . $site['server'] . ':/home/staticupload/' . $siteId;
- $rsync = new Rsync($tmp, $dest);
- $rsync->execute();
+
+ self::rsync($tmp, $site);
return redirect($site['url']);
}
+
+ public static function rsync($from, $site)
+ {
+ if (is_string($site)) {
+ $site = static::getSites()[$site];
+ }
+
+ $dest = 'staticupload@' . $site['server'] . ':/home/staticupload/' . $site['id'];
+ $rsync = new Rsync($from, $dest);
+ $rsync->execute();
+ }
}
namespace App\Models;
+use App\Http\Controllers\Admin\Operations\Tools\StaticSiteUploader;
+use App\Http\Controllers\Admin\Operations\Tools\WebflowOperation;
+use App\Jobs\WebflowPublish;
use App\Models\Base\ToolboxModel;
+use Cubist\Backpack\Magic\Fields\SelectFromArray;
use Cubist\Backpack\Magic\Fields\Table;
use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\Fields\Textarea;
use Cubist\Backpack\Magic\Fields\URL;
use Cubist\Util\CommandLine;
use Cubist\Util\Files\Files;
'singular' => 'site',
'plural' => 'sites'];
- protected $_operations = [];
+ protected $_operations = [WebflowOperation::class];
public function setFields()
{
$this->addField('name', Text::class, __('Projet'), ['column' => true, 'tab' => __('Paramètres')]);
$this->addField('webflow', Text::class, __('URL du projet webflow'), ['prefix' => 'https://', 'suffix' => '.webflow.io', 'column' => true, 'hint' => __('ex : :url', ['url' => 'https://projet.webflow.io']), 'tab' => __('Paramètres')]);
+ $this->addField('domains', Textarea::class, __('Domaines à télécharger'), ['tab' => __('Paramètres')]);
$this->addField('locales', Table::class, __('Langues'), ['columns' => ['locale' => __('Code langue'), 'url' => __('URL')], 'tab' => __('Paramètres')]);
+ $this->addField('slack', Text::class, __('Notification slack'), ['tab' => __('Paramètres')]);
+ $s = StaticSiteUploader::getSites();
+ $sites = [];
+ foreach ($s as $k => $item) {
+ $sites[$k] = $item['label'];
+ }
+ $this->addField('upload', SelectFromArray::class, __('Uploader sur'), ['options' => $sites, 'tab' => __('Paramètres')]);
//$this->addField('texts');
//$this->addField('images');
//$this->addField('seo');
return Cache::get('webflow_' . $this->id . '_locales', []);
}
- public function mirror($slow = true, $reset = false)
+
+ public function onPublish()
+ {
+ WebflowPublish::dispatch($this->id);
+ }
+
+ /**
+ * @param $slow bool
+ * @param $force bool
+ * @return CommandLine
+ */
+ public function mirror($slow = true, $force = false)
{
$path = Files::mkdir(protected_path('webflow/' . $this->id));
- if ($reset) {
+ if ($force) {
$path = Files::emptyDir($path);
}
$wget = new CommandLine('wget');
$wget->setArg('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0');
$wget->setArg("directory-prefix", $path);
$wget->setArg("span-hosts");
+ $wget->setArg("no-host-directories");
if ($slow) {
- $wget->setArg("w", $reset ? 2 : 10);
+ $wget->setArg("wait", $force ? 2 : 10);
$wget->setArg("random-wait");
}
- $domains = [$this->webflow . '.webflow.io',
- 'assets-global.website-files.com',
- 'cdn.jsdelivr.net',
- 'unpkg.com',
- 'cdnjs.cloudflare.com',
- 'ajax.googleapis.com',
- ];
+ $domains = array_unique([$this->webflow . '.webflow.io',
+ 'assets-global.website-files.com',
+ 'cdn.jsdelivr.net',
+ 'unpkg.com',
+ 'cdnjs.cloudflare.com',
+ 'ajax.googleapis.com',
+ 'uploads-ssl.webflow.com',
+ 'uploads.webflow.com',
+ ] + \Cubist\Util\Text::splitLines($this->domains));
+
$wget->setArg("domains", implode(',', $domains));
$wget->setArg("compression", 'auto');
- if (!$reset) {
+ if (!$force) {
$wget->setArg('N');
}
$wget->setArg(null, 'https://' . $this->webflow . '.webflow.io');
$wget->execute();
- $wget->dd();
+ return $wget;
}
public function onRetrieved(): bool
{
- Cache::put('webflow_' . $this->id . '_locales', $this->locales);
- $this->mirror();
+ $locales = $this->locales;
+ if (is_string($locales)) {
+ $locales = json_decode($locales, true);
+ }
+ Cache::put('webflow_' . $this->id . '_locales', $locales);
return parent::onRetrieved();
}