get and browse team folders shared with me

This commit is contained in:
Čarodej
2021-09-24 16:56:18 +02:00
parent 37cad85a86
commit 07b249346b
10 changed files with 450 additions and 59 deletions
@@ -1,9 +1,8 @@
<?php
namespace Domain\Files\Controllers\FileAccess;
use Illuminate\Http\Request;
use Gate;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Domain\Files\Models\File as UserFile;
use Domain\Files\Actions\DownloadFileAction;
use Domain\Traffic\Actions\RecordDownloadAction;
@@ -14,28 +13,26 @@ class GetFileController extends Controller
public function __construct(
private RecordDownloadAction $recordDownload,
private DownloadFileAction $downloadFile,
) {
}
) {}
/**
* Get file
*/
public function __invoke(
Request $request,
string $filename,
): BinaryFileResponse {
// Get file record
$file = UserFile::withTrashed()
->where('user_id', Auth::id())
->where('basename', $filename)
->firstOrFail();
if (! Gate::any(['can-edit', 'can-visit'], [$file, null])) {
abort(403, 'Access Denied');
}
// Store user download size
($this->recordDownload)(
file_size: (int) $file->getRawOriginal('filesize'),
user_id: Auth::id(),
user_id: $file->user_id,
);
return ($this->downloadFile)($file, Auth::id());
return ($this->downloadFile)($file, $file->user_id);
}
}
@@ -1,9 +1,9 @@
<?php
namespace Domain\Files\Controllers\FileAccess;
use Gate;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Domain\Files\Models\File as UserFile;
use Domain\Files\Actions\DownloadThumbnailAction;
use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -13,21 +13,21 @@ class GetThumbnailController extends Controller
{
public function __construct(
private DownloadThumbnailAction $downloadThumbnail,
) {
}
) {}
/**
* Get image thumbnail
*/
public function __invoke(
Request $request,
string $filename,
): FileNotFoundException | StreamedResponse {
$file = UserFile::withTrashed()
->whereUserId(Auth::id())
->whereThumbnail($filename)
->where('thumbnail', $filename)
->firstOrFail();
return ($this->downloadThumbnail)($file, Auth::id());
if (! Gate::any(['can-edit', 'can-visit'], [$file, null])) {
abort(403, 'Access Denied');
}
return ($this->downloadThumbnail)($file, $file->user_id);
}
}