mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 16:22:14 +00:00
- enhanced setup:dev script
- refactored shared token creation
This commit is contained in:
@@ -62,9 +62,6 @@ BACKBLAZE_ENDPOINT=
|
|||||||
BACKBLAZE_REGION=
|
BACKBLAZE_REGION=
|
||||||
BACKBLAZE_BUCKET=
|
BACKBLAZE_BUCKET=
|
||||||
|
|
||||||
PASSPORT_CLIENT_ID=
|
|
||||||
PASSPORT_CLIENT_SECRET=
|
|
||||||
|
|
||||||
APP_DEPLOY_SECRET=
|
APP_DEPLOY_SECRET=
|
||||||
|
|
||||||
CASHIER_LOGGER=stack
|
CASHIER_LOGGER=stack
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Folder;
|
||||||
use App\Models\Page;
|
use App\Models\Page;
|
||||||
|
use App\Models\Share;
|
||||||
use App\Services\SetupService;
|
use App\Services\SetupService;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -26,6 +28,8 @@ class SetupDevEnvironment extends Command
|
|||||||
*/
|
*/
|
||||||
protected $description = 'Set up development environment';
|
protected $description = 'Set up development environment';
|
||||||
|
|
||||||
|
private $setup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
*
|
*
|
||||||
@@ -35,7 +39,7 @@ class SetupDevEnvironment extends Command
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->faker = Faker\Factory::create();
|
$this->faker = Faker\Factory::create();
|
||||||
$this->setup = app()->make(SetupService::class);
|
$this->setup = resolve(SetupService::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,10 +54,21 @@ class SetupDevEnvironment extends Command
|
|||||||
$this->info('Creating system directories...');
|
$this->info('Creating system directories...');
|
||||||
$this->setup->create_directories();
|
$this->setup->create_directories();
|
||||||
|
|
||||||
|
$this->info('Migrating Databases...');
|
||||||
$this->migrate_and_generate();
|
$this->migrate_and_generate();
|
||||||
$this->store_data();
|
|
||||||
$this->seed_default_content();
|
$this->info('Storing default settings and content...');
|
||||||
|
$this->store_default_settings();
|
||||||
|
$this->setup->seed_default_pages();
|
||||||
|
$this->setup->seed_default_settings('Extended');
|
||||||
|
|
||||||
|
$this->info('Creating default admin...');
|
||||||
$this->create_admin();
|
$this->create_admin();
|
||||||
|
|
||||||
|
$this->info('Creating default admin content...');
|
||||||
|
$this->create_admin_default_content();
|
||||||
|
|
||||||
|
$this->info('Clearing application cache...');
|
||||||
$this->clear_cache();
|
$this->clear_cache();
|
||||||
|
|
||||||
$this->info('Everything is done, congratulations! 🥳🥳🥳');
|
$this->info('Everything is done, congratulations! 🥳🥳🥳');
|
||||||
@@ -66,15 +81,15 @@ class SetupDevEnvironment extends Command
|
|||||||
{
|
{
|
||||||
$user = User::forceCreate([
|
$user = User::forceCreate([
|
||||||
'role' => 'admin',
|
'role' => 'admin',
|
||||||
'email' => 'john@doe.com',
|
'email' => 'howdy@hi5ve.digital',
|
||||||
'password' => Hash::make('secret'),
|
'password' => Hash::make('vuefilemanager'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user
|
$user
|
||||||
->settings()
|
->settings()
|
||||||
->create([
|
->create([
|
||||||
'storage_capacity' => 5,
|
'storage_capacity' => 5,
|
||||||
'name' => 'John Doe',
|
'name' => 'Jane Doe',
|
||||||
'address' => $this->faker->address,
|
'address' => $this->faker->address,
|
||||||
'state' => $this->faker->state,
|
'state' => $this->faker->state,
|
||||||
'city' => $this->faker->city,
|
'city' => $this->faker->city,
|
||||||
@@ -85,27 +100,167 @@ class SetupDevEnvironment extends Command
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Show user credentials
|
// Show user credentials
|
||||||
$this->info('Default admin account created. Email: john@doe.com and Password: secret');
|
$this->info('Default admin account created. Email: howdy@hi5ve.digital and Password: vuefilemanager');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seed default content to database
|
* Create default admin content
|
||||||
*/
|
*/
|
||||||
private function seed_default_content(): void
|
private function create_admin_default_content(): void
|
||||||
{
|
{
|
||||||
collect(config('content.content'))
|
$user = User::whereEmail('howdy@hi5ve.digital')
|
||||||
->each(function ($content) {
|
->first();
|
||||||
Setting::updateOrCreate($content);
|
|
||||||
});
|
// 1.
|
||||||
|
$shared_folder = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => 'Shared Folder',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Share::factory(Share::class)
|
||||||
|
->create([
|
||||||
|
'type' => 'folder',
|
||||||
|
'item_id' => $shared_folder->id,
|
||||||
|
'permission' => 'editor',
|
||||||
|
'is_protected' => false,
|
||||||
|
'password' => null,
|
||||||
|
'expire_in' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$peters_files = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'parent_id' => $shared_folder->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => "Peter's Files",
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 2.
|
||||||
|
$random_pics = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => 'Random Pics',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$nature = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'parent_id' => $random_pics->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => "Nature",
|
||||||
|
]);
|
||||||
|
|
||||||
|
$apartments = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'parent_id' => $random_pics->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => "Apartments",
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 3.
|
||||||
|
$playable_media = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => 'Playable Media',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$video = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'parent_id' => $playable_media->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => "Video",
|
||||||
|
]);
|
||||||
|
|
||||||
|
$audio = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'parent_id' => $playable_media->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => "Audio",
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 4.
|
||||||
|
$multi_level = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => 'Multi Level Folder',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$first_level = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'parent_id' => $multi_level->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => "First Level",
|
||||||
|
]);
|
||||||
|
|
||||||
|
$second_level = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'parent_id' => $first_level->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => "Second Level",
|
||||||
|
]);
|
||||||
|
|
||||||
|
$third_level = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'parent_id' => $second_level->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => "Third Level",
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 5.
|
||||||
|
$documents = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => 'Documents',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Share::factory(Share::class)
|
||||||
|
->create([
|
||||||
|
'type' => 'folder',
|
||||||
|
'item_id' => $documents->id,
|
||||||
|
'permission' => 'editor',
|
||||||
|
'is_protected' => false,
|
||||||
|
'password' => null,
|
||||||
|
'expire_in' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 6.
|
||||||
|
$videohive = Folder::factory(Folder::class)
|
||||||
|
->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'user_scope' => 'master',
|
||||||
|
'name' => 'Videohive by MakingCG',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user
|
||||||
|
->favouriteFolders()
|
||||||
|
->sync([
|
||||||
|
$shared_folder->id,
|
||||||
|
$random_pics->id,
|
||||||
|
$documents->id,
|
||||||
|
$peters_files->id,
|
||||||
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store main app settings into database
|
* Store main app settings into database
|
||||||
*/
|
*/
|
||||||
private function store_data(): void
|
private function store_default_settings(): void
|
||||||
{
|
{
|
||||||
// Get options
|
// Get options
|
||||||
$settings = collect([
|
collect([
|
||||||
[
|
[
|
||||||
'name' => 'setup_wizard_database',
|
'name' => 'setup_wizard_database',
|
||||||
'value' => 1,
|
'value' => 1,
|
||||||
@@ -162,11 +317,11 @@ class SetupDevEnvironment extends Command
|
|||||||
'name' => 'purchase_code',
|
'name' => 'purchase_code',
|
||||||
'value' => '26b889eb-3602-4bf2-beb3-3sc378fcf484',
|
'value' => '26b889eb-3602-4bf2-beb3-3sc378fcf484',
|
||||||
]
|
]
|
||||||
]);
|
])->each(function ($col) {
|
||||||
|
Setting::forceCreate([
|
||||||
// Store options
|
'name' => $col['name'],
|
||||||
$settings->each(function ($col) {
|
'value' => $col['value']
|
||||||
Setting::updateOrCreate(['name' => $col['name']], $col);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,17 +330,15 @@ class SetupDevEnvironment extends Command
|
|||||||
*/
|
*/
|
||||||
private function migrate_and_generate(): void
|
private function migrate_and_generate(): void
|
||||||
{
|
{
|
||||||
// Generate app key
|
|
||||||
$this->call('key:generate', [
|
|
||||||
'--force' => true
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Migrate database
|
// Migrate database
|
||||||
$this->call('migrate:fresh', [
|
$this->call('migrate:fresh', [
|
||||||
'--force' => true
|
'--force' => true
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->setup->seed_default_pages();
|
// Generate app key
|
||||||
|
$this->call('key:generate', [
|
||||||
|
'--force' => true
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -43,15 +43,8 @@ class ShareController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function store(CreateShareRequest $request, $id)
|
public function store(CreateShareRequest $request, $id)
|
||||||
{
|
{
|
||||||
// TODO: poriesit binarny string
|
|
||||||
do {
|
|
||||||
// Generate unique token
|
|
||||||
$token = Str::random(16);
|
|
||||||
|
|
||||||
} while (Share::where('token', $token)->exists());
|
|
||||||
|
|
||||||
// Create shared options
|
// Create shared options
|
||||||
$options = [
|
$shared = Share::create([
|
||||||
'password' => $request->has('password') ? Hash::make($request->password) : null,
|
'password' => $request->has('password') ? Hash::make($request->password) : null,
|
||||||
'type' => $request->type === 'folder' ? 'folder' : 'file',
|
'type' => $request->type === 'folder' ? 'folder' : 'file',
|
||||||
'is_protected' => $request->isPassword,
|
'is_protected' => $request->isPassword,
|
||||||
@@ -59,8 +52,7 @@ class ShareController extends Controller
|
|||||||
'item_id' => $id,
|
'item_id' => $id,
|
||||||
'expire_in' => $request->expiration ?? null,
|
'expire_in' => $request->expiration ?? null,
|
||||||
'user_id' => Auth::id(),
|
'user_id' => Auth::id(),
|
||||||
'token' => $token,
|
]);
|
||||||
];
|
|
||||||
|
|
||||||
// Send shared link via email
|
// Send shared link via email
|
||||||
if ($request->has('emails')) {
|
if ($request->has('emails')) {
|
||||||
@@ -68,13 +60,13 @@ class ShareController extends Controller
|
|||||||
foreach ($request->emails as $email) {
|
foreach ($request->emails as $email) {
|
||||||
|
|
||||||
Notification::route('mail', $email)->notify(
|
Notification::route('mail', $email)->notify(
|
||||||
new SharedSendViaEmail($token)
|
new SharedSendViaEmail($shared->token)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return created shared record
|
// Return created shared record
|
||||||
return new ShareResource(Share::create($options));
|
return new ShareResource($shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -43,8 +43,9 @@ class Share extends Model
|
|||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
static::creating(function ($model) {
|
static::creating(function ($shared) {
|
||||||
$model->id = (string)Str::uuid();
|
$shared->id = (string)Str::uuid();
|
||||||
|
$shared->token = Str::random(16);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class CreateFileManagerFiles extends Migration
|
|||||||
$table->text('name');
|
$table->text('name');
|
||||||
$table->text('basename');
|
$table->text('basename');
|
||||||
|
|
||||||
$table->text('mimetype')->nullable()->index();
|
$table->text('mimetype')->nullable();
|
||||||
$table->text('filesize');
|
$table->text('filesize');
|
||||||
|
|
||||||
$table->text('type')->nullable();
|
$table->text('type')->nullable();
|
||||||
|
|||||||
Reference in New Issue
Block a user