mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-03 12:55:57 +00:00
get and browse team folders shared with me
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Teams\Controllers;
|
||||
|
||||
use Domain\Files\Resources\FilesCollection;
|
||||
use Domain\Folders\Resources\FolderCollection;
|
||||
use Domain\Folders\Resources\FolderResource;
|
||||
use Str;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Folders\Models\Folder;
|
||||
@@ -11,43 +15,35 @@ class BrowseSharedWithMeController
|
||||
{
|
||||
public function __invoke($id): array
|
||||
{
|
||||
$rootId = Str::isUuid($id) ? $id : null;
|
||||
$requestedFolder = Str::isUuid($id) ? Folder::findOrFail($rootId) : null;
|
||||
$id = Str::isUuid($id) ? $id : null;
|
||||
|
||||
$relations = [
|
||||
'parent:id,name',
|
||||
'shared:token,id,item_id,permission,is_protected,expire_in',
|
||||
];
|
||||
|
||||
if ($rootId) {
|
||||
$folders = Folder::with($relations)
|
||||
->where('id', $id)
|
||||
if ($id) {
|
||||
$folders = Folder::with(['parent:id,name'])
|
||||
->where('parent_id', $id)
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
$files = File::with($relations)
|
||||
$files = File::with(['parent:id,name'])
|
||||
->where('parent_id', $id)
|
||||
->sortable()
|
||||
->get();
|
||||
}
|
||||
|
||||
if (! $rootId) {
|
||||
$folderIds = DB::table('team_folder_members')
|
||||
if (!$id) {
|
||||
$sharedFolderIds = DB::table('team_folder_members')
|
||||
->where('user_id', Auth::id())
|
||||
->pluck('parent_id');
|
||||
|
||||
$folders = Folder::with($relations)
|
||||
->whereIn('id', $folderIds)
|
||||
$folders = Folder::whereIn('id', $sharedFolderIds)
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
$files = [];
|
||||
}
|
||||
|
||||
// Collect folders and files to single array
|
||||
return [
|
||||
'content' => collect([$folders, $files])->collapse(),
|
||||
'folder' => $requestedFolder,
|
||||
'root' => $id ? new FolderResource(Folder::findOrFail($id)) : null,
|
||||
'folders' => new FolderCollection($folders),
|
||||
'files' => isset($files) ? new FilesCollection($files) : new FilesCollection([]),
|
||||
'teamFolder' => $id ? new FolderResource(Folder::findOrFail($id)->getLatestParent()) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user