mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-13 16:55:01 +00:00
Classes refactored
This commit is contained in:
@@ -14,113 +14,6 @@ use App\Models\Share;
|
||||
|
||||
class BrowseController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Get trashed files
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function trash()
|
||||
{
|
||||
// Get user id
|
||||
$user_id = Auth::id();
|
||||
|
||||
// Get folders and files
|
||||
$folders_trashed = Folder::onlyTrashed()
|
||||
->with(['trashed_folders', 'parent'])
|
||||
->where('user_id', $user_id)
|
||||
->get(['parent_id', 'id', 'name']);
|
||||
|
||||
$folders = Folder::onlyTrashed()
|
||||
->with(['parent'])
|
||||
->where('user_id', $user_id)
|
||||
->whereIn('id', filter_folders_ids($folders_trashed))
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
// Get files trashed
|
||||
$files_trashed = File::onlyTrashed()
|
||||
->with(['parent'])
|
||||
->where('user_id', $user_id)
|
||||
->whereNull('folder_id')
|
||||
->orWhereNotIn('folder_id', array_values(array_unique(recursiveFind($folders_trashed->toArray(), 'id'))))
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
// Collect folders and files to single array
|
||||
return collect([$folders, $files_trashed])->collapse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user shared items
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function shared()
|
||||
{
|
||||
// Get user
|
||||
$user_id = Auth::id();
|
||||
|
||||
// Get shared folders and files
|
||||
$folder_ids = Share::where('user_id', $user_id)
|
||||
->where('type', 'folder')
|
||||
->pluck('item_id');
|
||||
|
||||
$file_ids = Share::where('user_id', $user_id)
|
||||
->where('type', '!=', 'folder')
|
||||
->pluck('item_id');
|
||||
|
||||
// Get folders and files
|
||||
$folders = Folder::with(['parent', 'shared:token,id,item_id,permission,is_protected,expire_in'])
|
||||
->where('user_id', $user_id)
|
||||
->whereIn('id', $folder_ids)
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
$files = File::with(['parent', 'shared:token,id,item_id,permission,is_protected,expire_in'])
|
||||
->where('user_id', $user_id)
|
||||
->whereIn('id', $file_ids)
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
// Collect folders and files to single array
|
||||
return collect([$folders, $files])->collapse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest user uploads
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function latest()
|
||||
{
|
||||
$user = User::with(['latest_uploads' => function ($query) {
|
||||
$query->sortable(['created_at' => 'desc']);
|
||||
}])
|
||||
->where('id', Auth::id())
|
||||
->first();
|
||||
|
||||
return $user->latest_uploads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get participant uploads
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function participant_uploads()
|
||||
{
|
||||
|
||||
// Get User
|
||||
$uploads = File::with(['parent'])
|
||||
->where('user_id', Auth::id())
|
||||
->whereUserScope('editor')
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
return $uploads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get directory with files
|
||||
*
|
||||
@@ -166,6 +59,108 @@ class BrowseController extends Controller
|
||||
->collapse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest user uploads
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function latest()
|
||||
{
|
||||
$user = User::with(['latest_uploads' => function ($query) {
|
||||
$query->sortable(['created_at' => 'desc']);
|
||||
}])
|
||||
->where('id', Auth::id())
|
||||
->first();
|
||||
|
||||
return $user->latest_uploads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get trashed files
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function trash()
|
||||
{
|
||||
$user_id = Auth::id();
|
||||
|
||||
// Get folders and files
|
||||
$folders_trashed = Folder::onlyTrashed()
|
||||
->with(['trashed_folders', 'parent'])
|
||||
->where('user_id', $user_id)
|
||||
->get(['parent_id', 'id', 'name']);
|
||||
|
||||
$folders = Folder::onlyTrashed()
|
||||
->with(['parent'])
|
||||
->where('user_id', $user_id)
|
||||
->whereIn('id', filter_folders_ids($folders_trashed))
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
// Get files trashed
|
||||
$files_trashed = File::onlyTrashed()
|
||||
->with(['parent'])
|
||||
->where('user_id', $user_id)
|
||||
->whereNull('folder_id')
|
||||
->orWhereNotIn('folder_id', array_values(array_unique(recursiveFind($folders_trashed->toArray(), 'id'))))
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
// Collect folders and files to single array
|
||||
return collect([$folders, $files_trashed])
|
||||
->collapse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user shared items
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function shared()
|
||||
{
|
||||
$user_id = Auth::id();
|
||||
|
||||
// Get shared folders and files
|
||||
$folder_ids = Share::where('user_id', $user_id)
|
||||
->where('type', 'folder')
|
||||
->pluck('item_id');
|
||||
|
||||
$file_ids = Share::where('user_id', $user_id)
|
||||
->where('type', '!=', 'folder')
|
||||
->pluck('item_id');
|
||||
|
||||
// Get folders and files
|
||||
$folders = Folder::with(['parent', 'shared:token,id,item_id,permission,is_protected,expire_in'])
|
||||
->where('user_id', $user_id)
|
||||
->whereIn('id', $folder_ids)
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
$files = File::with(['parent', 'shared:token,id,item_id,permission,is_protected,expire_in'])
|
||||
->where('user_id', $user_id)
|
||||
->whereIn('id', $file_ids)
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
// Collect folders and files to single array
|
||||
return collect([$folders, $files])
|
||||
->collapse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get participant uploads
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function participant_uploads()
|
||||
{
|
||||
return File::with(['parent'])
|
||||
->where('user_id', Auth::id())
|
||||
->whereUserScope('editor')
|
||||
->sortable()
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user folder tree
|
||||
*
|
||||
@@ -190,24 +185,26 @@ class BrowseController extends Controller
|
||||
/**
|
||||
* Search files
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
* @param SearchRequest $request
|
||||
* @return Collection
|
||||
*/
|
||||
public function search(SearchRequest $request)
|
||||
{
|
||||
// Get user
|
||||
$user_id = Auth::id();
|
||||
|
||||
$query = remove_accents($request->input('query'));
|
||||
|
||||
// Search files id db
|
||||
$searched_files = File::search($query)
|
||||
->where('user_id', $user_id)
|
||||
->get();
|
||||
|
||||
$searched_folders = Folder::search($query)
|
||||
->where('user_id', $user_id)
|
||||
->get();
|
||||
|
||||
// Collect folders and files to single array
|
||||
return collect([$searched_folders, $searched_files])->collapse();
|
||||
return collect([$searched_folders, $searched_files])
|
||||
->collapse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,37 @@ class BrowseShareController extends Controller
|
||||
$this->helper = resolve(HelperService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse public folders
|
||||
*
|
||||
* @param $id
|
||||
* @param $token
|
||||
* @return Collection
|
||||
*/
|
||||
public function get_public_folders($id, $token)
|
||||
{
|
||||
$shared = get_shared($token);
|
||||
|
||||
// Abort if folder is protected
|
||||
if ((int)$shared->is_protected) {
|
||||
abort(403, "Sorry, you don't have permission");
|
||||
}
|
||||
|
||||
// Check if user can get directory
|
||||
$this->helper->check_item_access($id, $shared);
|
||||
|
||||
// Get files and folders
|
||||
list($folders, $files) = $this->helper->get_items_under_shared_by_folder_id($id, $shared);
|
||||
|
||||
// Set thumbnail links for public files
|
||||
$files->map(function ($file) use ($token) {
|
||||
$file->setPublicUrl($token);
|
||||
});
|
||||
|
||||
// Collect folders and files to single array
|
||||
return collect([$folders, $files])->collapse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Search public files
|
||||
*
|
||||
@@ -77,11 +108,11 @@ class BrowseShareController extends Controller
|
||||
/**
|
||||
* Get navigation tree
|
||||
*
|
||||
* @param $token
|
||||
* @return array
|
||||
*/
|
||||
public function get_public_navigation_tree($token)
|
||||
{
|
||||
// Get sharing record
|
||||
$shared = get_shared($token);
|
||||
|
||||
// Check if user can get directory
|
||||
@@ -103,35 +134,4 @@ class BrowseShareController extends Controller
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse public folders
|
||||
*
|
||||
* @param $id
|
||||
* @param $token
|
||||
* @return Collection
|
||||
*/
|
||||
public function get_public_folders($id, $token)
|
||||
{
|
||||
$shared = get_shared($token);
|
||||
|
||||
// Abort if folder is protected
|
||||
if ((int)$shared->is_protected) {
|
||||
abort(403, "Sorry, you don't have permission");
|
||||
}
|
||||
|
||||
// Check if user can get directory
|
||||
$this->helper->check_item_access($id, $shared);
|
||||
|
||||
// Get files and folders
|
||||
list($folders, $files) = $this->helper->get_items_under_shared_by_folder_id($id, $shared);
|
||||
|
||||
// Set thumbnail links for public files
|
||||
$files->map(function ($file) use ($token) {
|
||||
$file->setPublicUrl($token);
|
||||
});
|
||||
|
||||
// Collect folders and files to single array
|
||||
return collect([$folders, $files])->collapse();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ use App\Services\HelperService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class SharedFileAccessContentController extends Controller
|
||||
class FileSharedAccessController extends Controller
|
||||
{
|
||||
private $helper;
|
||||
|
||||
+1
-2
@@ -9,7 +9,6 @@ use App\Models\Share;
|
||||
use App\Models\Setting;
|
||||
use App\Services\HelperService;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -19,7 +18,7 @@ use App\Models\File;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class FileSharingController extends Controller
|
||||
class ServeSharedController extends Controller
|
||||
{
|
||||
private $helper;
|
||||
|
||||
+5
-5
@@ -8,7 +8,7 @@ use App\Http\Controllers\FileManager\EditItemsController;
|
||||
use App\Http\Controllers\FileManager\FavouriteController;
|
||||
use App\Http\Controllers\FileManager\ShareController;
|
||||
use App\Http\Controllers\FileManager\TrashController;
|
||||
use App\Http\Controllers\Sharing\FileSharingController;
|
||||
use App\Http\Controllers\Sharing\ServeSharedController;
|
||||
|
||||
// Pages
|
||||
Route::get('/content', [AppFunctionsController::class, 'get_setting_columns']);
|
||||
@@ -62,10 +62,10 @@ Route::group(['middleware' => ['auth:api', 'auth.shared', 'scope:visitor,editor'
|
||||
|
||||
// Browse folders & files
|
||||
// TODO: tests for private shared content
|
||||
Route::get('/folders/{unique_id}/private', [FileSharingController::class, 'get_private_folders']);
|
||||
Route::get('/navigation/private', [FileSharingController::class, 'get_private_navigation_tree']);
|
||||
Route::get('/search/private', [FileSharingController::class, 'search_private']);
|
||||
Route::get('/files/private', [FileSharingController::class, 'file_private']);
|
||||
Route::get('/folders/{unique_id}/private', [ServeSharedController::class, 'get_private_folders']);
|
||||
Route::get('/navigation/private', [ServeSharedController::class, 'get_private_navigation_tree']);
|
||||
Route::get('/search/private', [ServeSharedController::class, 'search_private']);
|
||||
Route::get('/files/private', [ServeSharedController::class, 'file_private']);
|
||||
});
|
||||
|
||||
// User master,editor routes
|
||||
|
||||
+4
-4
@@ -2,15 +2,15 @@
|
||||
|
||||
// Get avatars and system images
|
||||
use App\Http\Controllers\FileManager\FileAccessController;
|
||||
use App\Http\Controllers\Sharing\SharedFileAccessContentController;
|
||||
use App\Http\Controllers\Sharing\FileSharedAccessController;
|
||||
|
||||
Route::get('/avatars/{avatar}', [FileAccessController::class, 'get_avatar'])->name('avatar');
|
||||
Route::get('/system/{image}', [FileAccessController::class, 'get_system_image']);
|
||||
|
||||
// Get public thumbnails and files
|
||||
Route::get('/thumbnail/{name}/public/{token}', [SharedFileAccessContentController::class, 'get_thumbnail_public']);
|
||||
Route::get('/file/{name}/public/{token}', [SharedFileAccessContentController::class, 'get_file_public']);
|
||||
Route::get('/zip/{id}/public/{token}', [SharedFileAccessContentController::class, 'get_zip_public'])->name('zip_public');
|
||||
Route::get('/thumbnail/{name}/public/{token}', [FileSharedAccessController::class, 'get_thumbnail_public']);
|
||||
Route::get('/file/{name}/public/{token}', [FileSharedAccessController::class, 'get_file_public']);
|
||||
Route::get('/zip/{id}/public/{token}', [FileSharedAccessController::class, 'get_zip_public'])->name('zip_public');
|
||||
|
||||
// User master,editor,visitor access to image thumbnails and file downloads
|
||||
Route::group(['middleware' => ['auth:sanctum']], function () {
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@ use App\Http\Controllers\App\AppFunctionsController;
|
||||
use App\Http\Controllers\Sharing\BrowseShareController;
|
||||
use App\Http\Controllers\Sharing\EditShareItemsController;
|
||||
use App\Http\Controllers\FileManager\ShareController;
|
||||
use App\Http\Controllers\Sharing\FileSharingController;
|
||||
use App\Http\Controllers\Sharing\ServeSharedController;
|
||||
|
||||
// Editor functions
|
||||
Route::group(['prefix' => 'editor'], function () {
|
||||
@@ -27,8 +27,8 @@ Route::group(['prefix' => 'browse'], function () {
|
||||
Route::get('/folders/{id}/public/{token}', [BrowseShareController::class, 'get_public_folders']);
|
||||
Route::get('/search/public/{token}', [BrowseShareController::class, 'search_public']);
|
||||
|
||||
Route::post('/shared/authenticate/{token}', [FileSharingController::class, 'authenticate']);
|
||||
Route::get('/files/{token}/public', [FileSharingController::class, 'file_public']);
|
||||
Route::post('/shared/authenticate/{token}', [ServeSharedController::class, 'authenticate']);
|
||||
Route::get('/files/{token}/public', [ServeSharedController::class, 'file_public']);
|
||||
Route::get('/shared/{token}', [ShareController::class, 'show']);
|
||||
});
|
||||
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
use App\Http\Controllers\Admin\InvoiceController;
|
||||
use App\Http\Controllers\App\SetupWizardController;
|
||||
use App\Http\Controllers\App\AppFunctionsController;
|
||||
use App\Http\Controllers\Sharing\FileSharingController;
|
||||
use App\Http\Controllers\Sharing\ServeSharedController;
|
||||
use App\Http\Controllers\Subscription\StripeWebhookController;
|
||||
|
||||
Route::post('/stripe/webhook', [StripeWebhookController::class, 'handleWebhook']);
|
||||
@@ -16,7 +16,7 @@ Route::get('/invoice/{customer}/{token}', [InvoiceController::class, 'show'])->m
|
||||
if (Crawler::isCrawler()) {
|
||||
Route::get('/shared/{token}', [AppFunctionsController::class, 'og_site']);
|
||||
} else {
|
||||
Route::get('/shared/{token}', [FileSharingController::class, 'index']);
|
||||
Route::get('/shared/{token}', [ServeSharedController::class, 'index']);
|
||||
}
|
||||
|
||||
// Show index.blade
|
||||
|
||||
Reference in New Issue
Block a user