mirror of
https://github.com/notf0und/SGS
synced 2026-07-17 18:21:06 +00:00
* Fix CI/CD php version
* Add Pint * Format code
This commit is contained in:
parent
0993bfa666
commit
bae79d68ab
@@ -16,7 +16,7 @@ jobs:
|
||||
- name: Set up PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.2'
|
||||
php-version: '8.4'
|
||||
extensions: mbstring
|
||||
coverage: none
|
||||
|
||||
@@ -34,10 +34,33 @@ jobs:
|
||||
working-directory: www
|
||||
run: php artisan test
|
||||
|
||||
lint:
|
||||
name: Check code style (Pint)
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: mbstring
|
||||
coverage: none
|
||||
|
||||
- name: Install Composer dependencies
|
||||
working-directory: www
|
||||
run: composer install --no-interaction --prefer-dist --optimize-autoloader
|
||||
|
||||
- name: Run Pint
|
||||
working-directory: www
|
||||
run: ./vendor/bin/pint --test
|
||||
|
||||
docker:
|
||||
name: Build and push Docker image
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
needs: [test, lint]
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
|
||||
@@ -16,7 +16,7 @@ jobs:
|
||||
- name: Set up PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.2'
|
||||
php-version: '8.4'
|
||||
extensions: mbstring
|
||||
coverage: none
|
||||
|
||||
@@ -33,3 +33,26 @@ jobs:
|
||||
- name: Run tests
|
||||
working-directory: www
|
||||
run: php artisan test
|
||||
|
||||
lint:
|
||||
name: Check code style (Pint)
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: mbstring
|
||||
coverage: none
|
||||
|
||||
- name: Install Composer dependencies
|
||||
working-directory: www
|
||||
run: composer install --no-interaction --prefer-dist --optimize-autoloader
|
||||
|
||||
- name: Run Pint
|
||||
working-directory: www
|
||||
run: ./vendor/bin/pint --test
|
||||
|
||||
@@ -18,7 +18,7 @@ enum NintendoFileExtension: string
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return array_map(fn($case) => $case->value, self::cases());
|
||||
return array_map(fn ($case) => $case->value, self::cases());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Helpers;
|
||||
class FileSize
|
||||
{
|
||||
private const UNITS = ['', 'K', 'M', 'G', 'T'];
|
||||
|
||||
private const THRESHOLD = 1024;
|
||||
|
||||
/**
|
||||
@@ -22,6 +23,6 @@ class FileSize
|
||||
$size = $bytes / pow(self::THRESHOLD, $unitIndex);
|
||||
$decimals = $unitIndex === 0 ? 0 : 2;
|
||||
|
||||
return number_format($size, $decimals, '.', '') . self::UNITS[$unitIndex];
|
||||
return number_format($size, $decimals, '.', '').self::UNITS[$unitIndex];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ class IndexController extends Controller
|
||||
private function getRequestPath(Request $request): ?string
|
||||
{
|
||||
$path = $request->route('path');
|
||||
|
||||
return $path ? rawurldecode($path) : null;
|
||||
}
|
||||
|
||||
@@ -51,9 +52,9 @@ class IndexController extends Controller
|
||||
*/
|
||||
private function serveFile(string $path): Response|BinaryFileResponse
|
||||
{
|
||||
$storagePath = self::GAMES_DIRECTORY . '/' . $path;
|
||||
$storagePath = self::GAMES_DIRECTORY.'/'.$path;
|
||||
|
||||
if (!Storage::exists($storagePath)) {
|
||||
if (! Storage::exists($storagePath)) {
|
||||
return response('File not found', 404);
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ class IndexController extends Controller
|
||||
private function serveDirectoryListing(?string $path, Request $request): Response
|
||||
{
|
||||
$storagePath = $path
|
||||
? self::GAMES_DIRECTORY . '/' . $path
|
||||
? self::GAMES_DIRECTORY.'/'.$path
|
||||
: self::GAMES_DIRECTORY;
|
||||
|
||||
$directories = $this->getDirectories($storagePath);
|
||||
@@ -132,7 +133,7 @@ class IndexController extends Controller
|
||||
private function buildDirectoryListingHtml(Collection $directories, Collection $files, string $currentPath, string $baseUrl, bool $isDBI): string
|
||||
{
|
||||
$displayPath = $currentPath
|
||||
? '/games/' . rawurldecode($currentPath) . '/'
|
||||
? '/games/'.rawurldecode($currentPath).'/'
|
||||
: '/games/';
|
||||
|
||||
return view('dbi.directory-listing', [
|
||||
@@ -151,7 +152,7 @@ class IndexController extends Controller
|
||||
*/
|
||||
private function getParentDirectoryUrl(string $currentPath, string $baseUrl, bool $isDBI): ?string
|
||||
{
|
||||
if (!$currentPath) {
|
||||
if (! $currentPath) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -167,7 +168,7 @@ class IndexController extends Controller
|
||||
return $baseUrl;
|
||||
}
|
||||
|
||||
return rtrim($baseUrl, '/') . '/' . collect(explode('/', $parentPath))
|
||||
return rtrim($baseUrl, '/').'/'.collect(explode('/', $parentPath))
|
||||
->map(fn ($segment) => rawurlencode($segment))
|
||||
->implode('/');
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class IndexController extends Controller
|
||||
{
|
||||
return response()->json([
|
||||
'files' => $this->getInstallableFiles()->values(),
|
||||
'success' => config('app.name')
|
||||
'success' => config('app.name'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class IndexController extends Controller
|
||||
->filter(fn ($path) => NintendoFileExtension::isSupported($path))
|
||||
->map(fn ($path) => [
|
||||
'url' => url($path),
|
||||
'size' => Storage::size($path)
|
||||
'size' => Storage::size($path),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,20 +6,17 @@ use Closure;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class EnsureIsTinfoilClient
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Closure(Request): (Response|RedirectResponse) $next
|
||||
* @return Response|RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response|RedirectResponse
|
||||
{
|
||||
if (!!$request->header('theme')) {
|
||||
if ((bool) $request->header('theme')) {
|
||||
return redirect()->route('tinfoil');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Providers\AppServiceProvider;
|
||||
|
||||
return [
|
||||
App\Providers\AppServiceProvider::class,
|
||||
AppServiceProvider::class,
|
||||
];
|
||||
|
||||
+2
-2
@@ -9,14 +9,14 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"php": "^8.4",
|
||||
"laravel/framework": "^12.0",
|
||||
"laravel/tinker": "^2.10.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.23",
|
||||
"laravel/pail": "^1.2.2",
|
||||
"laravel/pint": "^1.24",
|
||||
"laravel/pint": "^1.29",
|
||||
"laravel/sail": "^1.41",
|
||||
"mockery/mockery": "^1.6",
|
||||
"nunomaduro/collision": "^8.6",
|
||||
|
||||
Generated
+14
-13
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "cf274898566d29ebdc912d11f0d0a6e3",
|
||||
"content-hash": "f10e5685efd94a89d824ca6ed03c8b85",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
@@ -6525,16 +6525,16 @@
|
||||
},
|
||||
{
|
||||
"name": "laravel/pint",
|
||||
"version": "v1.26.0",
|
||||
"version": "v1.29.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/pint.git",
|
||||
"reference": "69dcca060ecb15e4b564af63d1f642c81a241d6f"
|
||||
"reference": "bdec963f53172c5e36330f3a400604c69bf02d39"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/69dcca060ecb15e4b564af63d1f642c81a241d6f",
|
||||
"reference": "69dcca060ecb15e4b564af63d1f642c81a241d6f",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/bdec963f53172c5e36330f3a400604c69bf02d39",
|
||||
"reference": "bdec963f53172c5e36330f3a400604c69bf02d39",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -6545,13 +6545,14 @@
|
||||
"php": "^8.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^3.90.0",
|
||||
"illuminate/view": "^12.40.1",
|
||||
"larastan/larastan": "^3.8.0",
|
||||
"laravel-zero/framework": "^12.0.4",
|
||||
"friendsofphp/php-cs-fixer": "^3.94.2",
|
||||
"illuminate/view": "^12.54.1",
|
||||
"larastan/larastan": "^3.9.3",
|
||||
"laravel-zero/framework": "^12.0.5",
|
||||
"mockery/mockery": "^1.6.12",
|
||||
"nunomaduro/termwind": "^2.3.3",
|
||||
"pestphp/pest": "^3.8.4"
|
||||
"nunomaduro/termwind": "^2.4.0",
|
||||
"pestphp/pest": "^3.8.6",
|
||||
"shipfastlabs/agent-detector": "^1.1.0"
|
||||
},
|
||||
"bin": [
|
||||
"builds/pint"
|
||||
@@ -6588,7 +6589,7 @@
|
||||
"issues": "https://github.com/laravel/pint/issues",
|
||||
"source": "https://github.com/laravel/pint"
|
||||
},
|
||||
"time": "2025-11-25T21:15:52+00:00"
|
||||
"time": "2026-03-12T15:51:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/sail",
|
||||
@@ -9339,7 +9340,7 @@
|
||||
"prefer-stable": true,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": "^8.2"
|
||||
"php": "^8.4"
|
||||
},
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.9.0"
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
@@ -62,7 +64,7 @@ return [
|
||||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => env('AUTH_MODEL', App\Models\User::class),
|
||||
'model' => env('AUTH_MODEL', User::class),
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Pdo\Mysql;
|
||||
|
||||
return [
|
||||
|
||||
@@ -59,7 +60,7 @@ return [
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
(PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
|
||||
(PHP_VERSION_ID >= 80500 ? Mysql::ATTR_SSL_CA : PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
@@ -79,7 +80,7 @@ return [
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
(PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
|
||||
(PHP_VERSION_ID >= 80500 ? Mysql::ATTR_SSL_CA : PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
|
||||
+4
-2
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\DBI\IndexController as DBIIndexController;
|
||||
use App\Http\Controllers\Tinfoil\IndexController as TinfoilIndexController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
/*
|
||||
@@ -7,9 +9,9 @@ use Illuminate\Support\Facades\Route;
|
||||
| API Routes
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
Route::get('tinfoil', \App\Http\Controllers\Tinfoil\IndexController::class)
|
||||
Route::get('tinfoil', TinfoilIndexController::class)
|
||||
->name('tinfoil');
|
||||
|
||||
Route::get('dbi/{path?}', \App\Http\Controllers\DBI\IndexController::class)
|
||||
Route::get('dbi/{path?}', DBIIndexController::class)
|
||||
->where('path', '.*')
|
||||
->name('dbi');
|
||||
|
||||
+4
-4
@@ -6,12 +6,12 @@ use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::view('/', 'welcome')->middleware([
|
||||
EnsureIsDbiClient::class,
|
||||
EnsureIsTinfoilClient::class
|
||||
EnsureIsTinfoilClient::class,
|
||||
]);
|
||||
|
||||
Route::get('/docs/{page}', function ($page) {
|
||||
$allowedPages = ['TINFOIL', 'DBI'];
|
||||
if (!in_array($page, $allowedPages)) {
|
||||
if (! in_array($page, $allowedPages)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ Route::get('/docs/{page}', function ($page) {
|
||||
Route::get('/docs-images/{path}', function ($path) {
|
||||
$imagePath = base_path("docs/images/{$path}");
|
||||
|
||||
if (!file_exists($imagePath)) {
|
||||
if (! file_exists($imagePath)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return response()->file($imagePath);
|
||||
})->where('path', '.*')->name('docs.images');
|
||||
|
||||
Route::get('/{path}', fn() => response('Not Found', 404))
|
||||
Route::get('/{path}', fn () => response('Not Found', 404))
|
||||
->where('path', '(?!api|docs-images).*')
|
||||
->middleware(EnsureIsDbiClient::class);
|
||||
|
||||
@@ -106,7 +106,7 @@ test('DBI user-agent receives relative links', function () {
|
||||
$response = $this->get('/api/dbi/', ['HTTP_USER_AGENT' => 'DBI/1.0']);
|
||||
|
||||
// DBI clients need a relative href like "GameA/" not an absolute path
|
||||
$response->assertSee('href="' . rawurlencode('GameA') . '/"', false);
|
||||
$response->assertSee('href="'.rawurlencode('GameA').'/"', false);
|
||||
});
|
||||
|
||||
test('browser user-agent receives absolute links', function () {
|
||||
@@ -114,7 +114,7 @@ test('browser user-agent receives absolute links', function () {
|
||||
|
||||
$response = $this->get('/api/dbi/');
|
||||
|
||||
$response->assertSee('href="/api/dbi/' . rawurlencode('GameA') . '"', false);
|
||||
$response->assertSee('href="/api/dbi/'.rawurlencode('GameA').'"', false);
|
||||
});
|
||||
|
||||
test('displays the current subdirectory path in the page title', function () {
|
||||
|
||||
@@ -47,7 +47,7 @@ test('only includes files with supported Nintendo Switch extensions', function (
|
||||
|
||||
$files = collect($response->json('files'));
|
||||
expect($files)->toHaveCount(4);
|
||||
expect($files->pluck('url')->every(fn ($url) => !str_ends_with($url, '.txt') && !str_ends_with($url, '.jpg')))->toBeTrue();
|
||||
expect($files->pluck('url')->every(fn ($url) => ! str_ends_with($url, '.txt') && ! str_ends_with($url, '.jpg')))->toBeTrue();
|
||||
});
|
||||
|
||||
test('file url is an absolute URL', function () {
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Test Case
|
||||
@@ -11,7 +13,7 @@
|
||||
|
|
||||
*/
|
||||
|
||||
pest()->extend(Tests\TestCase::class)
|
||||
pest()->extend(TestCase::class)
|
||||
// ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
|
||||
->in('Feature');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user