refactor files
This commit is contained in:
@@ -21,7 +21,8 @@ class GenerateFileSchema extends Command
|
|||||||
name: $name,
|
name: $name,
|
||||||
label: $name,
|
label: $name,
|
||||||
fields: Collection::make(),
|
fields: Collection::make(),
|
||||||
path: "",
|
disk: "lucent",
|
||||||
|
path: $name,
|
||||||
groups: []
|
groups: []
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use Lucent\LucentException;
|
|||||||
use Lucent\Record\FileData as RecordFile;
|
use Lucent\Record\FileData as RecordFile;
|
||||||
use Lucent\Record\QueryRecord;
|
use Lucent\Record\QueryRecord;
|
||||||
use Lucent\Schema\FilesSchema;
|
use Lucent\Schema\FilesSchema;
|
||||||
|
use Lucent\Schema\Schema;
|
||||||
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
||||||
|
|
||||||
class FileService
|
class FileService
|
||||||
@@ -65,7 +66,7 @@ class FileService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$disk = $this->loadDisk();
|
$disk = $this->loadDisk($schema);
|
||||||
$path = $schema->path . "/" . $filename;
|
$path = $schema->path . "/" . $filename;
|
||||||
$res = $disk->put(
|
$res = $disk->put(
|
||||||
$path,
|
$path,
|
||||||
@@ -108,22 +109,10 @@ class FileService
|
|||||||
return in_array($mimetype, $imageMimes);
|
return in_array($mimetype, $imageMimes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadDisk(): Filesystem
|
public function loadDisk(Schema $schema): Filesystem
|
||||||
{
|
{
|
||||||
return Storage::disk('lucent');
|
return Storage::disk($schema->disk);
|
||||||
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,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkDuplicate(string $schemaName, string $checksum, int $filesize): string
|
private function checkDuplicate(string $schemaName, string $checksum, int $filesize): string
|
||||||
@@ -155,7 +144,7 @@ class FileService
|
|||||||
|
|
||||||
$image->fit(300, 300);
|
$image->fit(300, 300);
|
||||||
try {
|
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);
|
// $image->encode('webp', 75)->save($thumbDir . $filename);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
logger($e->getMessage());
|
logger($e->getMessage());
|
||||||
|
|||||||
@@ -35,8 +35,9 @@ class FileController extends Controller
|
|||||||
$templatePath = $request->route("any");
|
$templatePath = $request->route("any");
|
||||||
$filePath = str_replace($template."/", "", $templatePath);
|
$filePath = str_replace($template."/", "", $templatePath);
|
||||||
$record = $this->query->filter(["_file.path" => $filePath])->run()->records->first();
|
$record = $this->query->filter(["_file.path" => $filePath])->run()->records->first();
|
||||||
|
$schema = $this->channelService->getSchema($record->schema);
|
||||||
$this->imageService->file($record,$template);
|
$this->imageService->file($record,$template);
|
||||||
$disk = $this->fileService->loadDisk();
|
$disk = $this->fileService->loadDisk($schema->disk);
|
||||||
return response()->file($disk->path("templates/".$templatePath));
|
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('/lucent/setup', [SetupController::class, 'setup']);
|
||||||
Route::get('/storage/templates/{any}', [FileController::class, 'template'])->where('any', '.*');
|
Route::get('/storage/templates/{any}', [FileController::class, 'template'])->where('any', '.*');
|
||||||
|
//Route::get('/storage/thumbs/{any}', [FileController::class, 'thumb'])->where('any', '.*');
|
||||||
|
|
||||||
Route::group([
|
Route::group([
|
||||||
'middleware' => ['web'],
|
'middleware' => ['web'],
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class FilesSchema implements Schema
|
|||||||
public string $name,
|
public string $name,
|
||||||
public string $label,
|
public string $label,
|
||||||
public Collection $fields,
|
public Collection $fields,
|
||||||
|
public string $disk,
|
||||||
public string $path,
|
public string $path,
|
||||||
public array $groups,
|
public array $groups,
|
||||||
public bool $isEntry = false,
|
public bool $isEntry = false,
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class SchemaService
|
|||||||
name: $schemaArr["name"],
|
name: $schemaArr["name"],
|
||||||
label: $schemaArr["label"],
|
label: $schemaArr["label"],
|
||||||
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']),
|
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']),
|
||||||
|
disk: $schemaArr["disk"],
|
||||||
path: $schemaArr["path"] ?? $schemaArr["name"],
|
path: $schemaArr["path"] ?? $schemaArr["name"],
|
||||||
groups: $schemaArr["groups"] ?? [],
|
groups: $schemaArr["groups"] ?? [],
|
||||||
isEntry: $schemaArr["isEntry"] ?? false,
|
isEntry: $schemaArr["isEntry"] ?? false,
|
||||||
|
|||||||
Reference in New Issue
Block a user