filters now is a folder config only
This commit is contained in:
@@ -5,11 +5,12 @@ namespace Lucent\Commands;
|
||||
use Illuminate\Console\Command;
|
||||
use Lucent\Primitive\Collection;
|
||||
use Lucent\Schema\CollectionSchema;
|
||||
use Lucent\Schema\Ui\Text;
|
||||
|
||||
class GenerateCollectionSchema extends Command
|
||||
{
|
||||
|
||||
protected $signature = 'lucent:make:collection-schema {name}';
|
||||
protected $signature = 'lucent:make:collection-schema {name} {fields?}';
|
||||
|
||||
protected $description = 'Generate a lucent collection';
|
||||
|
||||
@@ -17,26 +18,37 @@ class GenerateCollectionSchema extends Command
|
||||
public function handle()
|
||||
{
|
||||
$name = $this->argument('name');
|
||||
$fields = $this->argument('fields');
|
||||
$fieldsStringArray = [];
|
||||
if(!empty($fields)){
|
||||
$fieldsStringArray = explode(',', $fields);
|
||||
}
|
||||
|
||||
|
||||
$schema = new CollectionSchema(
|
||||
name: $name,
|
||||
label: $name,
|
||||
visible: [],
|
||||
groups: [],
|
||||
fields: Collection::make(),
|
||||
fields: Collection::make([]),
|
||||
folder: "",
|
||||
);
|
||||
$schemaAr = $schema->forJsonGenerator();
|
||||
$schemaAr["fields"] = collect($fieldsStringArray)
|
||||
->map(fn(string $fieldName) => new Text($fieldName, $fieldName))
|
||||
->map(fn(Text $field) => ["name" => $field->name, "label" => $field->name, "ui" => $field->info->name]);
|
||||
|
||||
$json = json_encode($schema, JSON_PRETTY_PRINT);
|
||||
$json = json_encode($schemaAr, JSON_PRETTY_PRINT);
|
||||
$configDir = base_path(config('lucent.schemas_path'));
|
||||
|
||||
if(!file_exists($configDir)) {
|
||||
if (!file_exists($configDir)) {
|
||||
$this->error("Your config directory \"$configDir\" doesn't exist. Create it first and run again");
|
||||
return;
|
||||
}
|
||||
|
||||
$schemaPath = $configDir . "/" . $name . '.json';
|
||||
|
||||
if(file_exists($schemaPath)){
|
||||
if (file_exists($schemaPath)) {
|
||||
$this->error("The schema file already exists.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace Lucent\File;
|
||||
|
||||
use DirectoryIterator;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Log\Logger;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\Drivers\Imagick\Encoders\WebpEncoder;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\Database\Database;
|
||||
@@ -16,6 +19,7 @@ use Lucent\Record\QueryRecord;
|
||||
use Lucent\Schema\FilesSchema;
|
||||
use Lucent\Schema\Schema;
|
||||
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class FileService
|
||||
{
|
||||
@@ -79,9 +83,15 @@ class FileService
|
||||
throw new LucentException("File $filename not uploaded");
|
||||
}
|
||||
|
||||
$this->createTemplates($disk, $path, $file);
|
||||
if($this->isImage($mimetype)){
|
||||
$this->createTemplates($disk, $path);
|
||||
}
|
||||
|
||||
list($width, $height) = $this->isImage($mimetype) ? getimagesize($file) : [0, 0];
|
||||
|
||||
|
||||
|
||||
|
||||
$recordFile = new RecordFile(
|
||||
originalName: $originalFilename,
|
||||
mime: $mimetype,
|
||||
@@ -131,16 +141,32 @@ class FileService
|
||||
|
||||
public function createTemplates(Filesystem $disk, string $path): void
|
||||
{
|
||||
$originalImage = $this->imageManager->make($disk->get($path));
|
||||
foreach (config("lucent.imageFilters") as $preset => $filterClass) {
|
||||
$image = $originalImage->filter(new $filterClass);
|
||||
$templateUri = "/templates/" . $preset . "/" . $path;
|
||||
$disk->put($templateUri, $image->encode('webp', 75));
|
||||
try {
|
||||
$originalImage = $this->imageManager->read($disk->get($path));
|
||||
}catch (Exception $exception){
|
||||
$this->logger->error($exception->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (new DirectoryIterator(config("lucent.image_filters_path")) as $file) {
|
||||
if($file->isDot()) continue;
|
||||
|
||||
$namespace = app()->getNamespace();
|
||||
$filterClass = $namespace.str_replace(
|
||||
['/', '.php'],
|
||||
['\\', ''],
|
||||
Str::after($file->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
|
||||
);
|
||||
|
||||
$image = $originalImage->modify(new $filterClass);
|
||||
$templateUri = "/templates/" . (new $filterClass)->name . "/" . $path;
|
||||
$disk->put($templateUri, $image->encode(new WebpEncoder(75)));
|
||||
};
|
||||
|
||||
|
||||
$thumbDir = "thumbs/" . $path;
|
||||
|
||||
$image = $originalImage->fit(300, 300);
|
||||
$disk->put($thumbDir, $image->encode('webp', 75));
|
||||
$image = $originalImage->cover(300, 300);
|
||||
$disk->put($thumbDir, $image->encode(new WebpEncoder(quality: 75)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\Commands\CompileSchemas;
|
||||
@@ -35,7 +36,7 @@ class LucentServiceProvider extends ServiceProvider
|
||||
});
|
||||
|
||||
$this->app->bind(ImageManager::class, function () {
|
||||
return new ImageManager(['driver' => 'imagick']);
|
||||
return new ImageManager(Driver::class);
|
||||
});
|
||||
|
||||
$this->mergeConfigFrom(
|
||||
@@ -51,9 +52,6 @@ class LucentServiceProvider extends ServiceProvider
|
||||
"pgsql" => new PgsqlDatabaseGraph(),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,14 +59,12 @@ class LucentServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(Router $router): void
|
||||
{
|
||||
|
||||
$manifestPath = public_path('vendor/lucent/dist/manifest.json');
|
||||
$manifest = null;
|
||||
if (file_exists($manifestPath)) {
|
||||
$manifest = json_decode(file_get_contents(public_path('vendor/lucent/dist/manifest.json')), true);
|
||||
}
|
||||
|
||||
|
||||
$router->aliasMiddleware('lucent.auth', \Lucent\Http\Middleware\AuthMiddleware::class);
|
||||
$router->aliasMiddleware('lucent.guest', \Lucent\Http\Middleware\GuestMiddleware::class);
|
||||
|
||||
@@ -103,7 +99,5 @@ class LucentServiceProvider extends ServiceProvider
|
||||
__DIR__ . '/../front/dist' => public_path('vendor/lucent/dist'),
|
||||
__DIR__ . '/../front/public' => public_path('vendor/lucent/public'),
|
||||
], 'lucent');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ readonly class RecordService
|
||||
);
|
||||
|
||||
RecordRepo::update($newRecord);
|
||||
$newEdges = $this->edgeService->replaceManyForRecord($record->id, $record->schema, $edges);
|
||||
$newEdges = $this->edgeService->replaceManyForRecord($record->id, $edges );
|
||||
$this->revisionService->create($newRecord, $newEdges);
|
||||
|
||||
}
|
||||
|
||||
@@ -30,4 +30,11 @@ class CollectionSchema implements Schema
|
||||
{
|
||||
}
|
||||
|
||||
public function forJsonGenerator(): array
|
||||
{
|
||||
$schemaAr = toArray($this);
|
||||
unset($schemaAr["folder"]);
|
||||
return $schemaAr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user