lucent config
This commit is contained in:
@@ -51,7 +51,7 @@
|
||||
|
||||
</div>
|
||||
{#if channel.previewTarget}
|
||||
<a href="{channel.previewTarget}?schema={schema.name}&id={record.id}" target="_blank" class="btn btn-outline-info ms-3">
|
||||
<a href="{channel.previewTargetUrl}?schema={schema.name}&id={record.id}" target="_blank" class="btn btn-outline-info ms-3">
|
||||
Preview
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
@@ -22,9 +22,15 @@ readonly class AuthService
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function currentUserId(): ?string
|
||||
{
|
||||
return $this->session->get("user.id");
|
||||
if(app()->runningInConsole()){
|
||||
return config("lucent.systemUserId");
|
||||
}else{
|
||||
return $this->session->get("user.id");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function isLoggedIn(): bool
|
||||
|
||||
@@ -9,6 +9,7 @@ final class Channel
|
||||
{
|
||||
public string $lucentUrl;
|
||||
public string $filesUrl;
|
||||
public string $previewTargetUrl;
|
||||
|
||||
/**
|
||||
* @param Collection<Schema> $schemas
|
||||
@@ -20,11 +21,11 @@ final class Channel
|
||||
public string $generateCommand,
|
||||
public Collection $schemas,
|
||||
public array $imageFilters,
|
||||
// public Collection $previewTargets,
|
||||
)
|
||||
{
|
||||
$this->lucentUrl = $url . "/lucent";
|
||||
$this->filesUrl = $url . "/storage";
|
||||
$this->previewTargetUrl = $url . "/". $previewTarget;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,25 +21,24 @@ final class ChannelService
|
||||
|
||||
public static function fromConfig(): ChannelService
|
||||
{
|
||||
if(file_exists(storage_path("lucent.config.json"))){
|
||||
$configJson = file_get_contents(storage_path("lucent.config.json"));
|
||||
$configArray = json_decode($configJson, true);
|
||||
}else{
|
||||
$configArray = null;
|
||||
$schemasArray = [];
|
||||
if(file_exists(schemas_path())){
|
||||
$schemasJson = file_get_contents(schemas_path());
|
||||
$schemasArray = json_decode($schemasJson, true);
|
||||
}
|
||||
|
||||
|
||||
$schemaService = new SchemaService();
|
||||
$schemasCollection = (new Collection($configArray["schemas"] ?? []))->map([$schemaService, 'fromArray']);
|
||||
$schemasCollection = (new Collection($schemasArray))->map([$schemaService, 'fromArray']);
|
||||
|
||||
|
||||
$channel = new Channel(
|
||||
name: $configArray["name"] ?? "",
|
||||
url: rtrim($configArray["url"] ?? "", "/"),
|
||||
previewTarget: rtrim($configArray["previewTarget"] ?? "", "/"),
|
||||
generateCommand: $configArray["generateCommand"] ?? "",
|
||||
name: config("lucent.name") ?? "",
|
||||
url: rtrim( config("lucent.url") ?? "", "/"),
|
||||
previewTarget: rtrim( config("lucent.previewTarget") ?? "", "/"),
|
||||
generateCommand: config("lucent.generateCommand") ?? "",
|
||||
schemas: $schemasCollection,
|
||||
imageFilters: $configArray["imageFilters"] ?? [],
|
||||
imageFilters: config("lucent.imageFilters") ?? [],
|
||||
);
|
||||
$channelService = new ChannelService($schemaService);
|
||||
$channelService->channel = $channel;
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Commands;
|
||||
|
||||
use DirectoryIterator;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CompileConfig extends Command
|
||||
{
|
||||
|
||||
protected $signature = 'lucent:config';
|
||||
|
||||
protected $description = 'Compiles Config';
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$configDir = base_path(config('lucent.config_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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Commands;
|
||||
|
||||
use DirectoryIterator;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CompileSchemas extends Command
|
||||
{
|
||||
|
||||
protected $signature = 'lucent:schemas';
|
||||
|
||||
protected $description = 'Compiles schemas';
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$configDir = base_path(config('lucent.schemas_path'));
|
||||
$schemasDirIterator = new DirectoryIterator($configDir);
|
||||
$schemas = [];
|
||||
foreach ($schemasDirIterator as $file) {
|
||||
if ($file->getExtension() !== "json") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$schemaJson = file_get_contents($configDir . "/" . $file->getFilename());
|
||||
$schema = json_decode($schemaJson, true);
|
||||
if (empty($schema)) {
|
||||
$this->error("Invalid JSON " . $file->getFilename());
|
||||
return 0;
|
||||
}
|
||||
$schemas[] = $schema;
|
||||
|
||||
}
|
||||
|
||||
$schemas = collect($schemas)->sortBy("label")->values()->toArray();
|
||||
|
||||
if(!file_exists(storage_path("lucent"))){
|
||||
mkdir(storage_path("lucent"));
|
||||
}
|
||||
|
||||
file_put_contents(schemas_path(), json_encode($schemas));
|
||||
|
||||
$this->info("Lucent Schemas were updated");
|
||||
}
|
||||
|
||||
}
|
||||
+6
-2
@@ -1,6 +1,10 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
"config_path" => env("LUCENT_CONFIG_PATH", "app/Lucent")
|
||||
|
||||
"schemas_path" => env("LUCENT_SCHEMAS_PATH", "app/Lucent"),
|
||||
"name" => env("LUCENT_NAME", "Lucent"),
|
||||
"url" => env("LUCENT_URL", "http://localhost:8000/"),
|
||||
"previewTarget" => env("LUCENT_PREVIEW_TARGET", "previewTarget"),
|
||||
"generateCommand" => env("LUCENT_GENERATE_COMMAND", "generate:static"),
|
||||
"imageFilters" => [],
|
||||
];
|
||||
|
||||
@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\Commands\CompileConfig;
|
||||
use Lucent\Commands\CompileSchemas;
|
||||
use Lucent\Commands\RebuildThumbnails;
|
||||
use Lucent\File\FileService;
|
||||
use Lucent\File\ImageService;
|
||||
@@ -36,7 +36,12 @@ class LucentServiceProvider extends ServiceProvider
|
||||
public function boot(Router $router): void
|
||||
{
|
||||
|
||||
$manifest = json_decode(file_get_contents(public_path('vendor/lucent/dist/manifest.json')),true);
|
||||
$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);
|
||||
@@ -49,7 +54,7 @@ class LucentServiceProvider extends ServiceProvider
|
||||
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->commands([
|
||||
CompileConfig::class,
|
||||
CompileSchemas::class,
|
||||
RebuildThumbnails::class,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -37,3 +37,11 @@ if (!function_exists('make_dir_r')) {
|
||||
is_dir($path) || mkdir($path, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('schemas_path')) {
|
||||
function schemas_path(): string
|
||||
{
|
||||
return storage_path("lucent/lucent.schemas.json");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user