mirror of
https://github.com/notf0und/SGS
synced 2026-07-18 02:31:08 +00:00
* Fix CI/CD php version
* Add Pint * Format code
This commit is contained in:
parent
0993bfa666
commit
bae79d68ab
@@ -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;
|
||||
|
||||
/**
|
||||
@@ -18,10 +19,10 @@ class FileSize
|
||||
|
||||
$unitIndex = (int) floor(log($bytes, self::THRESHOLD));
|
||||
$unitIndex = min($unitIndex, count(self::UNITS) - 1);
|
||||
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -68,19 +69,19 @@ class IndexController extends Controller
|
||||
*/
|
||||
private function serveDirectoryListing(?string $path, Request $request): Response
|
||||
{
|
||||
$storagePath = $path
|
||||
? self::GAMES_DIRECTORY . '/' . $path
|
||||
$storagePath = $path
|
||||
? self::GAMES_DIRECTORY.'/'.$path
|
||||
: self::GAMES_DIRECTORY;
|
||||
|
||||
$directories = $this->getDirectories($storagePath);
|
||||
$files = $this->getFiles($storagePath);
|
||||
|
||||
|
||||
// Determine if this is a DBI client or regular browser
|
||||
$isDBI = str_starts_with($request->userAgent() ?? '', 'DBI/');
|
||||
|
||||
|
||||
// Determine base URL for links based on request path
|
||||
$baseUrl = str_starts_with($request->path(), 'api/dbi') ? '/api/dbi/' : '/';
|
||||
|
||||
|
||||
$html = $this->buildDirectoryListingHtml($directories, $files, $path ?? '', $baseUrl, $isDBI);
|
||||
|
||||
return response($html)->header('Content-Type', 'text/html');
|
||||
@@ -131,8 +132,8 @@ class IndexController extends Controller
|
||||
*/
|
||||
private function buildDirectoryListingHtml(Collection $directories, Collection $files, string $currentPath, string $baseUrl, bool $isDBI): string
|
||||
{
|
||||
$displayPath = $currentPath
|
||||
? '/games/' . rawurldecode($currentPath) . '/'
|
||||
$displayPath = $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,8 +168,8 @@ 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
|
||||
* @param Closure(Request): (Response|RedirectResponse) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response|RedirectResponse
|
||||
{
|
||||
if (!!$request->header('theme')) {
|
||||
if ((bool) $request->header('theme')) {
|
||||
return redirect()->route('tinfoil');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user