controller refactoring part 23

This commit is contained in:
Peter Papp
2021-07-21 18:00:45 +02:00
parent 9fb9b8a1b0
commit 91cb795054
18 changed files with 360 additions and 312 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace Domain\Files\Controllers\FileAccess;
use App\Http\Controllers\Controller;
use Domain\Files\Models\File as UserFile;
use Domain\Sharing\Models\Share;
use Domain\Traffic\Actions\RecordDownloadAction;
use Symfony\Component\HttpFoundation\StreamedResponse;
/**
* Get public image thumbnail
*/
class VisitorGetThumbnailController extends Controller
{
public function __construct(
private RecordDownloadAction $recordDownload,
) {}
public function __invoke(
$filename,
Share $shared,
): StreamedResponse {
// Check ability to access protected share files
$this->helper->check_protected_share_record($shared);
// Get file record
$file = UserFile::where('user_id', $shared->user_id)
->where('thumbnail', $filename)
->firstOrFail();
// Check file access
$this->helper->check_guest_access_to_shared_items($shared, $file);
// Store user download size
($this->recordDownload)(
file_size: (int) $file->getRawOriginal('filesize'),
user_id: $shared->user_id,
);
return $this->helper->download_thumbnail_file($file, $shared->user_id);
}
}