controller refactoring part 24

This commit is contained in:
Peter Papp
2021-07-21 18:46:55 +02:00
parent 54f1f4c9a8
commit 6d8a7a429c
29 changed files with 561 additions and 209 deletions

View File

@@ -14,7 +14,8 @@ class GetFileController extends Controller
public function __construct(
private RecordDownloadAction $recordDownload,
private DownloadFileAction $downloadFile,
) {}
) {
}
/**
* Get file

View File

@@ -1,12 +1,14 @@
<?php
namespace Domain\Files\Controllers\FileAccess;
use Domain\Files\Models\File;
use Domain\Sharing\Models\Share;
use App\Http\Controllers\Controller;
use Domain\Files\Models\File as UserFile;
use Domain\Files\Actions\DownloadFileAction;
use Domain\Traffic\Actions\RecordDownloadAction;
use Domain\Sharing\Actions\ProtectShareRecordAction;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Domain\Sharing\Actions\VerifyAccessToItemWithinAction;
/**
* Get file public
@@ -16,6 +18,8 @@ class VisitorGetFileController extends Controller
public function __construct(
private DownloadFileAction $downloadFile,
private RecordDownloadAction $recordDownload,
private ProtectShareRecordAction $protectShareRecord,
private VerifyAccessToItemWithinAction $verifyAccessToItemWithin,
) {
}
@@ -24,15 +28,15 @@ class VisitorGetFileController extends Controller
Share $shared,
): BinaryFileResponse {
// Check ability to access protected share files
$this->helper->check_protected_share_record($shared);
($this->protectShareRecord)($shared);
// Get file record
$file = UserFile::where('user_id', $shared->user_id)
$file = File::where('user_id', $shared->user_id)
->where('basename', $filename)
->firstOrFail();
// Check file access
$this->helper->check_guest_access_to_shared_items($shared, $file);
($this->verifyAccessToItemWithin)($shared, $file);
// Store user download size
($this->recordDownload)(
@@ -40,6 +44,7 @@ class VisitorGetFileController extends Controller
user_id: $shared->user_id,
);
// Finally download file
return ($this->downloadFile)($file, $shared->user_id);
}
}

View File

@@ -6,7 +6,9 @@ use App\Http\Controllers\Controller;
use Domain\Files\Models\File as UserFile;
use Domain\Traffic\Actions\RecordDownloadAction;
use Domain\Files\Actions\DownloadThumbnailAction;
use Domain\Sharing\Actions\ProtectShareRecordAction;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Domain\Sharing\Actions\VerifyAccessToItemWithinAction;
/**
* Get public image thumbnail
@@ -16,6 +18,8 @@ class VisitorGetThumbnailController extends Controller
public function __construct(
private RecordDownloadAction $recordDownload,
private DownloadThumbnailAction $downloadThumbnail,
private ProtectShareRecordAction $protectShareRecord,
private VerifyAccessToItemWithinAction $verifyAccessToItemWithin,
) {
}
@@ -24,7 +28,7 @@ class VisitorGetThumbnailController extends Controller
Share $shared,
): StreamedResponse {
// Check ability to access protected share files
$this->helper->check_protected_share_record($shared);
($this->protectShareRecord)($shared);
// Get file record
$file = UserFile::where('user_id', $shared->user_id)
@@ -32,7 +36,7 @@ class VisitorGetThumbnailController extends Controller
->firstOrFail();
// Check file access
$this->helper->check_guest_access_to_shared_items($shared, $file);
($this->verifyAccessToItemWithin)($shared, $file);
// Store user download size
($this->recordDownload)(
@@ -40,6 +44,7 @@ class VisitorGetThumbnailController extends Controller
user_id: $shared->user_id,
);
// Finally download thumbnail
return ($this->downloadThumbnail)($file, $shared->user_id);
}
}