diff --git a/app/Http/Controllers/FileController.php b/app/Http/Controllers/FileController.php new file mode 100644 index 0000000..316b79a --- /dev/null +++ b/app/Http/Controllers/FileController.php @@ -0,0 +1,47 @@ +vault); + + if (!$request->has('path')) { + abort(404); + } + + $path = $request->path; + + if (!Str::of($request->path)->startsWith('/') && $request->has('node')) { + $node = $vault->nodes()->findOrFail($request->node); + + if ($node->vault_id != $vault->id) { + abort(404); + } + + $currentPath = $node->ancestorsAndSelf()->get()->last()->full_path; + $path = (new ResolveTwoPaths())->handle($currentPath, $request->path); + } + + $node = (new GetVaultNodeFromPath())->handle($vault->id, $path); + $relativePath = (new GetPathFromVaultNode())->handle($node); + $absolutePath = Storage::disk('local')->path($relativePath); + + ob_end_clean(); + return response()->file($absolutePath); + } +} diff --git a/routes/web.php b/routes/web.php index cc4e6bf..996050e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,12 +5,15 @@ use App\Livewire\Auth\Register; use App\Livewire\Auth\ResetPassword; use App\Livewire\Auth\ForgotPassword; use Illuminate\Support\Facades\Route; +use App\Http\Controllers\FileController; use App\Livewire\Vault\Show as VaultShow; use App\Livewire\Vault\Index as VaultIndex; Route::middleware('auth')->group(function () { Route::get('vaults', VaultIndex::class)->name('vaults.index'); Route::get('vaults/{vault}', VaultShow::class)->name('vaults.show'); + + Route::get('files/{vault}', [FileController::class, 'show'])->name('files.show'); }); Route::middleware('guest')->group(function () {