filters now is a folder config only
This commit is contained in:
+5
-6
@@ -10,16 +10,15 @@
|
|||||||
"ext-imagick": "*",
|
"ext-imagick": "*",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
"php": "^8.3",
|
"php": "^8.3",
|
||||||
"guzzlehttp/guzzle": "^7.2",
|
|
||||||
"intervention/image": "^2.7",
|
|
||||||
"phpoption/phpoption": "^1.9",
|
"phpoption/phpoption": "^1.9",
|
||||||
"spatie/image-optimizer": "^1.6",
|
"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": {
|
"require-dev": {
|
||||||
"phpstan/phpstan": "^1.8",
|
"laravel/framework": "^10.48",
|
||||||
"laravel/framework": "^10.10"
|
"phpstan/phpstan": "^1.12"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
Generated
+287
-351
File diff suppressed because it is too large
Load Diff
+1
-11
@@ -3,6 +3,7 @@
|
|||||||
return [
|
return [
|
||||||
"env" => env("LUCENT_ENV", "production"),
|
"env" => env("LUCENT_ENV", "production"),
|
||||||
"schemas_path" => env("LUCENT_SCHEMAS_PATH", "resources/lucent/schemas"),
|
"schemas_path" => env("LUCENT_SCHEMAS_PATH", "resources/lucent/schemas"),
|
||||||
|
"image_filters_path" => "app/Filters",
|
||||||
"database" => env('LUCENT_DB_CONNECTION', env('DB_CONNECTION', "sqlite")),
|
"database" => env('LUCENT_DB_CONNECTION', env('DB_CONNECTION', "sqlite")),
|
||||||
"name" => env("LUCENT_NAME", "Stoic"),
|
"name" => env("LUCENT_NAME", "Stoic"),
|
||||||
"url" => env("LUCENT_URL", env('APP_URL')),
|
"url" => env("LUCENT_URL", env('APP_URL')),
|
||||||
@@ -17,17 +18,6 @@ return [
|
|||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
"commands" => [],
|
"commands" => [],
|
||||||
/*
|
|
||||||
* Image filter will be available both for rich editor fields
|
|
||||||
* and throughout your application
|
|
||||||
*
|
|
||||||
* example:
|
|
||||||
* [
|
|
||||||
* "filterName" => Filter::class
|
|
||||||
* ]
|
|
||||||
*
|
|
||||||
* */
|
|
||||||
"imageFilters" => [],
|
|
||||||
"canInvite" => ["admin"],
|
"canInvite" => ["admin"],
|
||||||
"canBuild" => ["admin"],
|
"canBuild" => ["admin"],
|
||||||
"systemUserId" => "",
|
"systemUserId" => "",
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<button class="bt bt-primary">
|
||||||
|
{{$slot}}
|
||||||
|
<img alt="indicator" id="indicator" class="htmx-indicator" src="/img/spinner.svg"/>
|
||||||
|
</button>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<div class="notice {{$type ?? "info"}}">
|
||||||
|
<div class="title">{{$title}}</div>
|
||||||
|
<div class="content">{{ $slot }}</div>
|
||||||
|
</div>
|
||||||
@@ -5,11 +5,12 @@ namespace Lucent\Commands;
|
|||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Lucent\Primitive\Collection;
|
use Lucent\Primitive\Collection;
|
||||||
use Lucent\Schema\CollectionSchema;
|
use Lucent\Schema\CollectionSchema;
|
||||||
|
use Lucent\Schema\Ui\Text;
|
||||||
|
|
||||||
class GenerateCollectionSchema extends Command
|
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';
|
protected $description = 'Generate a lucent collection';
|
||||||
|
|
||||||
@@ -17,26 +18,37 @@ class GenerateCollectionSchema extends Command
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$name = $this->argument('name');
|
$name = $this->argument('name');
|
||||||
|
$fields = $this->argument('fields');
|
||||||
|
$fieldsStringArray = [];
|
||||||
|
if(!empty($fields)){
|
||||||
|
$fieldsStringArray = explode(',', $fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$schema = new CollectionSchema(
|
$schema = new CollectionSchema(
|
||||||
name: $name,
|
name: $name,
|
||||||
label: $name,
|
label: $name,
|
||||||
visible: [],
|
visible: [],
|
||||||
groups: [],
|
groups: [],
|
||||||
fields: Collection::make(),
|
fields: Collection::make([]),
|
||||||
folder: "",
|
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'));
|
$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");
|
$this->error("Your config directory \"$configDir\" doesn't exist. Create it first and run again");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$schemaPath = $configDir . "/" . $name . '.json';
|
$schemaPath = $configDir . "/" . $name . '.json';
|
||||||
|
|
||||||
if(file_exists($schemaPath)){
|
if (file_exists($schemaPath)) {
|
||||||
$this->error("The schema file already exists.");
|
$this->error("The schema file already exists.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
namespace Lucent\File;
|
namespace Lucent\File;
|
||||||
|
|
||||||
|
use DirectoryIterator;
|
||||||
|
use Exception;
|
||||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Log\Logger;
|
use Illuminate\Log\Logger;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Intervention\Image\Drivers\Imagick\Encoders\WebpEncoder;
|
||||||
use Intervention\Image\ImageManager;
|
use Intervention\Image\ImageManager;
|
||||||
use Lucent\Channel\ChannelService;
|
use Lucent\Channel\ChannelService;
|
||||||
use Lucent\Database\Database;
|
use Lucent\Database\Database;
|
||||||
@@ -16,6 +19,7 @@ use Lucent\Record\QueryRecord;
|
|||||||
use Lucent\Schema\FilesSchema;
|
use Lucent\Schema\FilesSchema;
|
||||||
use Lucent\Schema\Schema;
|
use Lucent\Schema\Schema;
|
||||||
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
||||||
|
use Symfony\Component\Finder\Finder;
|
||||||
|
|
||||||
class FileService
|
class FileService
|
||||||
{
|
{
|
||||||
@@ -79,9 +83,15 @@ class FileService
|
|||||||
throw new LucentException("File $filename not uploaded");
|
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];
|
list($width, $height) = $this->isImage($mimetype) ? getimagesize($file) : [0, 0];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$recordFile = new RecordFile(
|
$recordFile = new RecordFile(
|
||||||
originalName: $originalFilename,
|
originalName: $originalFilename,
|
||||||
mime: $mimetype,
|
mime: $mimetype,
|
||||||
@@ -131,16 +141,32 @@ class FileService
|
|||||||
|
|
||||||
public function createTemplates(Filesystem $disk, string $path): void
|
public function createTemplates(Filesystem $disk, string $path): void
|
||||||
{
|
{
|
||||||
$originalImage = $this->imageManager->make($disk->get($path));
|
try {
|
||||||
foreach (config("lucent.imageFilters") as $preset => $filterClass) {
|
$originalImage = $this->imageManager->read($disk->get($path));
|
||||||
$image = $originalImage->filter(new $filterClass);
|
}catch (Exception $exception){
|
||||||
$templateUri = "/templates/" . $preset . "/" . $path;
|
$this->logger->error($exception->getMessage());
|
||||||
$disk->put($templateUri, $image->encode('webp', 75));
|
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;
|
$thumbDir = "thumbs/" . $path;
|
||||||
|
|
||||||
$image = $originalImage->fit(300, 300);
|
$image = $originalImage->cover(300, 300);
|
||||||
$disk->put($thumbDir, $image->encode('webp', 75));
|
$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\Blade;
|
||||||
use Illuminate\Support\Facades\View;
|
use Illuminate\Support\Facades\View;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Intervention\Image\Drivers\Imagick\Driver;
|
||||||
use Intervention\Image\ImageManager;
|
use Intervention\Image\ImageManager;
|
||||||
use Lucent\Channel\ChannelService;
|
use Lucent\Channel\ChannelService;
|
||||||
use Lucent\Commands\CompileSchemas;
|
use Lucent\Commands\CompileSchemas;
|
||||||
@@ -35,7 +36,7 @@ class LucentServiceProvider extends ServiceProvider
|
|||||||
});
|
});
|
||||||
|
|
||||||
$this->app->bind(ImageManager::class, function () {
|
$this->app->bind(ImageManager::class, function () {
|
||||||
return new ImageManager(['driver' => 'imagick']);
|
return new ImageManager(Driver::class);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->mergeConfigFrom(
|
$this->mergeConfigFrom(
|
||||||
@@ -51,9 +52,6 @@ class LucentServiceProvider extends ServiceProvider
|
|||||||
"pgsql" => new PgsqlDatabaseGraph(),
|
"pgsql" => new PgsqlDatabaseGraph(),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,14 +59,12 @@ class LucentServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot(Router $router): void
|
public function boot(Router $router): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$manifestPath = public_path('vendor/lucent/dist/manifest.json');
|
$manifestPath = public_path('vendor/lucent/dist/manifest.json');
|
||||||
$manifest = null;
|
$manifest = null;
|
||||||
if (file_exists($manifestPath)) {
|
if (file_exists($manifestPath)) {
|
||||||
$manifest = json_decode(file_get_contents(public_path('vendor/lucent/dist/manifest.json')), true);
|
$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.auth', \Lucent\Http\Middleware\AuthMiddleware::class);
|
||||||
$router->aliasMiddleware('lucent.guest', \Lucent\Http\Middleware\GuestMiddleware::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/dist' => public_path('vendor/lucent/dist'),
|
||||||
__DIR__ . '/../front/public' => public_path('vendor/lucent/public'),
|
__DIR__ . '/../front/public' => public_path('vendor/lucent/public'),
|
||||||
], 'lucent');
|
], 'lucent');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ readonly class RecordService
|
|||||||
);
|
);
|
||||||
|
|
||||||
RecordRepo::update($newRecord);
|
RecordRepo::update($newRecord);
|
||||||
$newEdges = $this->edgeService->replaceManyForRecord($record->id, $record->schema, $edges);
|
$newEdges = $this->edgeService->replaceManyForRecord($record->id, $edges );
|
||||||
$this->revisionService->create($newRecord, $newEdges);
|
$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