mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-20 12:15:02 +00:00
- added not found exception for Model
- cleared dev console - get share record refactored on backend
This commit is contained in:
@@ -14,6 +14,7 @@ use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Faker;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SetupDevEnvironment extends Command
|
||||
{
|
||||
@@ -75,6 +76,7 @@ class SetupDevEnvironment extends Command
|
||||
|
||||
$this->info('Creating default admin content...');
|
||||
$this->create_admin_default_content();
|
||||
$this->create_share_records();
|
||||
|
||||
$this->info('Clearing application cache...');
|
||||
$this->clear_cache();
|
||||
@@ -374,20 +376,22 @@ class SetupDevEnvironment extends Command
|
||||
])
|
||||
->each(function ($file) use ($user) {
|
||||
|
||||
$basename = Str::random(12) . '-' . $file['basename'];
|
||||
|
||||
// Copy file into app storage
|
||||
\File::copy(storage_path("demo/documents/{$file['basename']}"), storage_path("app/files/$user->id/{$file['basename']}"));
|
||||
\File::copy(storage_path("demo/documents/{$file['basename']}"), storage_path("app/files/$user->id/$basename"));
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'folder_id' => null,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file['name'],
|
||||
'basename' => $file['basename'],
|
||||
'basename' => $basename,
|
||||
'type' => 'file',
|
||||
'user_scope' => 'master',
|
||||
'mimetype' => $file['mimetype'],
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -416,20 +420,22 @@ class SetupDevEnvironment extends Command
|
||||
])
|
||||
->each(function ($file) use ($user, $documents) {
|
||||
|
||||
$basename = Str::random(12) . '-' . $file['basename'];
|
||||
|
||||
// Copy file into app storage
|
||||
\File::copy(storage_path("demo/documents/{$file['basename']}"), storage_path("app/files/$user->id/{$file['basename']}"));
|
||||
\File::copy(storage_path("demo/documents/{$file['basename']}"), storage_path("app/files/$user->id/$basename"));
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'folder_id' => $documents->id,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file['name'],
|
||||
'basename' => $file['basename'],
|
||||
'basename' => $basename,
|
||||
'type' => 'file',
|
||||
'user_scope' => 'master',
|
||||
'mimetype' => $file['mimetype'],
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -448,20 +454,22 @@ class SetupDevEnvironment extends Command
|
||||
])
|
||||
->each(function ($file) use ($user, $shared_folder) {
|
||||
|
||||
$basename = Str::random(12) . '-' . $file['basename'];
|
||||
|
||||
// Copy file into app storage
|
||||
\File::copy(storage_path("demo/documents/{$file['basename']}"), storage_path("app/files/$user->id/{$file['basename']}"));
|
||||
\File::copy(storage_path("demo/documents/{$file['basename']}"), storage_path("app/files/$user->id/$basename"));
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'folder_id' => $shared_folder->id,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file['name'],
|
||||
'basename' => $file['basename'],
|
||||
'basename' => $basename,
|
||||
'type' => 'file',
|
||||
'user_scope' => 'master',
|
||||
'mimetype' => $file['mimetype'],
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -505,20 +513,22 @@ class SetupDevEnvironment extends Command
|
||||
])
|
||||
->each(function ($file) use ($user, $peters_files) {
|
||||
|
||||
$basename = Str::random(12) . '-' . $file['basename'];
|
||||
|
||||
// Copy file into app storage
|
||||
\File::copy(storage_path("demo/documents/{$file['basename']}"), storage_path("app/files/$user->id/{$file['basename']}"));
|
||||
\File::copy(storage_path("demo/documents/{$file['basename']}"), storage_path("app/files/$user->id/$basename"));
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'folder_id' => $peters_files->id,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file['name'],
|
||||
'basename' => $file['basename'],
|
||||
'basename' => $basename,
|
||||
'type' => 'file',
|
||||
'user_scope' => 'editor',
|
||||
'mimetype' => $file['mimetype'],
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -531,20 +541,22 @@ class SetupDevEnvironment extends Command
|
||||
])
|
||||
->each(function ($file) use ($user, $videohive) {
|
||||
|
||||
$basename = Str::random(12) . '-' . $file;
|
||||
|
||||
// Copy file into app storage
|
||||
\File::copy(storage_path("demo/video/$file"), storage_path("app/files/$user->id/$file"));
|
||||
\File::copy(storage_path("demo/video/$file"), storage_path("app/files/$user->id/$basename"));
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'folder_id' => $videohive->id,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file,
|
||||
'basename' => $file,
|
||||
'basename' => $basename,
|
||||
'type' => 'video',
|
||||
'user_scope' => 'master',
|
||||
'mimetype' => 'mp4',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -554,20 +566,22 @@ class SetupDevEnvironment extends Command
|
||||
])
|
||||
->each(function ($file) use ($user, $video) {
|
||||
|
||||
$basename = Str::random(12) . '-' . $file;
|
||||
|
||||
// Copy file into app storage
|
||||
\File::copy(storage_path("demo/video/$file"), storage_path("app/files/$user->id/$file"));
|
||||
\File::copy(storage_path("demo/video/$file"), storage_path("app/files/$user->id/$basename"));
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'folder_id' => $video->id,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file,
|
||||
'basename' => $file,
|
||||
'basename' => $basename,
|
||||
'type' => 'video',
|
||||
'user_scope' => 'master',
|
||||
'mimetype' => 'mp4',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -577,20 +591,22 @@ class SetupDevEnvironment extends Command
|
||||
])
|
||||
->each(function ($file) use ($user, $audio) {
|
||||
|
||||
$basename = Str::random(12) . '-' . $file;
|
||||
|
||||
// Copy file into app storage
|
||||
\File::copy(storage_path("demo/audio/$file"), storage_path("app/files/$user->id/$file"));
|
||||
\File::copy(storage_path("demo/audio/$file"), storage_path("app/files/$user->id/$basename"));
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'folder_id' => $audio->id,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file,
|
||||
'basename' => $file,
|
||||
'basename' => $basename,
|
||||
'type' => 'audio',
|
||||
'user_scope' => 'master',
|
||||
'mimetype' => 'mp3',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -611,8 +627,10 @@ class SetupDevEnvironment extends Command
|
||||
])
|
||||
->each(function ($file) use ($user, $apartments) {
|
||||
|
||||
$basename = Str::random(12) . '-' . $file;
|
||||
|
||||
// Copy file into app storage
|
||||
\File::copy(storage_path("demo/images/memes/$file"), storage_path("app/files/$user->id/$file"));
|
||||
\File::copy(storage_path("demo/images/memes/$file"), storage_path("app/files/$user->id/$basename"));
|
||||
|
||||
$this->info("Creating thumbnail for image: $file");
|
||||
|
||||
@@ -621,13 +639,13 @@ class SetupDevEnvironment extends Command
|
||||
'folder_id' => null,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file,
|
||||
'basename' => $file,
|
||||
'basename' => $basename,
|
||||
'type' => 'image',
|
||||
'user_scope' => 'master',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'thumbnail' => $this->helper->create_image_thumbnail("files/$user->id/$file", $file, $user->id),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
'thumbnail' => $this->helper->create_image_thumbnail("files/$user->id/$basename", $file, $user->id),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -643,8 +661,10 @@ class SetupDevEnvironment extends Command
|
||||
])
|
||||
->each(function ($file) use ($user, $apartments) {
|
||||
|
||||
$basename = Str::random(12) . '-' . $file;
|
||||
|
||||
// Copy file into app storage
|
||||
\File::copy(storage_path("demo/images/apartments/$file"), storage_path("app/files/$user->id/$file"));
|
||||
\File::copy(storage_path("demo/images/apartments/$file"), storage_path("app/files/$user->id/$basename"));
|
||||
|
||||
$this->info("Creating thumbnail for image: $file");
|
||||
|
||||
@@ -653,13 +673,13 @@ class SetupDevEnvironment extends Command
|
||||
'folder_id' => $apartments->id,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file,
|
||||
'basename' => $file,
|
||||
'basename' => $basename,
|
||||
'type' => 'image',
|
||||
'user_scope' => 'master',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'thumbnail' => $this->helper->create_image_thumbnail("files/$user->id/$file", $file, $user->id),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
'thumbnail' => $this->helper->create_image_thumbnail("files/$user->id/$basename", $file, $user->id),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -679,8 +699,10 @@ class SetupDevEnvironment extends Command
|
||||
])
|
||||
->each(function ($file) use ($user, $nature) {
|
||||
|
||||
$basename = Str::random(12) . '-' . $file;
|
||||
|
||||
// Copy file into app storage
|
||||
\File::copy(storage_path("demo/images/nature/$file"), storage_path("app/files/$user->id/$file"));
|
||||
\File::copy(storage_path("demo/images/nature/$file"), storage_path("app/files/$user->id/$basename"));
|
||||
|
||||
$this->info("Creating thumbnail for image: $file");
|
||||
|
||||
@@ -689,17 +711,57 @@ class SetupDevEnvironment extends Command
|
||||
'folder_id' => $nature->id,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file,
|
||||
'basename' => $file,
|
||||
'basename' => $basename,
|
||||
'type' => 'image',
|
||||
'user_scope' => 'master',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'thumbnail' => $this->helper->create_image_thumbnail("files/$user->id/$file", $file, $user->id),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
'thumbnail' => $this->helper->create_image_thumbnail("files/$user->id/$basename", $file, $user->id),
|
||||
'created_at' => Carbon::now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
private function create_share_records(): void
|
||||
{
|
||||
$user = User::whereEmail('howdy@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$images = File::whereType('image')
|
||||
->whereFolderId(null)
|
||||
->take(3)
|
||||
->pluck('id');
|
||||
|
||||
$images->each(function ($id) use ($user) {
|
||||
Share::create([
|
||||
'user_id' => $user->id,
|
||||
'item_id' => $id,
|
||||
'type' => 'file',
|
||||
'is_protected' => false,
|
||||
'permission' => 'editor',
|
||||
'password' => null,
|
||||
'expire_in' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
$files = File::whereType('file')
|
||||
->whereFolderId(null)
|
||||
->take(2)
|
||||
->pluck('id');
|
||||
|
||||
$files->each(function ($id) use ($user) {
|
||||
Share::create([
|
||||
'user_id' => $user->id,
|
||||
'item_id' => $id,
|
||||
'type' => 'file',
|
||||
'is_protected' => false,
|
||||
'permission' => 'editor',
|
||||
'password' => null,
|
||||
'expire_in' => null,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Store main app settings into database
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
@@ -50,6 +51,12 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
if ($exception instanceof ModelNotFoundException) {
|
||||
|
||||
return response()
|
||||
->redirectTo('/not-found')->setStatusCode(404);
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class BrowseShareController extends Controller
|
||||
public function get_public_folders($id, Share $shared)
|
||||
{
|
||||
// Abort if folder is protected
|
||||
if ((int)$shared->is_protected) {
|
||||
if ($shared->is_protected) {
|
||||
abort(403, "Sorry, you don't have permission");
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class BrowseShareController extends Controller
|
||||
public function search_public(Request $request, Share $shared)
|
||||
{
|
||||
// Abort if folder is protected
|
||||
if ((int)$shared->is_protected) {
|
||||
if ($shared->is_protected) {
|
||||
abort(403, "Sorry, you don't have permission");
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class EditShareItemsController extends Controller
|
||||
*/
|
||||
public function create_folder(CreateFolderRequest $request, Share $shared)
|
||||
{
|
||||
if (is_demo($shared->user_id)) {
|
||||
if (is_demo_account($shared->user->email)) {
|
||||
return $this->demo->create_folder($request);
|
||||
}
|
||||
|
||||
@@ -70,8 +70,7 @@ class EditShareItemsController extends Controller
|
||||
*/
|
||||
public function rename_item(RenameItemRequest $request, $id, Share $shared)
|
||||
{
|
||||
// Demo preview
|
||||
if (is_demo($shared->user_id)) {
|
||||
if (is_demo_account($shared->user->email)) {
|
||||
return $this->demo->rename_item($request, $id);
|
||||
}
|
||||
|
||||
@@ -116,8 +115,7 @@ class EditShareItemsController extends Controller
|
||||
*/
|
||||
public function delete_item(DeleteItemRequest $request, Share $shared)
|
||||
{
|
||||
// Demo preview
|
||||
if (is_demo($shared->user_id)) {
|
||||
if (is_demo_account($shared->user->email)) {
|
||||
return $this->demo->response_with_no_content();
|
||||
}
|
||||
|
||||
@@ -155,8 +153,7 @@ class EditShareItemsController extends Controller
|
||||
*/
|
||||
public function upload(UploadRequest $request, Share $shared)
|
||||
{
|
||||
// Demo preview
|
||||
if (is_demo($shared->user_id)) {
|
||||
if (is_demo_account($shared->user->email)) {
|
||||
return $this->demo->upload($request);
|
||||
}
|
||||
|
||||
@@ -186,8 +183,7 @@ class EditShareItemsController extends Controller
|
||||
*/
|
||||
public function move(MoveItemRequest $request, Share $shared)
|
||||
{
|
||||
// Demo preview
|
||||
if (is_demo(Auth::id())) {
|
||||
if (is_demo_account($shared->user->email)) {
|
||||
return $this->demo->response_with_no_content();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class FileSharedAccessController extends Controller
|
||||
public function get_file_public($filename, Share $shared)
|
||||
{
|
||||
// Abort if shared is protected
|
||||
if ((int)$shared->is_protected) {
|
||||
if ($shared->is_protected) {
|
||||
abort(403, "Sorry, you don't have permission");
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class FileSharedAccessController extends Controller
|
||||
public function get_thumbnail_public($filename, Share $shared)
|
||||
{
|
||||
// Abort if thumbnail is protected
|
||||
if ((int)$shared->is_protected) {
|
||||
if ($shared->is_protected) {
|
||||
abort(403, "Sorry, you don't have permission");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,76 +35,63 @@ class ServeSharedController extends Controller
|
||||
*/
|
||||
public function index(Share $shared)
|
||||
{
|
||||
if (!$shared) {
|
||||
return response()
|
||||
->view('index', [
|
||||
'settings' => null,
|
||||
'legal' => null,
|
||||
'installation' => null,
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Delete old access_token if exist
|
||||
Cookie::queue('shared_access_token', '', -1);
|
||||
|
||||
// Set cookies
|
||||
if ((int)$shared->is_protected) {
|
||||
if ($shared->is_protected) {
|
||||
|
||||
// Set shared token
|
||||
Cookie::queue('shared_token', $shared->token, 43200);
|
||||
}
|
||||
|
||||
// Check if shared is image file and then show it
|
||||
if ($shared->type === 'file' && !(int)$shared->is_protected) {
|
||||
if ($shared->type === 'file' && !$shared->is_protected) {
|
||||
|
||||
$image = File::where('user_id', $shared->user_id)
|
||||
->where('type', 'image')
|
||||
->where('id', $shared->item_id)
|
||||
->first();
|
||||
$image = File::whereUserId($shared->user_id)
|
||||
->whereType('image')
|
||||
->whereId($shared->item_id)
|
||||
->firstOrFail();
|
||||
|
||||
if ($image) {
|
||||
// Store user download size
|
||||
$shared
|
||||
->user
|
||||
->record_download(
|
||||
(int)$image->getRawOriginal('filesize')
|
||||
);
|
||||
|
||||
// Store user download size
|
||||
User::find($shared->user_id)->record_download((int)$image->getRawOriginal('filesize'));
|
||||
|
||||
return $this->show_image($image);
|
||||
}
|
||||
return $this->show_image($image, $shared->user_id);
|
||||
}
|
||||
|
||||
// Get all settings
|
||||
$settings = get_settings_in_json();
|
||||
|
||||
// Return page index
|
||||
return view("index")
|
||||
->with('settings', $settings ?? null);
|
||||
->with('settings', get_settings_in_json() ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image from storage and show it
|
||||
*
|
||||
* @param $file
|
||||
* @param $user_id
|
||||
* @return \Symfony\Component\HttpFoundation\StreamedResponse
|
||||
*/
|
||||
private function show_image($file)
|
||||
private function show_image($file, $user_id)
|
||||
{
|
||||
// Format pretty filename
|
||||
$file_pretty_name = $file->name . '.' . $file->mimetype;
|
||||
|
||||
// Get file path
|
||||
$path = '/files/' . $file->basename;
|
||||
$path = "/files/$user_id/$file->basename";
|
||||
|
||||
// Check if file exist
|
||||
if (!Storage::exists($path)) abort(404);
|
||||
|
||||
$header = [
|
||||
return Storage::response($path, $file_pretty_name, [
|
||||
"Content-Type" => Storage::mimeType($path),
|
||||
"Content-Length" => Storage::size($path),
|
||||
"Accept-Ranges" => "bytes",
|
||||
"Content-Range" => "bytes 0-600/" . Storage::size($path),
|
||||
];
|
||||
|
||||
// Get file
|
||||
return Storage::response($path, $file_pretty_name, $header);
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +154,7 @@ class ServeSharedController extends Controller
|
||||
public function file_public(Share $shared)
|
||||
{
|
||||
// Abort if file is protected
|
||||
if ((int)$shared->is_protected) {
|
||||
if ($shared->is_protected) {
|
||||
abort(403, "Sorry, you don't have permission");
|
||||
}
|
||||
|
||||
@@ -224,10 +211,10 @@ class ServeSharedController extends Controller
|
||||
// Return folder tree
|
||||
return [
|
||||
[
|
||||
'id' => $shared->item_id,
|
||||
'name' => __('vuefilemanager.home'),
|
||||
'location' => 'public',
|
||||
'folders' => $folders,
|
||||
'id' => $shared->item_id,
|
||||
'name' => __('vuefilemanager.home'),
|
||||
'location' => 'public',
|
||||
'folders' => $folders,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ class Share extends Model
|
||||
|
||||
protected $primaryKey = 'token';
|
||||
|
||||
protected $casts = [
|
||||
'is_protected' => 'boolean'
|
||||
];
|
||||
|
||||
/**
|
||||
* Generate share link
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user