From 74f5dc5db142eb02e5cda507ab9d984789f1646b Mon Sep 17 00:00:00 2001 From: Javier Feliz Date: Tue, 22 Jul 2025 19:45:33 -0400 Subject: [PATCH] Initial test --- app/Livewire/Forms/NewScript.php | 33 +++ app/Models/Script.php | 20 ++ app/Models/User.php | 8 +- ...2025_07_22_221405_create_scripts_table.php | 32 +++ .../views/components/layouts/app.blade.php | 4 +- .../components/layouts/app/header.blade.php | 199 +++++++++--------- resources/views/dashboard.blade.php | 25 +-- .../views/livewire/forms/new-script.blade.php | 18 ++ resources/views/partials/head.blade.php | 2 +- resources/views/script.blade.php | 49 +++++ routes/auth.php | 5 +- routes/web.php | 15 +- vite.config.js | 1 + 13 files changed, 290 insertions(+), 121 deletions(-) create mode 100644 app/Livewire/Forms/NewScript.php create mode 100644 app/Models/Script.php create mode 100644 database/migrations/2025_07_22_221405_create_scripts_table.php create mode 100644 resources/views/livewire/forms/new-script.blade.php create mode 100644 resources/views/script.blade.php diff --git a/app/Livewire/Forms/NewScript.php b/app/Livewire/Forms/NewScript.php new file mode 100644 index 0000000..0be1eb4 --- /dev/null +++ b/app/Livewire/Forms/NewScript.php @@ -0,0 +1,33 @@ +validate(); + auth()->user()->scripts()->create([ + 'name' => $this->name, + 'path' => str($this->path)->remove('.sh')->lower()->kebab()->toString(), + 'content' => $this->content + ]); + + $this->reset(['name', 'path', 'content']); + } + + public function render() + { + return view('livewire.forms.new-script'); + } +} diff --git a/app/Models/Script.php b/app/Models/Script.php new file mode 100644 index 0000000..881340a --- /dev/null +++ b/app/Models/Script.php @@ -0,0 +1,20 @@ + $this->path]); + } + + public function contentUrl() + { + return route('script-content', ['path' => $this->path]); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 3cb5ccb..d914de9 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,6 +4,7 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Str; @@ -55,7 +56,12 @@ class User extends Authenticatable return Str::of($this->name) ->explode(' ') ->take(2) - ->map(fn ($word) => Str::substr($word, 0, 1)) + ->map(fn($word) => Str::substr($word, 0, 1)) ->implode(''); } + + public function scripts(): HasMany + { + return $this->hasMany(Script::class); + } } diff --git a/database/migrations/2025_07_22_221405_create_scripts_table.php b/database/migrations/2025_07_22_221405_create_scripts_table.php new file mode 100644 index 0000000..7533c96 --- /dev/null +++ b/database/migrations/2025_07_22_221405_create_scripts_table.php @@ -0,0 +1,32 @@ +id(); + $table->foreignIdFor(User::class); + $table->string('name'); + $table->string('path'); + $table->longText('content'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('scripts'); + } +}; diff --git a/resources/views/components/layouts/app.blade.php b/resources/views/components/layouts/app.blade.php index 3d15107..6dec043 100644 --- a/resources/views/components/layouts/app.blade.php +++ b/resources/views/components/layouts/app.blade.php @@ -1,5 +1,5 @@ - + {{ $slot }} - + \ No newline at end of file diff --git a/resources/views/components/layouts/app/header.blade.php b/resources/views/components/layouts/app/header.blade.php index f017f67..4d57647 100644 --- a/resources/views/components/layouts/app/header.blade.php +++ b/resources/views/components/layouts/app/header.blade.php @@ -1,124 +1,121 @@ - - @include('partials.head') - - - - - - - + + @include('partials.head') + - - - {{ __('Dashboard') }} - - + + + - + + + - - - - - - - - - - - + + + {{ __('Dashboard') }} + + - - - + - - -
-
- - - {{ auth()->user()->initials() }} - + + + + + + + + + + + + + + + + + + +
+
+ + + {{ auth()->user()->initials() }} + -
- {{ auth()->user()->name }} - {{ auth()->user()->email }} -
+
+ {{ auth()->user()->name }} + {{ auth()->user()->email }}
- +
+
- + - - {{ __('Settings') }} - + + {{ __('Settings') }} + + - + -
- @csrf - - {{ __('Log Out') }} - -
-
-
- +
+ @csrf + + {{ __('Log Out') }} + +
+ + + - - - + + + - - - + + + - - - - {{ __('Dashboard') }} - - - - - - - - - {{ __('Repository') }} + + + + {{ __('Dashboard') }} + + - - {{ __('Documentation') }} - - - + - {{ $slot }} + + + {{ __('Repository') }} + - @fluxScripts - - + + {{ __('Documentation') }} + + + + + {{ $slot }} + + @fluxScripts + + + \ No newline at end of file diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 5b4558d..4a9a4b0 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -1,18 +1,15 @@ -
-
-
- +
+ +
+ @foreach (auth()->user()->scripts as $s) +
+ {{ $s->name }} +
+ View +
-
- -
-
- -
-
-
- + @endforeach
- + \ No newline at end of file diff --git a/resources/views/livewire/forms/new-script.blade.php b/resources/views/livewire/forms/new-script.blade.php new file mode 100644 index 0000000..d32e403 --- /dev/null +++ b/resources/views/livewire/forms/new-script.blade.php @@ -0,0 +1,18 @@ +
+ New Script +
+
+ +
+ + Path + + {{ config('app.url') }}/ + + + +
+ + + Create + \ No newline at end of file diff --git a/resources/views/partials/head.blade.php b/resources/views/partials/head.blade.php index dce8058..2009ccb 100644 --- a/resources/views/partials/head.blade.php +++ b/resources/views/partials/head.blade.php @@ -11,4 +11,4 @@ @vite(['resources/css/app.css', 'resources/js/app.js']) -@fluxAppearance +@fluxAppearance \ No newline at end of file diff --git a/resources/views/script.blade.php b/resources/views/script.blade.php new file mode 100644 index 0000000..f7e9d8e --- /dev/null +++ b/resources/views/script.blade.php @@ -0,0 +1,49 @@ + + + + + + + @include('partials.head') + + {{ $script->name }} + + + + @php + $copystring = "curl -fsSL ".route('script-content', ['path' => $script->path]).' | sh'; + @endphp +
+ {{ $script->name }} +
+
+

+
+                
+                    
+                        
+                    
+                    Copied!
+                
+            
+ +
{{$script->content}}
+ +
+
+ + @fluxScripts + + + + + \ No newline at end of file diff --git a/routes/auth.php b/routes/auth.php index 031f43c..0280c28 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -7,11 +7,14 @@ use App\Livewire\Auth\Login; use App\Livewire\Auth\Register; use App\Livewire\Auth\ResetPassword; use App\Livewire\Auth\VerifyEmail; +use App\Models\User; use Illuminate\Support\Facades\Route; Route::middleware('guest')->group(function () { Route::get('login', Login::class)->name('login'); - Route::get('register', Register::class)->name('register'); + if (User::count() == 0) { + Route::get('register', Register::class)->name('register'); + } Route::get('forgot-password', ForgotPassword::class)->name('password.request'); Route::get('reset-password/{token}', ResetPassword::class)->name('password.reset'); }); diff --git a/routes/web.php b/routes/web.php index 910db32..11d3b22 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,6 +3,7 @@ use App\Livewire\Settings\Appearance; use App\Livewire\Settings\Password; use App\Livewire\Settings\Profile; +use App\Models\Script; use Illuminate\Support\Facades\Route; Route::get('/', function () { @@ -21,4 +22,16 @@ Route::middleware(['auth'])->group(function () { Route::get('settings/appearance', Appearance::class)->name('settings.appearance'); }); -require __DIR__.'/auth.php'; +require __DIR__ . '/auth.php'; + +Route::get("{path}.sh", function (string $path) { + $script = Script::where('path', $path)->firstOrFail(); + + return response($script->content, 200)->header('Content-Type', 'text/plain'); +})->name('script-content'); + +Route::get("{path}", function (string $path) { + $script = Script::where('path', $path)->firstOrFail(); + + return view('script', compact('script')); +})->name('script-view'); diff --git a/vite.config.js b/vite.config.js index 75a8c16..dd77dce 100644 --- a/vite.config.js +++ b/vite.config.js @@ -14,5 +14,6 @@ export default defineConfig({ ], server: { cors: true, + host: "scripthost.test" }, }); \ No newline at end of file