wip stograge

This commit is contained in:
2024-09-20 13:39:45 +03:00
parent 32c8378020
commit 6d15591601
7 changed files with 26 additions and 9 deletions
+3 -4
View File
@@ -1,14 +1,13 @@
export function imgurl(channel,record) { export function imgurl(channel,record) {
if (record._file.mime === "image/svg+xml") { if (record._file.mime === "image/svg+xml") {
return fileurl(channel, record); return fileurl(channel, record);
} }
return channel.filesUrl + `/thumbs/${record._file.path}`; return channel.filesUrl + `/thumbs/${record._file.disk}/${record._file.path}`;
} }
export function fileurl(channel, record) { export function fileurl(channel, record) {
return channel.filesUrl + `/${record._file.path}`; return channel.filesUrl + `/${record._file.disk}/${record._file.path}`;
} }
export function htmlurl(channel,record, preset) { export function htmlurl(channel,record, preset) {
@@ -19,7 +18,7 @@ export function htmlurl(channel,record, preset) {
if (record._file.width > 0) { if (record._file.width > 0) {
let presetUrl = url; let presetUrl = url;
if (preset) { if (preset) {
presetUrl = channel.filesUrl + `/templates/${preset}/${record._file.path}`; presetUrl = channel.filesUrl + `/templates/${preset}/${record._file.disk}/${record._file.path}`;
} }
html = `<img src="${presetUrl}" alt="${record._file.path}" />` html = `<img src="${presetUrl}" alt="${record._file.path}" />`
+3 -2
View File
@@ -85,6 +85,7 @@ class FileService
originalName: $originalFilename, originalName: $originalFilename,
mime: $mimetype, mime: $mimetype,
path: $path, path: $path,
disk: $schema->disk,
size: $file->getSize(), size: $file->getSize(),
width: $width, width: $width,
height: $height, height: $height,
@@ -109,9 +110,9 @@ class FileService
return in_array($mimetype, $imageMimes); return in_array($mimetype, $imageMimes);
} }
public function loadDisk(Schema $schema): Filesystem public function loadDisk(Schema|string $schema): Filesystem
{ {
return Storage::disk($schema->disk); return Storage::disk($schema->disk ?? $schema);
} }
+14
View File
@@ -41,6 +41,20 @@ class FileController extends Controller
return response()->file($disk->path("templates/".$templatePath)); return response()->file($disk->path("templates/".$templatePath));
} }
public function original(Request $request, string $disk)
{
$imagePath = $request->route("any");
$disk = $this->fileService->loadDisk($disk);
return response()->file($disk->path($imagePath));
}
public function thumb(Request $request, string $disk)
{
$imagePath = "thumbs/".$request->route("any");
$disk = $this->fileService->loadDisk($disk);
return response()->file($disk->path($imagePath));
}
public function download(Request $request) public function download(Request $request)
{ {
$disk = $this->fileService->loadDisk(); $disk = $this->fileService->loadDisk();
+2 -1
View File
@@ -15,7 +15,8 @@ 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::get('/lfs-{disk}/thumbs/{any}', [FileController::class, 'thumb'])->where('any', '.*');
Route::get('/lfs-{disk}/{disk}/{any}', [FileController::class, 'original'])->where('any', '.*');
Route::group([ Route::group([
'middleware' => ['web'], 'middleware' => ['web'],
+2
View File
@@ -10,6 +10,7 @@ class FileData
public readonly string $originalName, public readonly string $originalName,
public readonly string $mime, public readonly string $mime,
public readonly string $path, public readonly string $path,
public readonly string $disk,
public readonly int $size, public readonly int $size,
public readonly int $width, public readonly int $width,
public readonly int $height, public readonly int $height,
@@ -24,6 +25,7 @@ class FileData
originalName: data_get($data, "originalName"), originalName: data_get($data, "originalName"),
mime: data_get($data, "mime"), mime: data_get($data, "mime"),
path: data_get($data, "path"), path: data_get($data, "path"),
disk: data_get($data, "disk", "lucent"),
size: data_get($data, "size"), size: data_get($data, "size"),
width: data_get($data, "width"), width: data_get($data, "width"),
height: data_get($data, "height"), height: data_get($data, "height"),
+1 -1
View File
@@ -54,7 +54,7 @@ class Record implements JsonSerializable
$file = json_decode($data->_file, true); $file = json_decode($data->_file, true);
if (!empty($file)) { if (!empty($file)) {
$file = new FileData(...$file); $file = FileData::fromArray($file);
} else { } else {
$file = null; $file = null;
} }
+1 -1
View File
@@ -90,7 +90,7 @@ class RevisionRepo
$file = json_decode($data->_file, true); $file = json_decode($data->_file, true);
if (!empty($file)) { if (!empty($file)) {
$file = new FileData(...$file); $file = FileData::fromArray($file);
} else { } else {
$file = null; $file = null;
} }