image fixes

This commit is contained in:
2026-05-14 21:15:33 +03:00
parent ef29e4d261
commit 8cd80c016f
14 changed files with 180 additions and 38 deletions
+13
View File
@@ -3,6 +3,7 @@
namespace Lucent\Channel;
use Lucent\Channel\Data\UserCommand;
use Lucent\Data\ImagePreset;
use Lucent\Primitive\Collection;
use Lucent\Data\Schema;
use Lucent\Data\ChannelAuth;
@@ -12,6 +13,10 @@ final class Channel
public string $lucentUrl;
public string $filesUrl;
public string $previewTargetUrl;
/**
* @param array<ImagePreset> $imagePresets
*/
public array $imagePresets;
/**
* @param Collection<Schema> $schemas
@@ -30,6 +35,14 @@ final class Channel
$this->lucentUrl = $url . "/lucent";
$this->filesUrl = $this->makeFilesUrl();
$this->previewTargetUrl = $url . "/" . $previewTarget;
$this->imagePresets = array_map(function ($i) {
$preset = new $i();
return new ImagePreset(
id: $i,
name: $preset->getName(),
path: $preset->getPath(),
);
}, $this->imageFilters);
}
private function makeFilesUrl(): string
+23 -1
View File
@@ -45,7 +45,7 @@ final class ChannelService
previewTarget: rtrim(config("lucent.previewTarget") ?? "", "/"),
commands: Collection::make($userCommands),
schemas: $schemasCollection,
imageFilters: config("lucent.imageFilters") ?? [],
imageFilters: self::loadImageFilters(),
roles: $schemasArray["roles"] ?? [],
);
@@ -54,6 +54,28 @@ final class ChannelService
return $channelService;
}
private static function loadImageFilters(): array
{
$relativePath = config("lucent.image_filter_path");
if (!$relativePath) {
return [];
}
$dir = base_path($relativePath);
if (!is_dir($dir)) {
return [];
}
$namespace = str_replace("/", "\\", ucwords($relativePath, "/"));
return array_values(
array_map(
fn(string $file) => $namespace . "\\" . basename($file, ".php"),
glob("{$dir}/*.php") ?: [],
),
);
}
/**
* @param string $name
* @return Option<Schema>