filters now is a folder config only

This commit is contained in:
2024-10-09 02:17:44 +03:00
parent 19e8d648fc
commit b208e79d15
10 changed files with 362 additions and 390 deletions
+5 -6
View File
@@ -10,16 +10,15 @@
"ext-imagick": "*",
"ext-pdo": "*",
"php": "^8.3",
"guzzlehttp/guzzle": "^7.2",
"intervention/image": "^2.7",
"phpoption/phpoption": "^1.9",
"spatie/image-optimizer": "^1.6",
"staudenmeir/laravel-cte": "^1.0"
"staudenmeir/laravel-cte": "^1.10",
"intervention/image": "^3.8",
"guzzlehttp/guzzle": "^7.9"
},
"require-dev": {
"phpstan/phpstan": "^1.8",
"laravel/framework": "^10.10"
"laravel/framework": "^10.48",
"phpstan/phpstan": "^1.12"
},
"autoload": {
"psr-4": {
Generated
+287 -351
View File
File diff suppressed because it is too large Load Diff
+1 -11
View File
@@ -3,6 +3,7 @@
return [
"env" => env("LUCENT_ENV", "production"),
"schemas_path" => env("LUCENT_SCHEMAS_PATH", "resources/lucent/schemas"),
"image_filters_path" => "app/Filters",
"database" => env('LUCENT_DB_CONNECTION', env('DB_CONNECTION', "sqlite")),
"name" => env("LUCENT_NAME", "Stoic"),
"url" => env("LUCENT_URL", env('APP_URL')),
@@ -17,17 +18,6 @@ return [
*
* */
"commands" => [],
/*
* Image filter will be available both for rich editor fields
* and throughout your application
*
* example:
* [
* "filterName" => Filter::class
* ]
*
* */
"imageFilters" => [],
"canInvite" => ["admin"],
"canBuild" => ["admin"],
"systemUserId" => "",
@@ -0,0 +1,4 @@
<button class="bt bt-primary">
{{$slot}}
<img alt="indicator" id="indicator" class="htmx-indicator" src="/img/spinner.svg"/>
</button>
+4
View File
@@ -0,0 +1,4 @@
<div class="notice {{$type ?? "info"}}">
<div class="title">{{$title}}</div>
<div class="content">{{ $slot }}</div>
</div>
+17 -5
View File
@@ -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;
}
+34 -8
View File
@@ -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)));
}
}
+2 -8
View File
@@ -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');
}
}
+1 -1
View File
@@ -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);
}
+7
View File
@@ -30,4 +30,11 @@ class CollectionSchema implements Schema
{
}
public function forJsonGenerator(): array
{
$schemaAr = toArray($this);
unset($schemaAr["folder"]);
return $schemaAr;
}
}