Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Livewire\Actions\Api;
namespace App\Actions\Api;

use App\Enums\MediaType;
use App\Models\Media;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Livewire\Actions\Api\Spotify;
namespace App\Actions\Api\Spotify;

use App\Enums\ConnectionType;
use App\Models\User;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Livewire\Actions\Api\Spotify;
namespace App\Actions\Api\Spotify;

use App\Enums\ConnectionType;
use App\Enums\MediaType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Livewire\Actions\Api\Spotify;
namespace App\Actions\Api\Spotify;

use App\Enums\ConnectionType;
use App\Enums\MediaType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Livewire\Actions\Api\Twitch;
namespace App\Actions\Api\Twitch;

use App\Enums\ConnectionType;
use App\Models\User;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Livewire\Actions\Api\Twitch;
namespace App\Actions\Api\Twitch;

use App\Enums\ConnectionType;
use App\Enums\MediaType;
Expand Down Expand Up @@ -42,7 +42,7 @@ public function search(User $user, string $phrase, MediaType $mediaType)

return collect();
}

/* disgusting hack to get high rez images from this endpoint */
private function fix_box_art(string $string): string
{
Expand Down
44 changes: 44 additions & 0 deletions app/Actions/Blog/DestroyBlogPost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Actions\Blog;

use App\Models\DocumentView;
use Exception;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Prezet\Prezet\Models\Document;

final class DestroyBlogPost
{
public function handle(int $id): bool
{
$document = DB::connection('prezet')->table('documents')->find($id);

if (! $document) {
return false;
}

try {
Storage::disk('prezet')->delete("content/{$document->slug}.md");

DB::connection('prezet')->table('document_tags')->where('document_id', $id)->delete();

$imageDirectory = "images/{$document->slug}";

if (Storage::disk('prezet')->exists($imageDirectory)) {
Storage::disk('prezet')->deleteDirectory($imageDirectory);
}

Document::where('id', $id)->delete();

DocumentView::where('document_id', $id)->delete();

Artisan::call('prezet:index');

return true;
} catch (Exception) {
return false;
}
}
}
38 changes: 38 additions & 0 deletions app/Actions/Blog/StoreBlogPost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Actions\Blog;

use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Artisan;
use Prezet\Prezet\Models\Document;

final class StoreBlogPost
{
/**
* @param array<int, UploadedFile> $images
*/
public function handle(UploadedFile $file, array $images = []): void
{
$file->storeAs(
path: '/content',
name: $file->getClientOriginalName(),
options: ['disk' => 'prezet']
);

Artisan::call('prezet:index');

$document = Document::query()->latest()->first();

if ($document && $images) {
foreach ($images as $image) {
$image->storeAs(
path: "images/{$document->slug}",
name: $image->getClientOriginalName(),
options: ['disk' => 'prezet']
);
}

Artisan::call('prezet:index');
}
}
}
17 changes: 17 additions & 0 deletions app/Actions/Logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Actions;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

final class Logout
{
public function __invoke(): void
{
Auth::guard('web')->logout();

Session::invalidate();
Session::regenerateToken();
}
}
12 changes: 8 additions & 4 deletions app/Console/Commands/CheckTwitchLiveStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Console\Commands;

use App\Actions\Api\Twitch\RefreshToken;
use App\Enums\ConnectionType;
use App\Livewire\Actions\Api\Twitch\RefreshToken;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
Expand All @@ -13,6 +13,7 @@
class CheckTwitchLiveStatus extends Command
{
protected $signature = 'twitch:check-live';

protected $description = 'Check if spacelampsix is live on Twitch and notify Discord';

public function handle(): int
Expand All @@ -31,28 +32,31 @@ public function handle(): int

if (! $stream) {
$this->info('spacelampsix is not currently live.');

return self::SUCCESS;
}

$startedAt = $stream['started_at'];

if ($this->alreadyNotified($startedAt)) {
$this->info('Already notified for this stream session.');

return self::SUCCESS;
}

$this->notifyDiscord($stream);
$this->recordNotification($startedAt);

$this->info('Discord notification sent!');

return self::SUCCESS;
}

private function getStreamData(string $token): ?array
{
$response = Http::withHeaders([
'Client-ID' => config('services.twitch.client_id'),
'Authorization' => 'Bearer ' . $token,
'Authorization' => 'Bearer '.$token,
])->get('https://api.twitch.tv/helix/streams', [
'user_login' => 'spacelampsix',
]);
Expand Down Expand Up @@ -87,6 +91,6 @@ private function notifyDiscord(array $stream): void
],
]);

Log::channel('discord-internal-updates')->info("Discord notified of live stream successfully. Have a great stream!");
Log::channel('discord-internal-updates')->info('Discord notified of live stream successfully. Have a great stream!');
}
}
}
4 changes: 2 additions & 2 deletions app/Console/Commands/RefreshTwitchAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Livewire\Actions\Api\Twitch\RefreshToken;
use App\Actions\Api\Twitch\RefreshToken;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
Expand Down Expand Up @@ -30,6 +30,6 @@ public function handle()
{
(new RefreshToken)->handle(User::first());

Log::channel('discord-internal-updates')->info("Twitch Token updated automatically.");
Log::channel('discord-internal-updates')->info('Twitch Token updated automatically.');
}
}
6 changes: 3 additions & 3 deletions app/Console/Commands/UpdateArtistImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Console\Commands;

use App\Actions\Api\Spotify\RefreshToken;
use App\Enums\ConnectionType;
use App\Enums\MediaType;
use App\Livewire\Actions\Api\Spotify\RefreshToken;
use App\Models\Media;
use App\Models\User;
use GuzzleHttp\Client;
Expand Down Expand Up @@ -34,7 +34,7 @@ public function handle()
'GET',
"https://api.spotify.com/v1/artists?ids={$ids}", [
'headers' => [
'Authorization' => 'Bearer '. $user->connections->firstWhere('type_id', ConnectionType::SPOTIFY->value)->token,
'Authorization' => 'Bearer '.$user->connections->firstWhere('type_id', ConnectionType::SPOTIFY->value)->token,
],
]
);
Expand All @@ -59,4 +59,4 @@ public function handle()

return Command::SUCCESS;
}
}
}
65 changes: 9 additions & 56 deletions app/Livewire/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace App\Livewire;

use App\Actions\Blog\DestroyBlogPost;
use App\Actions\Blog\StoreBlogPost;
use App\Livewire\Traits\TableHelpers;
use App\Models\DocumentView;
use Flux\Flux;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Validate;
use Livewire\Component;
Expand Down Expand Up @@ -36,29 +36,7 @@ public function store()
{
$this->validate();

$this->file->storeAs(
path: '/content',
name: $this->file->getClientOriginalName(),
options: ['disk' => 'prezet']
);

/* index in prezet disk */
Artisan::call('prezet:index');

$document = Document::query()->latest()->first();

if ($document && $this->images) {
foreach ($this->images as $image) {
$image->storeAs(
path: "images/{$document->slug}",
name: $image->getClientOriginalName(),
options: ['disk' => 'prezet']
);
}

/* index in prezet disk again (for the images) */
Artisan::call('prezet:index');
}
(new StoreBlogPost)->handle($this->file, $this->images);

$this->file = null;
$this->images = [];
Expand All @@ -68,38 +46,13 @@ public function store()

public function destroy($id)
{
$document = DB::connection('prezet')->table('documents')->find($id);

if ($document) {
try {
/* delete the file */
Storage::disk('prezet')->delete("content/{$document->slug}.md");

/* delete the tags */
DB::connection('prezet')->table('document_tags')->where('document_id', $id)->delete();
$success = (new DestroyBlogPost)->handle($id);

/* delete images if there are any */
$imageDirectory = "images/{$document->slug}";

if (Storage::disk('prezet')->exists($imageDirectory)) {
Storage::disk('prezet')->deleteDirectory($imageDirectory);
}

/* delete the reference */
Document::where('id', $id)->delete();

/* delete the views */
DocumentView::where('document_id', $id)->delete();

/* Index the sqlite db */
Artisan::call('prezet:index');

} catch (Exception) {
Flux::toast(variant: 'danger', text: 'Blog Post could not be deleted.', duration: 3000);
}

Flux::toast(variant: 'success', text: 'Blog Post deleted.', duration: 3000);
}
Flux::toast(
variant: $success ? 'success' : 'danger',
text: $success ? 'Blog Post deleted.' : 'Blog Post could not be deleted.',
duration: 3000,
);
}

#[Computed]
Expand Down
6 changes: 3 additions & 3 deletions app/Livewire/Forms/LoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Livewire\Forms;

use App\Livewire\Actions\Api\Spotify\RefreshToken as SpotifyRefreshToken;
use App\Livewire\Actions\Api\Twitch\RefreshToken as TwitchRefreshToken;
use App\Actions\Api\Spotify\RefreshToken as SpotifyRefreshToken;
use App\Actions\Api\Twitch\RefreshToken as TwitchRefreshToken;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
Expand All @@ -26,7 +26,7 @@ class LoginForm extends Form
/**
* Attempt to authenticate the request's credentials.
*
* @throws \Illuminate\Validation\ValidationException
* @throws ValidationException
*/
public function authenticate(): void
{
Expand Down
5 changes: 3 additions & 2 deletions app/Livewire/Media/Games/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Livewire\Media\Games;

use App\Actions\Api\Twitch\SearchCategories;
use App\Enums\MediaType;
use App\Livewire\Actions\Api\Twitch\SearchCategories;
use App\Livewire\Forms\MediaForm;
use App\Livewire\Traits\TableHelpers;
use App\Models\Media;
Expand Down Expand Up @@ -39,7 +39,8 @@ public function games()
return Media::query()
->where('type_id', MediaType::VIDEO_GAME->value)
->when($this->search != '', fn (Builder $query) => $query->where('name', 'LIKE', "%$this->search%"))
->paginate(10);
->tap(fn ($query) => $this->sortBy ? $query->orderBy($this->sortBy, $this->sortDirection) : $query)
->paginate($this->perPage);
}

public function searchCategories()
Expand Down
Loading
Loading