This commit is contained in:
2023-10-02 23:10:49 +03:00
commit c6cb488379
255 changed files with 18731 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace Lucent\Commands;
use DirectoryIterator;
use Illuminate\Console\Command;
class CompileConfig extends Command
{
protected $signature = 'lucent:compile:config {path}';
protected $description = 'Compiles Config';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$configDir = base_path($this->argument('path'));
$configJson = file_get_contents($configDir . "lucent.json");
$config = json_decode($configJson, true);
$schemasDirIterator = new DirectoryIterator($configDir . "Schemas");
$schemas = [];
foreach ($schemasDirIterator as $file) {
if ($file->getExtension() !== "json") {
continue;
}
$schemaJson = file_get_contents($configDir . "Schemas/" . $file->getFilename());
$schema = json_decode($schemaJson, true);
if (empty($schema)) {
$this->error("Invalid JSON " . $file->getFilename());
return 0;
}
$schemas[] = $schema;
}
$config["schemas"] = collect($schemas)->sortBy("label")->values()->toArray();
$configOuputJson = json_encode($config);
file_put_contents(storage_path("lucent.config.json"), $configOuputJson);
$this->info("Lucent JSON update");
}
}
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace Lucent\Commands;
use DirectoryIterator;
use Exception;
use Illuminate\Console\Command;
use Intervention\Image\ImageManager;
use Lucent\Channel\ChannelService;
use Lucent\Schema\Schema;
use Lucent\Schema\Type;
class RebuildThumbnails extends Command
{
protected $signature = 'lucent:rebuild:thumbnails';
protected $description = 'Rebuilds thumbnails for path';
public function __construct(public ImageManager $imageManager)
{
parent::__construct();
}
public function handle(ChannelService $channelService): int
{
$channelService->channel->schemas
->where("type", Type::FILES)->values()
->map([$this, 'rebuildThumbnails']);
return 0;
}
public function rebuildThumbnails(Schema $schema): void
{
$filesDir = storage_path("app/public/" . $schema->path . "/");
$thumbDir = storage_path("app/public/thumbs/" . $schema->path . "/");
if (!file_exists($thumbDir)) {
mkdir($thumbDir);
}
$filesDirIterator = new DirectoryIterator($filesDir);
foreach ($filesDirIterator as $file) {
if ($file->isDot()) {
continue;
}
try {
$image = $this->imageManager->make($filesDir . $file->getFilename());
} catch (Exception $e) {
$this->error($e->getMessage());
continue;
}
$image->fit(300, 300);
try {
$image->encode('webp', 75)->save($thumbDir . $file->getFilename());
} catch (Exception $e) {
$this->error($e->getMessage());
continue;
}
$this->info($file->getFilename());
}
}
}