diff --git a/.gitignore b/.gitignore
index a8328560..9184766f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
/storage/*.key
/storage/*.index
/vendor
+.idea
.env
.env.backup
.phpunit.result.cache
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..94a25f7f
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index e390b358..e6df82d3 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,7 +1,41 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -14,43 +48,8 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- VueFileManager
- APP_NAME
- ResetUserPasswordNotification
- MAIL_FROM_ADDRESS
- belongsToMany
- .map
- recursiveFind
- latest_uploads
- ->each
- ->first
VerifyCsrfToken
CreateFreshApiToken
j. M. Y, H:i
@@ -71,14 +70,20 @@
cookie
getAppData
SET_AUT
+ PublicCloud
+ Illuminate\Http\Response
+ $updateText
+ ...map
+ ...mapGetters
+ access_token
+ user_account_capacity
+ 'bo
+ SET_CURRENT
+ logOut
-
-
-
-
@@ -100,65 +105,72 @@
+
+
+
+
+
+
+
@@ -283,26 +295,20 @@
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -318,6 +324,7 @@
+
@@ -352,18 +359,17 @@
1582538406416
-
+
-
+
-
-
+
@@ -377,7 +383,7 @@
-
+
@@ -390,170 +396,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -627,18 +469,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -646,96 +476,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -746,63 +486,351 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/Http/Controllers/AppFunctionsController.php b/app/Http/Controllers/AppFunctionsController.php
new file mode 100644
index 00000000..083a7c33
--- /dev/null
+++ b/app/Http/Controllers/AppFunctionsController.php
@@ -0,0 +1,44 @@
+header("Content-Type", $type);
+
+ return $response;
+ }
+}
diff --git a/app/Http/Controllers/PrivateCLoud/AuthController.php b/app/Http/Controllers/Auth/AuthController.php
similarity index 79%
rename from app/Http/Controllers/PrivateCLoud/AuthController.php
rename to app/Http/Controllers/Auth/AuthController.php
index 462d6022..4cab3791 100644
--- a/app/Http/Controllers/PrivateCLoud/AuthController.php
+++ b/app/Http/Controllers/Auth/AuthController.php
@@ -1,6 +1,6 @@
content(), true);
+ if ($response->isSuccessful()) {
- return response('Login Successfull!', 200)->cookie('token', $data['access_token'], 43200);
+ $data = json_decode($response->content(), true);
+
+ return response('Login Successfull!', 200)->cookie('token', $data['access_token'], 43200);
+ } else {
+
+ return $response;
+ }
}
/**
@@ -67,6 +74,9 @@ class AuthController extends Controller
*/
public function register(Request $request)
{
+ // Check if account registration is enabled
+ if (! config('vuefilemanager.registration') ) abort(401);
+
// Validate request
$request->validate([
'name' => ['required', 'string', 'max:255'],
@@ -81,9 +91,17 @@ class AuthController extends Controller
'password' => Hash::make($request->password),
]);
- $token = Route::dispatch(self::make_request($request));
+ $response = Route::dispatch(self::make_request($request));
- return $token;
+ if ($response->isSuccessful()) {
+
+ $data = json_decode($response->content(), true);
+
+ return response('Register Successfull!', 200)->cookie('token', $data['access_token'], 43200);
+ } else {
+
+ return $response;
+ }
}
/**
diff --git a/app/Http/Controllers/PrivateCLoud/ConfirmPasswordController.php b/app/Http/Controllers/Auth/ConfirmPasswordController.php
similarity index 95%
rename from app/Http/Controllers/PrivateCLoud/ConfirmPasswordController.php
rename to app/Http/Controllers/Auth/ConfirmPasswordController.php
index 833755d1..138c1f08 100644
--- a/app/Http/Controllers/PrivateCLoud/ConfirmPasswordController.php
+++ b/app/Http/Controllers/Auth/ConfirmPasswordController.php
@@ -1,6 +1,6 @@
fails()) abort(400, 'Bad input');
// Get user id
- $user_id = Auth::id();
+ $user = Auth::user();
// Delete folder
if ($request->type === 'folder') {
$item = FileManagerFolder::withTrashed()
->with('folders')
- ->where('user_id', $user_id)
+ ->where('user_id', $user->id)
->where('unique_id', $request->unique_id)
->first();
+ // Remove folder from user favourites
+ $user->favourites()->detach($request->unique_id);
+
foreach ($item->files as $file) {
if ($request->force_delete) {
@@ -273,7 +266,7 @@ class FileManagerController extends Controller
if ($request->type === 'file' || $request->type === 'image') {
$item = FileManagerFile::withTrashed()
- ->where('user_id', $user_id)
+ ->where('user_id', $user->id)
->where('unique_id', $request->unique_id)
->first();
@@ -302,17 +295,18 @@ class FileManagerController extends Controller
*/
public function empty_trash()
{
- // TODO: validacia
-
// Get user id
$user_id = Auth::id();
+ // Get files and folders
$folders = FileManagerFolder::onlyTrashed()->where('user_id', $user_id)->get();
$files = FileManagerFile::onlyTrashed()->where('user_id', $user_id)->get();
+ // Force delete every item
$folders->each->forceDelete();
$files->each->forceDelete();
+ // Return response
return response('Done!', 200);
}
@@ -327,6 +321,7 @@ class FileManagerController extends Controller
$validator = Validator::make($request->all(), [
'unique_id' => 'required|integer',
'type' => 'required|string',
+ 'to_home' => 'boolean',
]);
// Return error
@@ -347,6 +342,12 @@ class FileManagerController extends Controller
// Get item
$item = FileManagerFile::withTrashed()->where('user_id', $user_id)->where('unique_id', $request->unique_id)->first();
+
+ // Restore item to home directory
+ if ($request->has('to_home') && $request->to_home) {
+ $item->folder_id = 0;
+ $item->save();
+ }
}
// Restore Item
@@ -400,6 +401,10 @@ class FileManagerController extends Controller
*/
public function upload_item(Request $request)
{
+ // Check if user can upload
+ if (config('vuefilemanager.limit_storage_by_capacity') && user_storage_percentage() >= 100)
+ abort(423, 'You exceed your storage limit!');
+
// Validate request
$validator = Validator::make($request->all(), [
'parent_id' => 'required|integer',
@@ -447,7 +452,7 @@ class FileManagerController extends Controller
// Store file
$new_file = FileManagerFile::create([
- 'user_id' => Auth::id(),
+ 'user_id' => Auth::id(),
'name' => pathinfo($file->getClientOriginalName())['filename'],
'basename' => $filename,
'folder_id' => $folder_id,
@@ -514,7 +519,7 @@ class FileManagerController extends Controller
// Get user id
$user_id = Auth::id();
- return FileManagerFile::where('user_id', $user_id)->where('unique_id', $unique_id)->first();
+ return FileManagerFile::where('user_id', $user_id)->where('unique_id', $unique_id)->firstOrFail();
}
/**
@@ -525,8 +530,17 @@ class FileManagerController extends Controller
*/
public function get_file($filename)
{
+ // Get user id
+ $user_id = Auth::id();
+
+ // Get file record
+ $file = FileManagerFile::withTrashed()->where('user_id', $user_id)
+ ->where('basename', $filename)
+ ->orWhere('thumbnail', $filename)
+ ->firstOrFail();
+
// Get file path
- $path = storage_path() . '/app/file-manager/' . $filename;
+ $path = storage_path() . '/app/file-manager/' . $file->basename;
// Check if file exist
if (!File::exists($path)) abort(404);
@@ -544,30 +558,6 @@ class FileManagerController extends Controller
return $response;
}
- /**
- * Get file
- *
- * @param $filename
- * @return mixed
- */
- public function get_avatar($basename)
- {
- // Get file path
- $path = storage_path() . '/app/avatars/' . $basename;
-
- // Check if file exist
- if (!File::exists($path)) abort(404);
-
- $file = File::get($path);
- $type = File::mimeType($path);
-
- // Create response
- $response = Response::make($file, 200);
- $response->header("Content-Type", $type);
-
- return $response;
- }
-
/**
* Get unique id
*
diff --git a/app/Http/Controllers/PublicCloud/FileManagerController.php b/app/Http/Controllers/PublicCloud/FileManagerController.php
deleted file mode 100644
index 0ec004d2..00000000
--- a/app/Http/Controllers/PublicCloud/FileManagerController.php
+++ /dev/null
@@ -1,505 +0,0 @@
-with(['trashed_folders'])->get(['parent_id', 'unique_id', 'name']);
- $folders = FileManagerFolder::onlyTrashed()->whereIn('unique_id', filter_folders_ids($folders_trashed))->get();
-
- // Get files trashed
- $files_trashed = FileManagerFile::onlyTrashed()->whereNotIn('folder_id', array_values(array_unique(recursiveFind($folders_trashed->toArray(), 'unique_id'))))->get();
-
- // Collect folders and files to single array
- return collect([$folders, $files_trashed])->collapse();
- }
-
- /**
- * Get directory with files
- *
- * @return \Illuminate\Support\Collection
- */
- public function folder(Request $request, $unique_id)
- {
- // Get folder trash items
- if ( $request->query('trash') ) {
-
- // Get folders and files
- $folders = FileManagerFolder::onlyTrashed()->with('parent')->where('parent_id', $unique_id)->get();
- $files = FileManagerFile::onlyTrashed()->with('parent')->where('folder_id', $unique_id)->get();
-
- // Collect folders and files to single array
- return collect([$folders, $files])->collapse();
- }
-
- // Get folders and files
- $folders = FileManagerFolder::with('parent')->where('parent_id', $unique_id)->get();
- $files = FileManagerFile::with('parent')->where('folder_id', $unique_id)->get();
-
- // Collect folders and files to single array
- return collect([$folders, $files])->collapse();
- }
-
- /**
- * Search files
- *
- * @param Request $request
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public function search(Request $request)
- {
- // Validate request
- $validator = Validator::make($request->all(), [
- 'query' => 'required|string',
- ]);
-
- // Return error
- if ($validator->fails()) abort(400, 'Bad input');
-
- // Search files id db
- $searched_files = FileManagerFile::search($request->input('query'))->get();
- $searched_folders = FileManagerFolder::search($request->input('query'))->get();
-
- // Collect folders and files to single array
- return collect([$searched_folders, $searched_files])->collapse();
- }
-
- /**
- * Create new folder
- *
- * @param Request $request
- * @return array
- */
- public function create_folder(Request $request)
- {
- // Validate request
- $validator = Validator::make($request->all(), [
- 'parent_id' => 'required|integer',
- 'name' => 'string',
- ]);
-
- // Return error
- if ($validator->fails()) abort(400, 'Bad input');
-
- // Get parent_id from request
- $parent_id = $request->parent_id === 0 ? 0 : $request->parent_id;
-
- // Create folder
- $folder = FileManagerFolder::create([
- 'parent_id' => $parent_id,
- 'name' => $request->has('name') ? $request->input('name') : 'New Folder',
- 'type' => 'folder',
- 'unique_id' => $this->get_unique_id(),
- ]);
-
- // Return new folder
- return $folder;
- }
-
- /**
- * Rename item name
- *
- * @param Request $request
- * @return mixed
- */
- public function rename_item(Request $request)
- {
- // Validate request
- $validator = Validator::make($request->all(), [
- 'unique_id' => 'required|integer',
- 'name' => 'required|string',
- 'type' => 'required|string',
- ]);
-
- // Return error
- if ($validator->fails()) abort(400, 'Bad input');
-
- // Update folder name
- if ($request->type === 'folder') {
-
- $item = FileManagerFolder::where('unique_id', $request->unique_id)->first();
-
- $item->name = $request->name;
- $item->save();
-
- } else {
-
- $item = FileManagerFile::where('unique_id', $request->unique_id)->first();
-
- $item->name = $request->name;
- $item->save();
- }
-
- // Return updated item
- return $item;
- }
-
- /**
- * Delete item
- *
- * @param Request $request
- * @throws \Exception
- */
- public function delete_item(Request $request)
- {
-
- // Validate request
- $validator = Validator::make($request->all(), [
- 'unique_id' => 'required|integer',
- 'type' => 'required|string',
- 'force_delete' => 'required|boolean',
- ]);
-
- // Return error
- if ($validator->fails()) abort(400, 'Bad input');
-
- // Delete folder
- if ($request->type === 'folder') {
-
- $item = FileManagerFolder::withTrashed()->with('folders')->where('unique_id', $request->unique_id)->first();
-
- foreach ($item->files as $file) {
-
- if ($request->force_delete) {
-
- // Delete file
- Storage::disk('local')->delete('/file-manager/' . $file->basename);
-
- // Delete thumbnail if exist
- if (!is_null($file->thumbnail)) Storage::disk('local')->delete('/file-manager/' . $file->getOriginal('thumbnail'));
-
- // Delete file permanently
- $file->forceDelete();
- } else {
-
- // Delete file from visibility
- $file->delete();
- }
- }
-
- // Delete record
- if ($request->force_delete) {
-
- $item->forceDelete();
- } else {
-
- $item->delete();
- }
- }
-
- if ($request->type === 'file' || $request->type === 'image') {
-
- $item = FileManagerFile::withTrashed()->where('unique_id', $request->unique_id)->first();
-
- if ($request->force_delete) {
-
- // Delete file
- Storage::disk('local')->delete('/file-manager/' . $item->basename);
-
- // Delete thumbnail if exist
- if (!is_null($item->thumbnail)) Storage::disk('local')->delete('/file-manager/' . $item->thumbnail);
-
- // Delete file permanently
- $item->forceDelete();
- } else {
-
- // Delete file from visibility
- $item->delete();
- }
- }
- }
-
- /**
- * Empty user trash
- *
- * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
- */
- public function empty_trash() {
- // TODO: validacia
-
- $folders = FileManagerFolder::onlyTrashed()->get();
- $files = FileManagerFile::onlyTrashed()->get();
-
- $folders->each->forceDelete();
- $files->each->forceDelete();
-
- return response('Done!', 200);
- }
-
- /**
- * Restore item from trash
- *
- * @param Request $request
- */
- public function restore_item(Request $request) {
-
- // Validate request
- $validator = Validator::make($request->all(), [
- 'unique_id' => 'required|integer',
- 'type' => 'required|string',
- ]);
-
- // Return error
- if ($validator->fails()) abort(400, 'Bad input');
-
- // Get folder
- if ($request->type === 'folder') {
-
- // Get folder
- $item = FileManagerFolder::withTrashed()->where('unique_id', $request->unique_id)->first();
- }
-
- // Get file
- if ($request->type === 'file' || $request->type === 'image') {
-
- // Get item
- $item = FileManagerFile::withTrashed()->where('unique_id', $request->unique_id)->first();
- }
-
- // Restore Item
- $item->restore();
- }
-
- /**
- * Delete Item
- *
- * @param Request $request
- */
- public function delete_items(Request $request)
- {
- // Validate request
- $validator = Validator::make($request->all(), [
- 'items' => 'required|json',
- ]);
-
- // Return error
- if ($validator->fails()) abort(400, 'Bad input');
-
- foreach ($request->input('items') as $file) {
-
- if ($file['type'] === 'file' || $file['type'] === 'image') {
-
- $item = FileManagerFile::where('unique_id', $file['unique_id'])->first();
-
- } else {
-
- $item = FileManagerFolder::where('unique_id', $file['unique_id'])->first();
- }
-
- // Delete file
- Storage::disk('local')->delete('/file-manager/' . $item->basename);
-
- // Delete thumbnail if exist
- if (!is_null($item->thumbnail)) {
- Storage::disk('local')->delete('/file-manager/' . $item->thumbnail);
- }
-
- // Permanently delete file
- $item->forceDelete();
- }
- }
-
- /**
- * Upload items
- *
- * @param Request $request
- * @return array
- */
- public function upload_item(Request $request)
- {
- // Validate request
- $validator = Validator::make($request->all(), [
- 'parent_id' => 'required|integer',
- 'file' => 'required|file',
- ]);
-
- // Return error
- if ($validator->fails()) abort(400, 'Bad input');
-
- // Get parent_id from request
- $folder_id = $request->parent_id === 0 ? 0 : $request->parent_id;
- $file = $request->file('file');
-
- // File
- $filename = Str::random() . '-' . str_replace(' ', '', $file->getClientOriginalName());
- $filetype = 'file';
- $thumbnail = null;
- $filesize = $file->getSize();
- $directory = 'file-manager';
-
- // create directory if not exist
- if (!Storage::disk('local')->exists($directory)) {
- Storage::disk('local')->makeDirectory($directory);
- }
-
- // Store to disk
- Storage::disk('local')->putFileAs($directory, $file, $filename, 'public');
-
- // Create image thumbnail
- if (substr($file->getMimeType(), 0, 5) == 'image') {
-
- $filetype = 'image';
- $thumbnail = 'thumbnail-' . $filename;
-
- // Create intervention image
- $image = Image::make($file->getRealPath());
-
- $image->resize(256, null, function ($constraint) {
- $constraint->aspectRatio();
- })->save(null, 90);
-
- // Store thumbnail to s3
- Storage::disk('local')->put($directory . '/' . $thumbnail, $image);
- }
-
- // Store file
- $new_file = FileManagerFile::create([
- 'name' => pathinfo($file->getClientOriginalName())['filename'],
- 'basename' => $filename,
- 'folder_id' => $folder_id,
- 'mimetype' => $file->getClientOriginalExtension(),
- 'filesize' => $filesize,
- 'type' => $filetype,
- 'thumbnail' => $thumbnail,
- 'unique_id' => $this->get_unique_id(),
- ]);
-
- return $new_file;
- }
-
- /**
- * Move item
- *
- * @param Request $request
- */
- public function move_item(Request $request)
- {
- // Validate request
- $validator = Validator::make($request->all(), [
- 'from_unique_id' => 'required|integer',
- 'to_unique_id' => 'required|integer',
- 'from_type' => 'required|string',
- ]);
-
- // Return error
- if ($validator->fails()) abort(400, 'Bad input');
-
- if ($request->from_type === 'folder') {
-
- // Move folder
- $item = FileManagerFolder::where('unique_id', $request->from_unique_id)->first();
- $item->parent_id = $request->to_unique_id;
-
- } else {
-
- // Move file under new folder
- $item = FileManagerFile::where('unique_id', $request->from_unique_id)->first();
- $item->folder_id = $request->to_unique_id;
- }
-
- $item->update();
- }
-
- /**
- * Get file record
- *
- * @param $unique_id
- * @return mixed
- */
- public function get_file_detail($unique_id)
- {
- return FileManagerFile::where('unique_id', $unique_id)->first();
- }
-
- /**
- * Get file
- *
- * @param $filename
- * @return mixed
- */
- public function get_file($filename)
- {
- // Get file path
- $path = storage_path() . '/app/file-manager/' . $filename;
-
- // Check if file exist
- if (!File::exists($path)) abort(404);
-
- $file = File::get($path);
- $type = File::mimeType($path);
- $size = File::size($path);
-
- // Create response
- $response = Response::make($file, 200);
- $response->header("Content-Type", $type);
- $response->header("Content-Disposition", 'attachment; filename=' . $filename);
- $response->header("Content-Length", $size);
-
- return $response;
- }
-
- /**
- * Get file
- *
- * @param $filename
- * @return mixed
- */
- public function get_avatar($basename)
- {
- // Get file path
- $path = storage_path() . '/app/avatars/' . $basename;
-
- // Check if file exist
- if (!File::exists($path)) abort(404);
-
- $file = File::get($path);
- $type = File::mimeType($path);
-
- // Create response
- $response = Response::make($file, 200);
- $response->header("Content-Type", $type);
-
- return $response;
- }
-
- /**
- * Get unique id
- *
- * @return int
- */
- private function get_unique_id(): int
- {
- // Get files and folders
- $folders = FileManagerFolder::withTrashed()->get();
- $files = FileManagerFile::withTrashed()->get();
-
- // Get last ids
- $folders_unique = $folders->isEmpty() ? 0 : $folders->last()->unique_id;
- $files_unique = $files->isEmpty() ? 0 : $files->last()->unique_id;
-
- // Count new unique id
- $unique_id = $folders_unique > $files_unique ? $folders_unique + 1 : $files_unique + 1;
-
- return $unique_id;
- }
-}
diff --git a/app/Http/Controllers/PrivateCLoud/UserAccountController.php b/app/Http/Controllers/UserAccountController.php
similarity index 68%
rename from app/Http/Controllers/PrivateCLoud/UserAccountController.php
rename to app/Http/Controllers/UserAccountController.php
index ef7d4e92..30f26f19 100644
--- a/app/Http/Controllers/PrivateCLoud/UserAccountController.php
+++ b/app/Http/Controllers/UserAccountController.php
@@ -1,17 +1,43 @@
where('id', $user_id)->first();
+
+ return [
+ 'user' => $user->only(['name', 'email', 'avatar']),
+ 'favourites' => $user->favourites->makeHidden(['pivot']),
+ 'latest_uploads' => $user->latest_uploads->makeHidden(['user_id', 'basename']),
+
+ 'storage' => [
+ 'used' => Metric::bytes($user->used_capacity)->format(),
+ 'capacity' => format_gigabytes(config('vuefilemanager.user_storage_capacity')),
+ 'percentage' => get_storage_fill_percentage($user->used_capacity, config('vuefilemanager.user_storage_capacity')),
+ ],
+ ];
+ }
/**
* Update user profile
@@ -19,9 +45,20 @@ class UserAccountController extends Controller
* @param Request $request
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
*/
- public function update_profile(Request $request) {
- // TODO: validacia
+ public function update_profile(Request $request)
+ {
+ // Validate request
+ $validator = Validator::make($request->all(), [
+ 'avatar' => 'file',
+ '_method' => 'string',
+ 'name' => 'string',
+ 'value' => 'string',
+ ]);
+ // Return error
+ if ($validator->fails()) abort(400, 'Bad input');
+
+ // Get user
$user = Auth::user();
if ($request->hasFile('avatar')) {
@@ -54,36 +91,12 @@ class UserAccountController extends Controller
'password' => ['required', 'string', 'min:6', 'confirmed'],
]);
+ // Get user
$user = Auth::user();
+ // Change and store new password
$user->password = Hash::make($request->input('password'));
$user->save();
-
- }
-
- /**
- * Get all user data to frontend
- *
- * @return array|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
- */
- public function user(Request $request)
- {
- // Get User
- $user = User::with(['favourites', 'latest_uploads'])
- ->where('id', Auth::id())
- ->first();
-
- // TODO: dat do configu maximalnu kapacitu pre usera
- return [
- 'user' => $user->only(['name', 'email', 'avatar']),
- 'favourites' => $user->favourites->makeHidden(['pivot']),
- 'latest_uploads' => $user->latest_uploads->makeHidden(['user_id', 'basename']),
- 'storage' => [
- 'used' => Metric::bytes($user->used_capacity)->format(),
- 'capacity' => format_gigabytes(10),
- 'percentage' => get_storage_fill_percentage($user->used_capacity, 10),
- ],
- ];
}
/**
@@ -94,7 +107,13 @@ class UserAccountController extends Controller
*/
public function add_to_favourites(Request $request)
{
- // TODO: validation
+ // Validate request
+ $validator = Validator::make($request->all(), [
+ 'unique_id' => 'required|integer',
+ ]);
+
+ // Return error
+ if ($validator->fails()) abort(400, 'Bad input');
// Get user
$user = Auth::user();
@@ -114,7 +133,13 @@ class UserAccountController extends Controller
*/
public function remove_from_favourites(Request $request)
{
- // TODO: validation
+ // Validate request
+ $validator = Validator::make($request->all(), [
+ 'unique_id' => 'required|integer',
+ ]);
+
+ // Return error
+ if ($validator->fails()) abort(400, 'Bad input');
// Get user
$user = Auth::user();
diff --git a/app/Http/helpers.php b/app/Http/helpers.php
index 65d5f1de..989aa7e0 100644
--- a/app/Http/helpers.php
+++ b/app/Http/helpers.php
@@ -73,7 +73,6 @@ function make_single_input($request)
*/
function format_gigabytes($megabytes)
{
-
return Metric::megabytes($megabytes)->format();
}
@@ -86,7 +85,6 @@ function format_gigabytes($megabytes)
*/
function get_storage_fill_percentage($used, $capacity)
{
-
// Format gigabytes to bytes
$total = intval(Metric::megabytes($capacity)->numberOfBytes());
@@ -97,6 +95,18 @@ function get_storage_fill_percentage($used, $capacity)
return number_format((float)$progress, 2, '.', '');
}
+/**
+ * Get user capacity fill percentage
+ *
+ * @return string
+ */
+function user_storage_percentage() {
+
+ $user = \Illuminate\Support\Facades\Auth::user();
+
+ return get_storage_fill_percentage($user->used_capacity, config('vuefilemanager.user_storage_capacity'));
+}
+
/**
* Find all key values in recursive array
*
diff --git a/config/vuefilemanager.php b/config/vuefilemanager.php
new file mode 100644
index 00000000..e1b175e8
--- /dev/null
+++ b/config/vuefilemanager.php
@@ -0,0 +1,13 @@
+ true,
+
+ // Limit your storage size for every user if this option is enabled
+ 'limit_storage_by_capacity' => true,
+
+ // Define user storage capacity in MB. E.g. value 2000 is 2.00GB
+ 'user_storage_capacity' => 100,
+];
\ No newline at end of file
diff --git a/public/mix-manifest.json b/public/mix-manifest.json
index e7e8c392..f938e2ae 100644
--- a/public/mix-manifest.json
+++ b/public/mix-manifest.json
@@ -52,5 +52,65 @@
"/js/main.2f88baed5888ed7c18ec.hot-update.js": "/js/main.2f88baed5888ed7c18ec.hot-update.js",
"/js/main.28750132a4bf9f027f76.hot-update.js": "/js/main.28750132a4bf9f027f76.hot-update.js",
"/js/main.271855de5d8900e09251.hot-update.js": "/js/main.271855de5d8900e09251.hot-update.js",
- "/js/main.a5f3be671e89b7b02488.hot-update.js": "/js/main.a5f3be671e89b7b02488.hot-update.js"
+ "/js/main.a5f3be671e89b7b02488.hot-update.js": "/js/main.a5f3be671e89b7b02488.hot-update.js",
+ "/js/main.bbe4c1152bcc98c4a824.hot-update.js": "/js/main.bbe4c1152bcc98c4a824.hot-update.js",
+ "/js/main.51f97d93eec1b080e9e4.hot-update.js": "/js/main.51f97d93eec1b080e9e4.hot-update.js",
+ "/js/main.aada5ad78910b91cb195.hot-update.js": "/js/main.aada5ad78910b91cb195.hot-update.js",
+ "/js/main.7e74d89742cb29908548.hot-update.js": "/js/main.7e74d89742cb29908548.hot-update.js",
+ "/js/main.526354f8026836232108.hot-update.js": "/js/main.526354f8026836232108.hot-update.js",
+ "/js/main.095fd0ae956d13e7d0eb.hot-update.js": "/js/main.095fd0ae956d13e7d0eb.hot-update.js",
+ "/js/main.76bb6f7f9e40560681b6.hot-update.js": "/js/main.76bb6f7f9e40560681b6.hot-update.js",
+ "/js/main.fcee2fd91b74afff90f6.hot-update.js": "/js/main.fcee2fd91b74afff90f6.hot-update.js",
+ "/js/main.e2abd1caa20ec95707c2.hot-update.js": "/js/main.e2abd1caa20ec95707c2.hot-update.js",
+ "/js/main.cda452c02c35b348c3d2.hot-update.js": "/js/main.cda452c02c35b348c3d2.hot-update.js",
+ "/js/main.40bf27ec73a8df23a001.hot-update.js": "/js/main.40bf27ec73a8df23a001.hot-update.js",
+ "/js/main.d0b2da5a72218c5f2753.hot-update.js": "/js/main.d0b2da5a72218c5f2753.hot-update.js",
+ "/js/main.5809dfdf155fd5afe07d.hot-update.js": "/js/main.5809dfdf155fd5afe07d.hot-update.js",
+ "/js/main.1d75e99d7eb6206df763.hot-update.js": "/js/main.1d75e99d7eb6206df763.hot-update.js",
+ "/js/main.c9c04c5a9a8a925daaee.hot-update.js": "/js/main.c9c04c5a9a8a925daaee.hot-update.js",
+ "/js/main.0c6e0946cd529be6b378.hot-update.js": "/js/main.0c6e0946cd529be6b378.hot-update.js",
+ "/js/main.cbbbc2cb67a3d80f764b.hot-update.js": "/js/main.cbbbc2cb67a3d80f764b.hot-update.js",
+ "/js/main.d4620a39394f417bc81d.hot-update.js": "/js/main.d4620a39394f417bc81d.hot-update.js",
+ "/js/main.7b849857ab83be0c2c56.hot-update.js": "/js/main.7b849857ab83be0c2c56.hot-update.js",
+ "/js/main.e42986a050f3c8ba1579.hot-update.js": "/js/main.e42986a050f3c8ba1579.hot-update.js",
+ "/js/main.a14bb8bca0814982ed2b.hot-update.js": "/js/main.a14bb8bca0814982ed2b.hot-update.js",
+ "/js/main.182831741990e33f47d9.hot-update.js": "/js/main.182831741990e33f47d9.hot-update.js",
+ "/js/main.c97a01957f9112ed06da.hot-update.js": "/js/main.c97a01957f9112ed06da.hot-update.js",
+ "/js/main.684808ff4a9b478521f0.hot-update.js": "/js/main.684808ff4a9b478521f0.hot-update.js",
+ "/js/main.65773e1cec12c0a6dafd.hot-update.js": "/js/main.65773e1cec12c0a6dafd.hot-update.js",
+ "/js/main.dc6dbfd05791e0fa3456.hot-update.js": "/js/main.dc6dbfd05791e0fa3456.hot-update.js",
+ "/js/main.10cde6e22a01f10f3dc1.hot-update.js": "/js/main.10cde6e22a01f10f3dc1.hot-update.js",
+ "/js/main.cade64e98d9456c9d85b.hot-update.js": "/js/main.cade64e98d9456c9d85b.hot-update.js",
+ "/js/main.1e1883f028249ee95686.hot-update.js": "/js/main.1e1883f028249ee95686.hot-update.js",
+ "/js/main.dd41bbb237612b5ef1cf.hot-update.js": "/js/main.dd41bbb237612b5ef1cf.hot-update.js",
+ "/js/main.6e4d71a8180ef9d0027d.hot-update.js": "/js/main.6e4d71a8180ef9d0027d.hot-update.js",
+ "/js/main.7bf8c13576d91a63de15.hot-update.js": "/js/main.7bf8c13576d91a63de15.hot-update.js",
+ "/js/main.00008aac79fa0e306261.hot-update.js": "/js/main.00008aac79fa0e306261.hot-update.js",
+ "/js/main.c7d5f6f5553c8ac444a1.hot-update.js": "/js/main.c7d5f6f5553c8ac444a1.hot-update.js",
+ "/js/main.01331afd6e83ce53c9f1.hot-update.js": "/js/main.01331afd6e83ce53c9f1.hot-update.js",
+ "/js/main.6a97dcd027db22d2fe58.hot-update.js": "/js/main.6a97dcd027db22d2fe58.hot-update.js",
+ "/js/main.0439ef5b559eec971f46.hot-update.js": "/js/main.0439ef5b559eec971f46.hot-update.js",
+ "/js/main.13f7f31a870d036f33d4.hot-update.js": "/js/main.13f7f31a870d036f33d4.hot-update.js",
+ "/js/main.ebb5b8e3a49f7497799e.hot-update.js": "/js/main.ebb5b8e3a49f7497799e.hot-update.js",
+ "/js/main.d806d5e96490d67c6a87.hot-update.js": "/js/main.d806d5e96490d67c6a87.hot-update.js",
+ "/js/main.7cf3722d7936494ff475.hot-update.js": "/js/main.7cf3722d7936494ff475.hot-update.js",
+ "/js/main.821d8599536488baf0f8.hot-update.js": "/js/main.821d8599536488baf0f8.hot-update.js",
+ "/js/main.f5bd13ae830d4db45212.hot-update.js": "/js/main.f5bd13ae830d4db45212.hot-update.js",
+ "/js/main.e3f00309dc683e835468.hot-update.js": "/js/main.e3f00309dc683e835468.hot-update.js",
+ "/js/main.4e070f398ba2602d8b27.hot-update.js": "/js/main.4e070f398ba2602d8b27.hot-update.js",
+ "/js/main.4407ffbdbd68dbf1b6bb.hot-update.js": "/js/main.4407ffbdbd68dbf1b6bb.hot-update.js",
+ "/js/main.5460f498775a4edd0bb8.hot-update.js": "/js/main.5460f498775a4edd0bb8.hot-update.js",
+ "/js/main.b54c6958681b8e316912.hot-update.js": "/js/main.b54c6958681b8e316912.hot-update.js",
+ "/js/main.4dd9baec87cbba44da1f.hot-update.js": "/js/main.4dd9baec87cbba44da1f.hot-update.js",
+ "/js/main.15fa523c653a50e421a5.hot-update.js": "/js/main.15fa523c653a50e421a5.hot-update.js",
+ "/js/main.1a485b15893b04b29e77.hot-update.js": "/js/main.1a485b15893b04b29e77.hot-update.js",
+ "/js/main.c0d59287145c78d7527b.hot-update.js": "/js/main.c0d59287145c78d7527b.hot-update.js",
+ "/js/main.406a9b87d350e9f7d1af.hot-update.js": "/js/main.406a9b87d350e9f7d1af.hot-update.js",
+ "/js/main.47c7327d0c4dd0759676.hot-update.js": "/js/main.47c7327d0c4dd0759676.hot-update.js",
+ "/js/main.3c58b7fb8eec2d6af53f.hot-update.js": "/js/main.3c58b7fb8eec2d6af53f.hot-update.js",
+ "/js/main.8ea8151691b11c0808fb.hot-update.js": "/js/main.8ea8151691b11c0808fb.hot-update.js",
+ "/js/main.07a1de188746117946e4.hot-update.js": "/js/main.07a1de188746117946e4.hot-update.js",
+ "/js/main.7ef63b397f419a849587.hot-update.js": "/js/main.7ef63b397f419a849587.hot-update.js",
+ "/js/main.efaa9b6327a9e613cc07.hot-update.js": "/js/main.efaa9b6327a9e613cc07.hot-update.js",
+ "/js/main.cd194c3416426f2b5369.hot-update.js": "/js/main.cd194c3416426f2b5369.hot-update.js"
}
diff --git a/resources/js/App.vue b/resources/js/App.vue
index 55e6917a..7ed2f1d2 100644
--- a/resources/js/App.vue
+++ b/resources/js/App.vue
@@ -1,6 +1,6 @@
-
+
@@ -12,21 +12,10 @@
components: {
VueFileManager
},
- data() {
- return {
- config: {
- //api: 'https://vuefilemanager.hi5ve.digital/api'
- api: 'http://localhost:8000/api'
- //api: 'http://172.20.10.5:8000/api'
- //api: 'http://192.168.1.131:8000/api'
- }
- }
- }
}