refactor files
This commit is contained in:
@@ -21,7 +21,8 @@ class GenerateFileSchema extends Command
|
||||
name: $name,
|
||||
label: $name,
|
||||
fields: Collection::make(),
|
||||
path: "",
|
||||
disk: "lucent",
|
||||
path: $name,
|
||||
groups: []
|
||||
);
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user