diff --git a/src/Commands/GenerateFileSchema.php b/src/Commands/GenerateFileSchema.php index 9d014bf..56673af 100644 --- a/src/Commands/GenerateFileSchema.php +++ b/src/Commands/GenerateFileSchema.php @@ -21,7 +21,8 @@ class GenerateFileSchema extends Command name: $name, label: $name, fields: Collection::make(), - path: "", + disk: "lucent", + path: $name, groups: [] ); diff --git a/src/File/FileService.php b/src/File/FileService.php index 723bec1..d6e4bc6 100644 --- a/src/File/FileService.php +++ b/src/File/FileService.php @@ -14,6 +14,7 @@ use Lucent\LucentException; use Lucent\Record\FileData as RecordFile; use Lucent\Record\QueryRecord; use Lucent\Schema\FilesSchema; +use Lucent\Schema\Schema; use Spatie\ImageOptimizer\OptimizerChainFactory; class FileService @@ -65,7 +66,7 @@ class FileService ); } - $disk = $this->loadDisk(); + $disk = $this->loadDisk($schema); $path = $schema->path . "/" . $filename; $res = $disk->put( $path, @@ -108,22 +109,10 @@ class FileService return in_array($mimetype, $imageMimes); } - public function loadDisk(): Filesystem + public function loadDisk(Schema $schema): Filesystem { - return Storage::disk('lucent'); - return Storage::build([ - 'driver' => 'lucent', -// 'key' => config("filesystems.disks.s3.key"), -// 'secret' => config("filesystems.disks.s3.secret"), -// 'region' => config("filesystems.disks.s3.region"), -// 'bucket' => config("filesystems.disks.s3.bucket"), -// // 'url' => $schema->objectStorageUrl, -// 'endpoint' => $schema->objectStorageEndpoint, -// 'use_path_style_endpoint' => false, - 'visibility' => 'public', // now managed by aws policy - 'root' => storage_path('app/public'), - 'throw' => true, - ]); + return Storage::disk($schema->disk); + } private function checkDuplicate(string $schemaName, string $checksum, int $filesize): string @@ -155,7 +144,7 @@ class FileService $image->fit(300, 300); try { - $this->loadDisk()->put($thumbDir . $filename, $image->encode('webp', 75)); + $disk->put($thumbDir . $filename, $image->encode('webp', 75)); // $image->encode('webp', 75)->save($thumbDir . $filename); } catch (Exception $e) { logger($e->getMessage()); diff --git a/src/Http/Controller/FileController.php b/src/Http/Controller/FileController.php index f0e4523..b4b2ee0 100644 --- a/src/Http/Controller/FileController.php +++ b/src/Http/Controller/FileController.php @@ -35,8 +35,9 @@ class FileController extends Controller $templatePath = $request->route("any"); $filePath = str_replace($template."/", "", $templatePath); $record = $this->query->filter(["_file.path" => $filePath])->run()->records->first(); + $schema = $this->channelService->getSchema($record->schema); $this->imageService->file($record,$template); - $disk = $this->fileService->loadDisk(); + $disk = $this->fileService->loadDisk($schema->disk); return response()->file($disk->path("templates/".$templatePath)); } diff --git a/src/Http/web.php b/src/Http/web.php index 9e8ce92..e64ebf3 100644 --- a/src/Http/web.php +++ b/src/Http/web.php @@ -15,6 +15,7 @@ use Lucent\Http\Controller\SetupController; Route::get('/lucent/setup', [SetupController::class, 'setup']); Route::get('/storage/templates/{any}', [FileController::class, 'template'])->where('any', '.*'); +//Route::get('/storage/thumbs/{any}', [FileController::class, 'thumb'])->where('any', '.*'); Route::group([ 'middleware' => ['web'], diff --git a/src/Schema/FilesSchema.php b/src/Schema/FilesSchema.php index 5d24fb5..7605ba4 100644 --- a/src/Schema/FilesSchema.php +++ b/src/Schema/FilesSchema.php @@ -17,6 +17,7 @@ class FilesSchema implements Schema public string $name, public string $label, public Collection $fields, + public string $disk, public string $path, public array $groups, public bool $isEntry = false, diff --git a/src/Schema/SchemaService.php b/src/Schema/SchemaService.php index 390825c..fad9c0b 100644 --- a/src/Schema/SchemaService.php +++ b/src/Schema/SchemaService.php @@ -36,6 +36,7 @@ class SchemaService name: $schemaArr["name"], label: $schemaArr["label"], fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']), + disk: $schemaArr["disk"], path: $schemaArr["path"] ?? $schemaArr["name"], groups: $schemaArr["groups"] ?? [], isEntry: $schemaArr["isEntry"] ?? false,