diff --git a/front/js/svelte/records/StatusSelect.svelte b/front/js/svelte/records/StatusSelect.svelte index 55e8017..b471aca 100644 --- a/front/js/svelte/records/StatusSelect.svelte +++ b/front/js/svelte/records/StatusSelect.svelte @@ -51,7 +51,7 @@ {#if channel.previewTarget} - + Preview {/if} diff --git a/src/Account/AuthService.php b/src/Account/AuthService.php index ec9561d..ac7a261 100644 --- a/src/Account/AuthService.php +++ b/src/Account/AuthService.php @@ -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 diff --git a/src/Channel/Channel.php b/src/Channel/Channel.php index e97daf4..fa52403 100644 --- a/src/Channel/Channel.php +++ b/src/Channel/Channel.php @@ -9,6 +9,7 @@ final class Channel { public string $lucentUrl; public string $filesUrl; + public string $previewTargetUrl; /** * @param Collection $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; } } diff --git a/src/Channel/ChannelService.php b/src/Channel/ChannelService.php index 79d8651..8ea9db3 100644 --- a/src/Channel/ChannelService.php +++ b/src/Channel/ChannelService.php @@ -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; diff --git a/src/Commands/CompileConfig.php b/src/Commands/CompileConfig.php deleted file mode 100644 index 4b813fe..0000000 --- a/src/Commands/CompileConfig.php +++ /dev/null @@ -1,52 +0,0 @@ -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"); - } - -} diff --git a/src/Commands/CompileSchemas.php b/src/Commands/CompileSchemas.php new file mode 100644 index 0000000..b9277d5 --- /dev/null +++ b/src/Commands/CompileSchemas.php @@ -0,0 +1,53 @@ +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"); + } + +} diff --git a/src/Config/main.php b/src/Config/main.php index ac6c2e5..f1b1e85 100644 --- a/src/Config/main.php +++ b/src/Config/main.php @@ -1,6 +1,10 @@ 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" => [], ]; diff --git a/src/LucentServiceProvider.php b/src/LucentServiceProvider.php index 216d458..d259460 100644 --- a/src/LucentServiceProvider.php +++ b/src/LucentServiceProvider.php @@ -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, ]); } diff --git a/src/macros.php b/src/macros.php index df0e305..b659b57 100644 --- a/src/macros.php +++ b/src/macros.php @@ -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"); + } +}