build: initialize RetroHub with Laravel, Inertia, Vue, and Horizon
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Consoles\Controllers;
|
||||
|
||||
use App\Features\Consoles\Data\ConsoleData;
|
||||
use App\Features\Consoles\Services\ConsoleService;
|
||||
use App\Features\Games\Repositories\GameRepository;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class ConsoleController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private ConsoleService $consoleService,
|
||||
private GameRepository $gameRepository
|
||||
) {}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
$consoles = $this->consoleService->getAll()
|
||||
->map(fn ($console) => ConsoleData::fromModel($console));
|
||||
|
||||
return Inertia::render('Consoles/Index', [
|
||||
'consoles' => $consoles,
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(string $slug): Response
|
||||
{
|
||||
$console = $this->consoleService->getBySlug($slug);
|
||||
abort_unless($console, 404);
|
||||
|
||||
$games = $this->gameRepository->getByConsole($console->id);
|
||||
|
||||
return Inertia::render('Consoles/Show', [
|
||||
'selectedConsole' => ConsoleData::fromModel($console->loadCount('games')),
|
||||
'games' => $games,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Consoles\Data;
|
||||
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
#[MapInputName(SnakeCaseMapper::class)]
|
||||
class ConsoleData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $name,
|
||||
public string $slug,
|
||||
public ?string $iconPath,
|
||||
public array $romExtensions,
|
||||
public ?int $igdbPlatformId,
|
||||
public ?int $tgdbPlatformId,
|
||||
public int $gamesCount,
|
||||
) {}
|
||||
|
||||
public static function fromModel(Console $console): self
|
||||
{
|
||||
return new self(
|
||||
id: $console->id,
|
||||
name: $console->name,
|
||||
slug: $console->slug,
|
||||
iconPath: $console->icon_path,
|
||||
romExtensions: $console->rom_extensions,
|
||||
igdbPlatformId: $console->igdb_platform_id,
|
||||
tgdbPlatformId: $console->tgdb_platform_id,
|
||||
gamesCount: $console->games_count ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Consoles\Models;
|
||||
|
||||
use App\Features\Games\Models\Game;
|
||||
use Database\Factories\ConsoleFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Console extends Model
|
||||
{
|
||||
/** @use HasFactory<ConsoleFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected static ?string $factory = ConsoleFactory::class;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'icon_path',
|
||||
'rom_extensions',
|
||||
'igdb_platform_id',
|
||||
'tgdb_platform_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'rom_extensions' => 'array',
|
||||
];
|
||||
|
||||
public function games(): HasMany
|
||||
{
|
||||
return $this->hasMany(Game::class);
|
||||
}
|
||||
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'slug';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Consoles\Repositories;
|
||||
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ConsoleRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Console $model
|
||||
) {}
|
||||
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return $this->model->withCount('games')->orderBy('name')->get();
|
||||
}
|
||||
|
||||
public function getBySlug(string $slug): ?Console
|
||||
{
|
||||
return $this->model->where('slug', $slug)->first();
|
||||
}
|
||||
|
||||
public function getWithGamesCount(): Collection
|
||||
{
|
||||
return $this->model->withCount('games')->orderBy('name')->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Consoles\Services;
|
||||
|
||||
use App\Features\Consoles\Repositories\ConsoleRepository;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ConsoleService
|
||||
{
|
||||
public function __construct(
|
||||
private ConsoleRepository $repository
|
||||
) {}
|
||||
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return $this->repository->getAll();
|
||||
}
|
||||
|
||||
public function getBySlug(string $slug)
|
||||
{
|
||||
return $this->repository->getBySlug($slug);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Games\Controllers;
|
||||
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use App\Features\Games\Data\GameData;
|
||||
use App\Features\Games\Repositories\GameRepository;
|
||||
use App\Features\Games\Repositories\RomFileRepository;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class GameController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private GameRepository $gameRepository,
|
||||
private RomFileRepository $romFileRepository
|
||||
) {}
|
||||
|
||||
public function show(string $slug): Response
|
||||
{
|
||||
$game = $this->gameRepository->getBySlug($slug);
|
||||
abort_unless($game, 404);
|
||||
|
||||
return Inertia::render('Games/Show', [
|
||||
'game' => GameData::fromModel($game),
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(string $slug): Response
|
||||
{
|
||||
$game = $this->gameRepository->getBySlug($slug);
|
||||
abort_unless($game, 404);
|
||||
|
||||
return Inertia::render('Games/Edit', [
|
||||
'game' => GameData::fromModel($game),
|
||||
'consoles' => Console::orderBy('name')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, string $slug): RedirectResponse
|
||||
{
|
||||
$game = $this->gameRepository->getBySlug($slug);
|
||||
abort_unless($game, 404);
|
||||
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'release_year' => 'nullable|integer|min:1970|max:2030',
|
||||
'developer' => 'nullable|string|max:255',
|
||||
'publisher' => 'nullable|string|max:255',
|
||||
'genre' => 'nullable|string|max:255',
|
||||
'rating' => 'nullable|numeric|min:0|max:10',
|
||||
]);
|
||||
|
||||
$game->update($validated);
|
||||
|
||||
return redirect()->route('games.show', $game)
|
||||
->with('success', 'Game updated successfully.');
|
||||
}
|
||||
|
||||
public function destroy(string $slug): RedirectResponse
|
||||
{
|
||||
$game = $this->gameRepository->getBySlug($slug);
|
||||
abort_unless($game, 404);
|
||||
|
||||
$romFiles = $this->romFileRepository->getByGame($game->id);
|
||||
foreach ($romFiles as $romFile) {
|
||||
Storage::disk('local')->delete($romFile->file_path);
|
||||
$romFile->delete();
|
||||
}
|
||||
|
||||
if ($game->cover_path) {
|
||||
Storage::disk('local')->delete($game->cover_path);
|
||||
}
|
||||
|
||||
$console = $game->console;
|
||||
$game->delete();
|
||||
|
||||
return redirect()->route('consoles.show', $console->slug)
|
||||
->with('success', 'Game deleted successfully.');
|
||||
}
|
||||
|
||||
public function download(string $slug, int $romFileId): StreamedResponse
|
||||
{
|
||||
$game = $this->gameRepository->getBySlug($slug);
|
||||
abort_unless($game, 404);
|
||||
|
||||
$romFile = $this->romFileRepository->getByGame($game->id)->where('id', $romFileId)->first();
|
||||
abort_unless($romFile, 404);
|
||||
|
||||
return Storage::disk('local')->download(
|
||||
$romFile->file_path,
|
||||
$romFile->file_name
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Games\Data;
|
||||
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
#[MapInputName(SnakeCaseMapper::class)]
|
||||
class DashboardStatsData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public int $totalGames,
|
||||
public int $totalConsoles,
|
||||
public int $totalRoms,
|
||||
public int $userSaves,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Games\Data;
|
||||
|
||||
use App\Features\Consoles\Data\ConsoleData;
|
||||
use App\Features\Games\Models\Game;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
#[MapInputName(SnakeCaseMapper::class)]
|
||||
class GameData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public int $consoleId,
|
||||
public string $title,
|
||||
public string $slug,
|
||||
public ?int $igdbId,
|
||||
public ?int $tgdbId,
|
||||
public ?string $description,
|
||||
public ?int $releaseYear,
|
||||
public ?string $developer,
|
||||
public ?string $publisher,
|
||||
public ?string $genre,
|
||||
public ?float $rating,
|
||||
public ?string $coverPath,
|
||||
public ?string $thumbnailPath,
|
||||
public ?ConsoleData $console,
|
||||
public ?array $romFiles,
|
||||
) {}
|
||||
|
||||
public static function fromModel(Game $game): self
|
||||
{
|
||||
return new self(
|
||||
id: $game->id,
|
||||
consoleId: $game->console_id,
|
||||
title: $game->title,
|
||||
slug: $game->slug,
|
||||
igdbId: $game->igdb_id,
|
||||
tgdbId: $game->tgdb_id,
|
||||
description: $game->description,
|
||||
releaseYear: $game->release_year,
|
||||
developer: $game->developer,
|
||||
publisher: $game->publisher,
|
||||
genre: $game->genre,
|
||||
rating: $game->rating ? (float) $game->rating : null,
|
||||
coverPath: $game->cover_path,
|
||||
thumbnailPath: $game->thumbnail_path,
|
||||
console: $game->relationLoaded('console') && $game->console
|
||||
? ConsoleData::fromModel($game->console)
|
||||
: null,
|
||||
romFiles: $game->relationLoaded('romFiles')
|
||||
? $game->romFiles->map(fn ($rom) => RomFileData::fromModel($rom))->toArray()
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Games\Data;
|
||||
|
||||
use App\Features\Games\Models\RomFile;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
#[MapInputName(SnakeCaseMapper::class)]
|
||||
class RomFileData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public int $gameId,
|
||||
public string $filePath,
|
||||
public string $fileName,
|
||||
public int $fileSize,
|
||||
public string $fileHash,
|
||||
public ?string $region,
|
||||
public ?string $language,
|
||||
) {}
|
||||
|
||||
public static function fromModel(RomFile $romFile): self
|
||||
{
|
||||
return new self(
|
||||
id: $romFile->id,
|
||||
gameId: $romFile->game_id,
|
||||
filePath: $romFile->file_path,
|
||||
fileName: $romFile->file_name,
|
||||
fileSize: $romFile->file_size,
|
||||
fileHash: $romFile->file_hash,
|
||||
region: $romFile->region,
|
||||
language: $romFile->language,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Games\Models;
|
||||
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use App\Features\Settings\Models\SaveFile;
|
||||
use Database\Factories\GameFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Game extends Model
|
||||
{
|
||||
/** @use HasFactory<GameFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected static ?string $factory = GameFactory::class;
|
||||
|
||||
protected $fillable = [
|
||||
'console_id',
|
||||
'title',
|
||||
'slug',
|
||||
'igdb_id',
|
||||
'tgdb_id',
|
||||
'description',
|
||||
'release_year',
|
||||
'developer',
|
||||
'publisher',
|
||||
'genre',
|
||||
'rating',
|
||||
'cover_path',
|
||||
'thumbnail_path',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'rating' => 'decimal:1',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (Game $game) {
|
||||
if (empty($game->slug)) {
|
||||
$game->slug = Str::slug($game->title);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function console(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Console::class);
|
||||
}
|
||||
|
||||
public function romFiles(): HasMany
|
||||
{
|
||||
return $this->hasMany(RomFile::class);
|
||||
}
|
||||
|
||||
public function saveFiles(): HasMany
|
||||
{
|
||||
return $this->hasMany(SaveFile::class);
|
||||
}
|
||||
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'slug';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Games\Models;
|
||||
|
||||
use Database\Factories\RomFileFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class RomFile extends Model
|
||||
{
|
||||
/** @use HasFactory<RomFileFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected static ?string $factory = RomFileFactory::class;
|
||||
|
||||
protected $fillable = [
|
||||
'game_id',
|
||||
'file_path',
|
||||
'file_name',
|
||||
'file_size',
|
||||
'file_hash',
|
||||
'region',
|
||||
'language',
|
||||
];
|
||||
|
||||
public function game(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Game::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Games\Repositories;
|
||||
|
||||
use App\Features\Games\Models\Game;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class GameRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Game $model
|
||||
) {}
|
||||
|
||||
public function getByConsole(int $consoleId, int $perPage = 24): LengthAwarePaginator
|
||||
{
|
||||
return $this->model
|
||||
->where('console_id', $consoleId)
|
||||
->with('romFiles')
|
||||
->orderBy('title')
|
||||
->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getBySlug(string $slug): ?Game
|
||||
{
|
||||
return $this->model
|
||||
->with(['console', 'romFiles'])
|
||||
->where('slug', $slug)
|
||||
->first();
|
||||
}
|
||||
|
||||
public function getRecent(int $limit = 10): Collection
|
||||
{
|
||||
return $this->model
|
||||
->with('console')
|
||||
->latest()
|
||||
->take($limit)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function search(string $query): Collection
|
||||
{
|
||||
return $this->model
|
||||
->with('console')
|
||||
->where('title', 'like', "%{$query}%")
|
||||
->orderBy('title')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
return $this->model
|
||||
->with('console')
|
||||
->orderBy('title')
|
||||
->paginate(24);
|
||||
}
|
||||
|
||||
public function create(array $data): Game
|
||||
{
|
||||
return $this->model->create($data);
|
||||
}
|
||||
|
||||
public function firstOrCreate(array $conditions, array $values = []): Game
|
||||
{
|
||||
return $this->model->firstOrCreate($conditions, $values);
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return $this->model->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Games\Repositories;
|
||||
|
||||
use App\Features\Games\Models\RomFile;
|
||||
|
||||
class RomFileRepository
|
||||
{
|
||||
public function __construct(
|
||||
private RomFile $model
|
||||
) {}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return $this->model->count();
|
||||
}
|
||||
|
||||
public function findByHash(string $hash): ?RomFile
|
||||
{
|
||||
return $this->model->where('file_hash', $hash)->first();
|
||||
}
|
||||
|
||||
public function create(array $data): RomFile
|
||||
{
|
||||
return $this->model->create($data);
|
||||
}
|
||||
|
||||
public function getByGame(int $gameId)
|
||||
{
|
||||
return $this->model->where('game_id', $gameId)->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Scraper\Controllers;
|
||||
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use App\Features\Games\Models\Game;
|
||||
use App\Features\Scraper\Data\ScraperResultData;
|
||||
use App\Features\Scraper\Services\ScraperService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class ScraperController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private ScraperService $scraper
|
||||
) {}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
return Inertia::render('Scraper/Index', [
|
||||
'consoles' => Console::orderBy('name')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function search(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'query' => 'required|string|min:2',
|
||||
'console' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$results = $this->scraper->search(
|
||||
$request->query('query'),
|
||||
$request->query('console')
|
||||
)->map(fn ($result) => ScraperResultData::from($result));
|
||||
|
||||
return response()->json(['results' => $results]);
|
||||
}
|
||||
|
||||
public function apply(Request $request, string $slug): RedirectResponse
|
||||
{
|
||||
$game = Game::where('slug', $slug)->firstOrFail();
|
||||
|
||||
$request->validate([
|
||||
'cover_url' => 'required|url',
|
||||
]);
|
||||
|
||||
$path = $this->scraper->downloadCover(
|
||||
$request->cover_url,
|
||||
$game
|
||||
);
|
||||
|
||||
$game->update(['cover_path' => $path]);
|
||||
|
||||
return redirect()->route('games.show', $game)
|
||||
->with('success', 'Cover updated successfully.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Scraper\Data;
|
||||
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
#[MapInputName(SnakeCaseMapper::class)]
|
||||
class ScraperResultData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $title,
|
||||
public ?string $coverUrl,
|
||||
public ?string $year,
|
||||
public string $source,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Scraper\Services;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
interface CoverScraperInterface
|
||||
{
|
||||
public function search(string $query, ?int $consoleId = null): Collection;
|
||||
|
||||
public function getCoverUrl(int $externalId): ?string;
|
||||
|
||||
public function getScreenshotUrl(int $externalId): ?string;
|
||||
|
||||
public function getImages(int $externalId): array;
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Scraper\Services;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class IGDBCoverScraper implements CoverScraperInterface
|
||||
{
|
||||
private string $clientId;
|
||||
|
||||
private string $clientSecret;
|
||||
|
||||
private ?string $accessToken = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->clientId = config('services.igdb.client_id', '');
|
||||
$this->clientSecret = config('services.igdb.client_secret', '');
|
||||
}
|
||||
|
||||
public function search(string $query, ?int $consoleId = null): Collection
|
||||
{
|
||||
if (empty($this->clientId) || empty($this->clientSecret)) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$body = "search \"{$query}\"; fields name,cover.url,platforms,release_dates.year;";
|
||||
if ($consoleId) {
|
||||
$body .= " where platforms = [{$consoleId}];";
|
||||
}
|
||||
|
||||
$response = $this->makeRequest('/games', $body);
|
||||
|
||||
return collect($response)->map(fn ($game) => [
|
||||
'id' => $game['id'],
|
||||
'title' => $game['name'],
|
||||
'cover_url' => isset($game['cover']['url'])
|
||||
? str_replace('thumb', 'cover_big', $game['cover']['url'])
|
||||
: null,
|
||||
'year' => $game['release_dates'][0]['year'] ?? null,
|
||||
'source' => 'igdb',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getCoverUrl(int $externalId): ?string
|
||||
{
|
||||
if (empty($this->clientId) || empty($this->clientSecret)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$response = $this->makeRequest(
|
||||
'/covers',
|
||||
"fields url; where game = {$externalId};"
|
||||
);
|
||||
|
||||
if (! empty($response[0]['url'])) {
|
||||
return str_replace('thumb', 'cover_big', $response[0]['url']);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getScreenshotUrl(int $externalId): ?string
|
||||
{
|
||||
if (empty($this->clientId) || empty($this->clientSecret)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$response = $this->makeRequest(
|
||||
'/screenshots',
|
||||
"fields url; where game = {$externalId};"
|
||||
);
|
||||
|
||||
return $response[0]['url'] ?? null;
|
||||
}
|
||||
|
||||
public function getImages(int $externalId): array
|
||||
{
|
||||
return array_filter([
|
||||
'cover' => $this->getCoverUrl($externalId),
|
||||
'screenshot' => $this->getScreenshotUrl($externalId),
|
||||
]);
|
||||
}
|
||||
|
||||
private function makeRequest(string $endpoint, string $body): array
|
||||
{
|
||||
try {
|
||||
$this->ensureAccessToken();
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Client-ID' => $this->clientId,
|
||||
'Authorization' => "Bearer {$this->accessToken}",
|
||||
])->timeout(10)->post("https://api.igdb.com/v4{$endpoint}", $body);
|
||||
|
||||
if ($response->successful()) {
|
||||
return $response->json();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Log error
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private function ensureAccessToken(): void
|
||||
{
|
||||
if ($this->accessToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
$response = Http::asForm()->post('https://id.twitch.tv/oauth2/token', [
|
||||
'client_id' => $this->clientId,
|
||||
'client_secret' => $this->clientSecret,
|
||||
'grant_type' => 'client_credentials',
|
||||
]);
|
||||
|
||||
$this->accessToken = $response->json('access_token');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Scraper\Services;
|
||||
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use App\Features\Games\Models\Game;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ScraperService
|
||||
{
|
||||
public function __construct(
|
||||
private IGDBCoverScraper $igdb,
|
||||
private TGDBCoverScraper $tgdb
|
||||
) {}
|
||||
|
||||
public function search(string $query, ?string $consoleSlug = null): Collection
|
||||
{
|
||||
$console = $consoleSlug
|
||||
? Console::where('slug', $consoleSlug)->first()
|
||||
: null;
|
||||
|
||||
$consoleId = $console?->igdb_platform_id;
|
||||
|
||||
$results = $this->igdb->search($query, $consoleId);
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
$tgdbConsoleId = $console?->tgdb_platform_id;
|
||||
$results = $this->tgdb->search($query, $tgdbConsoleId);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function scrapeForGame(Game $game): ?string
|
||||
{
|
||||
$coverUrl = null;
|
||||
|
||||
if ($game->igdb_id) {
|
||||
$coverUrl = $this->igdb->getCoverUrl($game->igdb_id);
|
||||
}
|
||||
|
||||
if (! $coverUrl && $game->tgdb_id) {
|
||||
$coverUrl = $this->tgdb->getCoverUrl($game->tgdb_id);
|
||||
}
|
||||
|
||||
if ($coverUrl) {
|
||||
return $this->downloadCover($coverUrl, $game);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function downloadCover(string $url, Game $game): string
|
||||
{
|
||||
$consoleSlug = $game->console->slug ?? 'unknown';
|
||||
$filename = "{$game->slug}-cover.jpg";
|
||||
$path = "covers/{$consoleSlug}/{$filename}";
|
||||
|
||||
try {
|
||||
$contents = Http::timeout(30)->get($url)->body();
|
||||
Storage::disk('local')->put($path, $contents);
|
||||
|
||||
return $path;
|
||||
} catch (\Exception $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Scraper\Services;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class TGDBCoverScraper implements CoverScraperInterface
|
||||
{
|
||||
private string $apiKey;
|
||||
|
||||
private string $baseUrl = 'https://api.thegamesdb.net/v1';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->apiKey = config('services.thegamesdb.api_key', '');
|
||||
}
|
||||
|
||||
public function search(string $query, ?int $consoleId = null): Collection
|
||||
{
|
||||
if (empty($this->apiKey)) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$params = [
|
||||
'apikey' => $this->apiKey,
|
||||
'name' => $query,
|
||||
];
|
||||
if ($consoleId) {
|
||||
$params['platform'] = $consoleId;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::timeout(10)->get("{$this->baseUrl}/Games/ByGameName", $params);
|
||||
|
||||
if ($response->successful()) {
|
||||
$games = $response->json('data.games') ?? [];
|
||||
|
||||
return collect($games)->map(fn ($game) => [
|
||||
'id' => $game['id'],
|
||||
'title' => $game['game_title'],
|
||||
'cover_url' => $game['cover'] ?? null,
|
||||
'year' => isset($game['release_date'])
|
||||
? date('Y', strtotime($game['release_date']))
|
||||
: null,
|
||||
'source' => 'thegamesdb',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Log error
|
||||
}
|
||||
|
||||
return collect();
|
||||
}
|
||||
|
||||
public function getCoverUrl(int $externalId): ?string
|
||||
{
|
||||
if (empty($this->apiKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::timeout(10)->get("{$this->baseUrl}/Games/Images", [
|
||||
'apikey' => $this->apiKey,
|
||||
'id' => $externalId,
|
||||
'images_type' => 'boxart',
|
||||
]);
|
||||
|
||||
if ($response->successful()) {
|
||||
$images = $response->json('data.images') ?? [];
|
||||
if (! empty($images[0]['filename'])) {
|
||||
return "https://cdn.thegamesdb.net/images/original/{$images[0]['filename']}";
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Log error
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getScreenshotUrl(int $externalId): ?string
|
||||
{
|
||||
if (empty($this->apiKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::timeout(10)->get("{$this->baseUrl}/Games/Images", [
|
||||
'apikey' => $this->apiKey,
|
||||
'id' => $externalId,
|
||||
'images_type' => 'screenshot',
|
||||
]);
|
||||
|
||||
if ($response->successful()) {
|
||||
$images = $response->json('data.images') ?? [];
|
||||
if (! empty($images[0]['filename'])) {
|
||||
return "https://cdn.thegamesdb.net/images/original/{$images[0]['filename']}";
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Log error
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getImages(int $externalId): array
|
||||
{
|
||||
return array_filter([
|
||||
'cover' => $this->getCoverUrl($externalId),
|
||||
'screenshot' => $this->getScreenshotUrl($externalId),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Settings\Data;
|
||||
|
||||
use App\Features\Settings\Models\SaveFile;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
#[MapInputName(SnakeCaseMapper::class)]
|
||||
class SaveFileData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public int $userId,
|
||||
public int $gameId,
|
||||
public string $filePath,
|
||||
public string $fileName,
|
||||
public int $fileSize,
|
||||
public ?string $lastSyncedAt,
|
||||
) {}
|
||||
|
||||
public static function fromModel(SaveFile $saveFile): self
|
||||
{
|
||||
return new self(
|
||||
id: $saveFile->id,
|
||||
userId: $saveFile->user_id,
|
||||
gameId: $saveFile->game_id,
|
||||
filePath: $saveFile->file_path,
|
||||
fileName: $saveFile->file_name,
|
||||
fileSize: $saveFile->file_size,
|
||||
lastSyncedAt: $saveFile->last_synced_at?->toISOString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Settings\Models;
|
||||
|
||||
use App\Features\Games\Models\Game;
|
||||
use App\Models\User;
|
||||
use Database\Factories\SaveFileFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SaveFile extends Model
|
||||
{
|
||||
/** @use HasFactory<SaveFileFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected static ?string $factory = SaveFileFactory::class;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'game_id',
|
||||
'file_path',
|
||||
'file_name',
|
||||
'file_size',
|
||||
'last_synced_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'last_synced_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function game(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Game::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Settings\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Database\Factories\UserSettingFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserSetting extends Model
|
||||
{
|
||||
/** @use HasFactory<UserSettingFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected static ?string $factory = UserSettingFactory::class;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'setting_key',
|
||||
'setting_value',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Settings\Repositories;
|
||||
|
||||
use App\Features\Settings\Models\SaveFile;
|
||||
use App\Features\Settings\Models\UserSetting;
|
||||
use App\Models\User;
|
||||
|
||||
class SettingsRepository
|
||||
{
|
||||
public function __construct(
|
||||
private SaveFile $saveFileModel,
|
||||
private UserSetting $userSettingModel
|
||||
) {}
|
||||
|
||||
public function getUserSaves(User $user)
|
||||
{
|
||||
return $this->saveFileModel
|
||||
->where('user_id', $user->id)
|
||||
->with('game')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getUserSettings(User $user)
|
||||
{
|
||||
return $this->userSettingModel
|
||||
->where('user_id', $user->id)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getSetting(User $user, string $key, mixed $default = null): mixed
|
||||
{
|
||||
$setting = $this->userSettingModel
|
||||
->where('user_id', $user->id)
|
||||
->where('setting_key', $key)
|
||||
->first();
|
||||
|
||||
return $setting?->setting_value ?? $default;
|
||||
}
|
||||
|
||||
public function setSetting(User $user, string $key, mixed $value): void
|
||||
{
|
||||
$this->userSettingModel->updateOrCreate(
|
||||
['user_id' => $user->id, 'setting_key' => $key],
|
||||
['setting_value' => $value]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Uploads\Controllers;
|
||||
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use App\Features\Games\Repositories\GameRepository;
|
||||
use App\Features\Games\Repositories\RomFileRepository;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\ScrapeCoverJob;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class UploadController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private GameRepository $gameRepository,
|
||||
private RomFileRepository $romFileRepository
|
||||
) {}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
return Inertia::render('Upload/Index', [
|
||||
'consoles' => Console::orderBy('name')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'console_id' => 'required|exists:consoles,id',
|
||||
'rom_files' => 'required|array|min:1',
|
||||
'rom_files.*' => 'file|max:102400',
|
||||
]);
|
||||
|
||||
$console = Console::findOrFail($request->console_id);
|
||||
$allowedExtensions = $console->rom_extensions;
|
||||
|
||||
foreach ($request->file('rom_files') as $file) {
|
||||
$extension = strtolower($file->getClientOriginalExtension());
|
||||
|
||||
if (! in_array($extension, $allowedExtensions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filename = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
|
||||
$filename = "{$filename}.{$extension}";
|
||||
|
||||
$hash = hash_file('sha256', $file->getRealPath());
|
||||
|
||||
$existing = $this->romFileRepository->findByHash($hash);
|
||||
if ($existing) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $file->storeAs(
|
||||
"roms/{$console->slug}",
|
||||
$filename,
|
||||
'local'
|
||||
);
|
||||
|
||||
$gameTitle = Str::title(str_replace(['-', '_'], ' ', pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)));
|
||||
$gameSlug = Str::slug($gameTitle);
|
||||
|
||||
$game = $this->gameRepository->firstOrCreate(
|
||||
[
|
||||
'console_id' => $console->id,
|
||||
'slug' => $gameSlug,
|
||||
],
|
||||
[
|
||||
'title' => $gameTitle,
|
||||
]
|
||||
);
|
||||
|
||||
$this->romFileRepository->create([
|
||||
'game_id' => $game->id,
|
||||
'file_path' => $path,
|
||||
'file_name' => $file->getClientOriginalName(),
|
||||
'file_size' => $file->getSize(),
|
||||
'file_hash' => $hash,
|
||||
]);
|
||||
|
||||
if (! $game->cover_path) {
|
||||
ScrapeCoverJob::dispatch($game);
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard')
|
||||
->with('success', 'ROMs uploaded successfully.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\WebDav\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class WebDavController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
$webDavAccounts = $user->webDavAccounts;
|
||||
|
||||
return Inertia::render('Settings/WebDav', [
|
||||
'webDavAccounts' => $webDavAccounts,
|
||||
'appUrl' => config('app.url'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'username' => 'required|string|max:255|unique:webdav_accounts,username',
|
||||
'password' => 'required|string|min:8',
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
$user->webDavAccounts()->create([
|
||||
'username' => $request->username,
|
||||
'password_encrypted' => $request->password,
|
||||
'enabled' => true,
|
||||
'display_name' => $request->username,
|
||||
]);
|
||||
|
||||
return redirect()->route('settings.webdav')
|
||||
->with('success', 'WebDAV account created successfully.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, int $id): RedirectResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$account = $user->webDavAccounts()->findOrFail($id);
|
||||
$account->delete();
|
||||
|
||||
return redirect()->route('settings.webdav')
|
||||
->with('success', 'WebDAV account deleted successfully.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\WebDav\Data;
|
||||
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
#[MapInputName(SnakeCaseMapper::class)]
|
||||
class WebDavAccountData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public int $userId,
|
||||
public string $username,
|
||||
public string $displayName,
|
||||
public bool $enabled,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Inertia::render('Auth/Login', [
|
||||
'canResetPassword' => Route::has('password.request'),
|
||||
'status' => session('status'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*/
|
||||
public function store(LoginRequest $request): RedirectResponse
|
||||
{
|
||||
$request->authenticate();
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class ConfirmablePasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the confirm password view.
|
||||
*/
|
||||
public function show(): Response
|
||||
{
|
||||
return Inertia::render('Auth/ConfirmPassword');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if (! Auth::guard('web')->validate([
|
||||
'email' => $request->user()->email,
|
||||
'password' => $request->password,
|
||||
])) {
|
||||
throw ValidationException::withMessages([
|
||||
'password' => __('auth.password'),
|
||||
]);
|
||||
}
|
||||
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationNotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Send a new email verification notification.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'verification-link-sent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*/
|
||||
public function __invoke(Request $request): RedirectResponse|Response
|
||||
{
|
||||
return $request->user()->hasVerifiedEmail()
|
||||
? redirect()->intended(route('dashboard', absolute: false))
|
||||
: Inertia::render('Auth/VerifyEmail', ['status' => session('status')]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*/
|
||||
public function create(Request $request): Response
|
||||
{
|
||||
return Inertia::render('Auth/ResetPassword', [
|
||||
'email' => $request->email,
|
||||
'token' => $request->route('token'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => 'required',
|
||||
'email' => 'required|email',
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function ($user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
if ($status == Password::PASSWORD_RESET) {
|
||||
return redirect()->route('login')->with('status', __($status));
|
||||
}
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => [trans($status)],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Update the user's password.
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'current_password' => ['required', 'current_password'],
|
||||
'password' => ['required', Password::defaults(), 'confirmed'],
|
||||
]);
|
||||
|
||||
$request->user()->update([
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Inertia::render('Auth/ForgotPassword', [
|
||||
'status' => session('status'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'required|email',
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
// to send the link, we will examine the response then see the message we
|
||||
// need to show to the user. Finally, we'll send out a proper response.
|
||||
$status = Password::sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
if ($status == Password::RESET_LINK_SENT) {
|
||||
return back()->with('status', __($status));
|
||||
}
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => [trans($status)],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Inertia::render('Auth/Register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|string|lowercase|email|max:255|unique:'.User::class,
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return redirect(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, ValidatesRequests;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Features\Consoles\Data\ConsoleData;
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use App\Features\Games\Data\DashboardStatsData;
|
||||
use App\Features\Games\Data\GameData;
|
||||
use App\Features\Games\Repositories\GameRepository;
|
||||
use App\Features\Games\Repositories\RomFileRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private GameRepository $gameRepository,
|
||||
private RomFileRepository $romFileRepository
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$stats = new DashboardStatsData(
|
||||
totalGames: $this->gameRepository->count(),
|
||||
totalConsoles: Console::count(),
|
||||
totalRoms: $this->romFileRepository->count(),
|
||||
userSaves: $user->saveFiles()->count(),
|
||||
);
|
||||
|
||||
$recentGames = $this->gameRepository->getRecent(10)
|
||||
->map(fn ($game) => GameData::fromModel($game));
|
||||
|
||||
$consoles = Console::withCount('games')->get()
|
||||
->map(fn ($console) => ConsoleData::fromModel($console));
|
||||
|
||||
return Inertia::render('Dashboard/Index', [
|
||||
'stats' => $stats,
|
||||
'recentGames' => $recentGames,
|
||||
'consoles' => $consoles,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProfileUpdateRequest;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the user's profile form.
|
||||
*/
|
||||
public function edit(Request $request): Response
|
||||
{
|
||||
return Inertia::render('Profile/Edit', [
|
||||
'mustVerifyEmail' => $request->user() instanceof MustVerifyEmail,
|
||||
'status' => session('status'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*/
|
||||
public function update(ProfileUpdateRequest $request): RedirectResponse
|
||||
{
|
||||
$request->user()->fill($request->validated());
|
||||
|
||||
if ($request->user()->isDirty('email')) {
|
||||
$request->user()->email_verified_at = null;
|
||||
}
|
||||
|
||||
$request->user()->save();
|
||||
|
||||
return Redirect::route('profile.edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the user's account.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'password' => ['required', 'current_password'],
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
Auth::logout();
|
||||
|
||||
$user->delete();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Middleware;
|
||||
|
||||
class HandleInertiaRequests extends Middleware
|
||||
{
|
||||
/**
|
||||
* The root template that is loaded on the first page visit.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rootView = 'app';
|
||||
|
||||
/**
|
||||
* Determine the current asset version.
|
||||
*/
|
||||
public function version(Request $request): ?string
|
||||
{
|
||||
return parent::version($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the props that are shared by default.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function share(Request $request): array
|
||||
{
|
||||
return [
|
||||
...parent::share($request),
|
||||
'auth' => [
|
||||
'user' => $request->user(),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'string', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the request's credentials.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function authenticate(): void
|
||||
{
|
||||
$this->ensureIsNotRateLimited();
|
||||
|
||||
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the login request is not rate limited.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function ensureIsNotRateLimited(): void
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event(new Lockout($this));
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.throttle', [
|
||||
'seconds' => $seconds,
|
||||
'minutes' => ceil($seconds / 60),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rate limiting throttle key for the request.
|
||||
*/
|
||||
public function throttleKey(): string
|
||||
{
|
||||
return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ProfileUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'lowercase',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique(User::class)->ignore($this->user()->id),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Features\Games\Models\Game;
|
||||
use App\Features\Scraper\Services\ScraperService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ScrapeCoverJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public Game $game,
|
||||
) {}
|
||||
|
||||
public function handle(ScraperService $scraper): void
|
||||
{
|
||||
$result = $scraper->search($this->game->title, $this->game->console?->slug);
|
||||
|
||||
if ($result->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$bestMatch = $result->first();
|
||||
|
||||
if ($bestMatch->coverUrl) {
|
||||
$path = $scraper->downloadCover($bestMatch->coverUrl, $this->game);
|
||||
$this->game->update(['cover_path' => $path]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Features\Settings\UserSetting;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use N3XT0R\LaravelWebdavServer\Models\WebDavAccountModel;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
public function saveFiles(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Features\Settings\Models\SaveFile::class);
|
||||
}
|
||||
|
||||
public function settings(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserSetting::class);
|
||||
}
|
||||
|
||||
public function webDavAccounts(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebDavAccountModel::class);
|
||||
}
|
||||
|
||||
public function getSetting(string $key, mixed $default = null): mixed
|
||||
{
|
||||
$setting = $this->settings()->where('setting_key', $key)->first();
|
||||
|
||||
return $setting?->setting_value ?? $default;
|
||||
}
|
||||
|
||||
public function setSetting(string $key, mixed $value): void
|
||||
{
|
||||
$this->settings()->updateOrCreate(
|
||||
['setting_key' => $key],
|
||||
['setting_value' => $value]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Vite;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Vite::prefetch(concurrency: 3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Horizon\Horizon;
|
||||
use Laravel\Horizon\HorizonApplicationServiceProvider;
|
||||
|
||||
class HorizonServiceProvider extends HorizonApplicationServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
// Horizon::routeSmsNotificationsTo('15556667777');
|
||||
// Horizon::routeMailNotificationsTo('example@example.com');
|
||||
// Horizon::routeSlackNotificationsTo('slack-webhook-url', '#channel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Horizon gate.
|
||||
*
|
||||
* This gate determines who can access Horizon in non-local environments.
|
||||
*/
|
||||
protected function gate(): void
|
||||
{
|
||||
Gate::define('viewHorizon', function ($user = null) {
|
||||
return in_array(optional($user)->email, [
|
||||
//
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Spatie\LaravelTypeScriptTransformer\LaravelData\Transformers\DataClassTransformer;
|
||||
use Spatie\LaravelTypeScriptTransformer\TypeScriptTransformerApplicationServiceProvider as BaseTypeScriptTransformerServiceProvider;
|
||||
use Spatie\TypeScriptTransformer\Formatters\PrettierFormatter;
|
||||
use Spatie\TypeScriptTransformer\Transformers\AttributedClassTransformer;
|
||||
use Spatie\TypeScriptTransformer\Transformers\EnumTransformer;
|
||||
use Spatie\TypeScriptTransformer\TypeScriptTransformerConfigFactory;
|
||||
use Spatie\TypeScriptTransformer\Writers\GlobalNamespaceWriter;
|
||||
|
||||
class TypeScriptTransformerServiceProvider extends BaseTypeScriptTransformerServiceProvider
|
||||
{
|
||||
protected function configure(TypeScriptTransformerConfigFactory $config): void
|
||||
{
|
||||
$config
|
||||
->transformer(AttributedClassTransformer::class)
|
||||
->transformer(EnumTransformer::class)
|
||||
->transformer(DataClassTransformer::class)
|
||||
->transformDirectories(app_path())
|
||||
->writer(new GlobalNamespaceWriter('generated.d.ts'))
|
||||
->formatter(PrettierFormatter::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user