diff --git a/app/Http/Controllers/Sharing/BrowseShareController.php b/app/Http/Controllers/Sharing/BrowseShareController.php index 13cb7ab4..ec0e8df2 100644 --- a/app/Http/Controllers/Sharing/BrowseShareController.php +++ b/app/Http/Controllers/Sharing/BrowseShareController.php @@ -19,28 +19,6 @@ class BrowseShareController extends Controller $this->helper = resolve(HelperService::class); } - /** - * Get folders and files - * - * @param $id - * @param $shared - * @return array - */ - private function get_items($id, $shared): array - { - $folders = Folder::where('user_id', $shared->user_id) - ->where('parent_id', $id) - ->sortable() - ->get(); - - $files = File::where('user_id', $shared->user_id) - ->where('folder_id', $id) - ->sortable() - ->get(); - - return [$folders, $files]; - } - /** * Search public files * @@ -146,11 +124,11 @@ class BrowseShareController extends Controller $this->helper->check_item_access($id, $shared); // Get files and folders - list($folders, $files) = $this->get_items($id, $shared); + list($folders, $files) = $this->helper->get_items_under_shared_by_folder_id($id, $shared); // Set thumbnail links for public files - $files->map(function ($item) use ($token) { - $item->setPublicUrl($token); + $files->map(function ($file) use ($token) { + $file->setPublicUrl($token); }); // Collect folders and files to single array diff --git a/app/Http/Controllers/Sharing/FileSharingController.php b/app/Http/Controllers/Sharing/FileSharingController.php index 6ead99ab..eaa83ea9 100644 --- a/app/Http/Controllers/Sharing/FileSharingController.php +++ b/app/Http/Controllers/Sharing/FileSharingController.php @@ -158,11 +158,10 @@ class FileSharingController extends Controller // Check if user can get directory $this->helper->check_item_access($id, $shared); - // Get files and folders - list($folders, $files) = $this->get_items($id, $shared); - // Collect folders and files to single array - return collect([$folders, $files])->collapse(); + return collect( + $this->helper->get_items_under_shared_by_folder_id($id, $shared) + )->collapse(); } /** diff --git a/app/Http/Controllers/Sharing/SharedFileAccessContentController.php b/app/Http/Controllers/Sharing/SharedFileAccessContentController.php index e079b776..1e5b46ac 100644 --- a/app/Http/Controllers/Sharing/SharedFileAccessContentController.php +++ b/app/Http/Controllers/Sharing/SharedFileAccessContentController.php @@ -73,7 +73,7 @@ class SharedFileAccessContentController extends Controller ->firstOrFail(); // Check file access - $this->helper->check_file_access($shared, $file); + $this->helper->check_guest_access_to_shared_items($shared, $file); // Store user download size $shared @@ -109,7 +109,7 @@ class SharedFileAccessContentController extends Controller ->firstOrFail(); // Check file access - $this->helper->check_file_access($shared, $file); + $this->helper->check_guest_access_to_shared_items($shared, $file); // Store user download size $shared diff --git a/app/Services/FileManagerService.php b/app/Services/FileManagerService.php index 5eda3ab7..b7889286 100644 --- a/app/Services/FileManagerService.php +++ b/app/Services/FileManagerService.php @@ -413,7 +413,7 @@ class FileManagerService $this->helper->check_user_storage_capacity($user_id, $file_size, $temp_filename); // Create thumbnail - $thumbnail = $this->helper->get_image_thumbnail('chunks/' . $temp_filename, $disk_file_name, $user_id); + $thumbnail = $this->helper->create_image_thumbnail('chunks/' . $temp_filename, $disk_file_name, $user_id); // Move finished file from chunk to file-manager directory $disk_local->move('chunks/' . $temp_filename, "files/$user_id/$disk_file_name"); @@ -422,7 +422,7 @@ class FileManagerService if (!is_storage_driver(['local'])) { // Move file to external storage service - $this->helper->move_to_external_storage($disk_file_name, $thumbnail); + $this->helper->move_file_to_external_storage($disk_file_name, $thumbnail); } // Store user upload size diff --git a/app/Services/HelperService.php b/app/Services/HelperService.php index 1e47e020..3d618c8a 100644 --- a/app/Services/HelperService.php +++ b/app/Services/HelperService.php @@ -2,6 +2,7 @@ namespace App\Services; +use App\Models\File; use App\Models\Folder; use Aws\Exception\MultipartUploadException; use Aws\S3\MultipartUploader; @@ -75,7 +76,7 @@ class HelperService * @param $shared * @param $file */ - public function check_file_access($shared, $file): void + public function check_guest_access_to_shared_items($shared, $file): void { // Check by parent folder permission if ($shared->type === 'folder') { @@ -121,7 +122,7 @@ class HelperService * @param string $filename * @param string|null $thumbnail */ - function move_to_external_storage($filename, $thumbnail = null): void + function move_file_to_external_storage($filename, $thumbnail = null): void { $disk_local = Storage::disk('local'); @@ -188,7 +189,7 @@ class HelperService * @param string $user_id * @return string|null */ - function get_image_thumbnail($file_path, $filename, $user_id) + function create_image_thumbnail($file_path, $filename, $user_id) { $local_disk = Storage::disk('local'); @@ -251,6 +252,8 @@ class HelperService } /** + * Get image thumbnail for browser + * * @param $file * @param $user_id * @return mixed @@ -266,4 +269,26 @@ class HelperService // Return image thumbnail return Storage::download($path, $file->getRawOriginal('thumbnail')); } + + /** + * Get all folders and files under the share record + * + * @param $id + * @param $shared + * @return array + */ + function get_items_under_shared_by_folder_id($id, $shared): array + { + $folders = Folder::where('user_id', $shared->user_id) + ->where('parent_id', $id) + ->sortable() + ->get(); + + $files = File::where('user_id', $shared->user_id) + ->where('folder_id', $id) + ->sortable() + ->get(); + + return [$folders, $files]; + } } \ No newline at end of file