diff --git a/front/js/svelte/files/imageserver.js b/front/js/svelte/files/imageserver.js index eae0151..53313c0 100644 --- a/front/js/svelte/files/imageserver.js +++ b/front/js/svelte/files/imageserver.js @@ -1,14 +1,13 @@ export function imgurl(channel,record) { - if (record._file.mime === "image/svg+xml") { 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) { - return channel.filesUrl + `/${record._file.path}`; + return channel.filesUrl + `/${record._file.disk}/${record._file.path}`; } export function htmlurl(channel,record, preset) { @@ -19,7 +18,7 @@ export function htmlurl(channel,record, preset) { if (record._file.width > 0) { let presetUrl = url; if (preset) { - presetUrl = channel.filesUrl + `/templates/${preset}/${record._file.path}`; + presetUrl = channel.filesUrl + `/templates/${preset}/${record._file.disk}/${record._file.path}`; } html = `${record._file.path}` diff --git a/src/File/FileService.php b/src/File/FileService.php index d6e4bc6..06e4cb6 100644 --- a/src/File/FileService.php +++ b/src/File/FileService.php @@ -85,6 +85,7 @@ class FileService originalName: $originalFilename, mime: $mimetype, path: $path, + disk: $schema->disk, size: $file->getSize(), width: $width, height: $height, @@ -109,9 +110,9 @@ class FileService 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); } diff --git a/src/Http/Controller/FileController.php b/src/Http/Controller/FileController.php index b4b2ee0..6fe4ed3 100644 --- a/src/Http/Controller/FileController.php +++ b/src/Http/Controller/FileController.php @@ -41,6 +41,20 @@ class FileController extends Controller 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) { $disk = $this->fileService->loadDisk(); diff --git a/src/Http/web.php b/src/Http/web.php index e64ebf3..dceec26 100644 --- a/src/Http/web.php +++ b/src/Http/web.php @@ -15,7 +15,8 @@ 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::get('/lfs-{disk}/thumbs/{any}', [FileController::class, 'thumb'])->where('any', '.*'); +Route::get('/lfs-{disk}/{disk}/{any}', [FileController::class, 'original'])->where('any', '.*'); Route::group([ 'middleware' => ['web'], diff --git a/src/Record/FileData.php b/src/Record/FileData.php index e689b67..1a14738 100644 --- a/src/Record/FileData.php +++ b/src/Record/FileData.php @@ -10,6 +10,7 @@ class FileData public readonly string $originalName, public readonly string $mime, public readonly string $path, + public readonly string $disk, public readonly int $size, public readonly int $width, public readonly int $height, @@ -24,6 +25,7 @@ class FileData originalName: data_get($data, "originalName"), mime: data_get($data, "mime"), path: data_get($data, "path"), + disk: data_get($data, "disk", "lucent"), size: data_get($data, "size"), width: data_get($data, "width"), height: data_get($data, "height"), diff --git a/src/Record/Record.php b/src/Record/Record.php index ce14f3a..bcc1947 100644 --- a/src/Record/Record.php +++ b/src/Record/Record.php @@ -54,7 +54,7 @@ class Record implements JsonSerializable $file = json_decode($data->_file, true); if (!empty($file)) { - $file = new FileData(...$file); + $file = FileData::fromArray($file); } else { $file = null; } diff --git a/src/Revision/RevisionRepo.php b/src/Revision/RevisionRepo.php index 7412d62..697d27d 100644 --- a/src/Revision/RevisionRepo.php +++ b/src/Revision/RevisionRepo.php @@ -90,7 +90,7 @@ class RevisionRepo $file = json_decode($data->_file, true); if (!empty($file)) { - $file = new FileData(...$file); + $file = FileData::fromArray($file); } else { $file = null; }