1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-04-21 23:42:10 +02:00

Correct several performance and code issues, update HTTP kernel to Laravel 8 files

This commit is contained in:
Kovah 2021-01-20 22:24:43 +01:00
parent 1f12a4c3a0
commit 0fdd74a803
No known key found for this signature in database
GPG Key ID: AAAA031BA9830D7B
15 changed files with 200 additions and 25 deletions

View File

@ -4,6 +4,7 @@ namespace App\Actions\Fortify;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\ResetsUserPasswords;
class ResetUserPassword implements ResetsUserPasswords
@ -13,9 +14,10 @@ class ResetUserPassword implements ResetsUserPasswords
/**
* Validate and reset the user's forgotten password.
*
* @param mixed $user
* @param array $input
* @param mixed $user
* @param array $input
* @return void
* @throws ValidationException
*/
public function reset($user, array $input)
{

View File

@ -47,7 +47,7 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation
* @param array $input
* @return void
*/
protected function updateVerifiedUser($user, array $input)
protected function updateVerifiedUser($user, array $input): void
{
$user->forceFill([
'name' => $input['name'],

View File

@ -30,7 +30,7 @@ class CleanupLinkHistoriesCommand extends Command
return;
}
$linkCount = $baseQuery->groupBy('revisionable_id')->get('revisionable_id')->count();
$linkCount = $baseQuery->groupBy('revisionable_id')->count('revisionable_id');
$this->info(" Found $count entries across $linkCount links.");

View File

@ -43,7 +43,7 @@ class Kernel extends ConsoleKernel
$schedule->command('queue:work --daemon --once')
->withoutOverlapping();
if (env('BACKUP_ENABLED', false)) {
if (config('backup.backup.enabled')) {
$schedule->command('backup:clean')->daily()->at('01:00');
$schedule->command('backup:run')->daily()->at('02:00');
}

View File

@ -6,6 +6,7 @@ use App\Helper\WaybackMachine;
use App\Models\Link;
use App\Models\Setting;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
@ -32,7 +33,7 @@ function usersettings(string $key = '')
* Retrieve system settings
*
* @param string $key
* @return \Illuminate\Support\Collection
* @return null|Collection
*/
function systemsettings(string $key = '')
{
@ -128,7 +129,7 @@ function getShareLinks(Link $link): string
* @param int|null $height
* @return string
*/
function displaySVG($path, $width = null, $height = null)
function displaySVG(string $path, $width = null, $height = null)
{
$svg = file_get_contents($path);
@ -215,7 +216,7 @@ function getVersionFromPackage(): ?string
{
try {
$package = json_decode(Storage::disk('root')->get('package.json'), false);
} catch (\Exception $e) {
} catch (Exception $e) {
return null;
}

View File

@ -14,13 +14,13 @@ class CronController extends Controller
* cron is not available.
*
* @param Request $request
* @param string $cron_token
* @param string $cronToken
* @return ResponseFactory|Response
*/
public function __invoke(Request $request, $cron_token)
public function __invoke(Request $request, $cronToken)
{
// Verify the cron token
if ($cron_token !== systemsettings('cron_token')) {
if ($cronToken !== systemsettings('cron_token')) {
return response(trans('settings.cron_token_auth_failure'), 403);
}

View File

@ -14,11 +14,12 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
\App\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\SetupCheckMiddleware::class,
];
@ -42,7 +43,7 @@ class Kernel extends HttpKernel
'api' => [
'throttle:60,1',
'bindings',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

View File

@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array
*/
protected $except = [
//
];
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustHosts as Middleware;
class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array
*/
public function hosts()
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}

View File

@ -2,22 +2,22 @@
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array|string
* @var array|string|null
*/
protected $proxies = '**';
protected $proxies = '*';
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_ALL;
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB;
}

View File

@ -14,15 +14,11 @@ class AppServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot(UrlGenerator $url)
public function boot(): void
{
Schema::defaultStringLength(191);
Paginator::useBootstrap();
if (env('FORCE_HTTPS', false)) {
$url->forceScheme('https');
}
}
/**

View File

@ -7,7 +7,8 @@
"php": "^7.3 | ^8.0",
"composer/semver": "^1.5",
"doctrine/dbal": "^2.10.2",
"fideloper/proxy": "^4.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laracasts/flash": "^3.1",
"laravel/fortify": "^1.7",

135
composer.lock generated
View File

@ -4,8 +4,64 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "7778071f3b4d463d8aa5f0c8fd2dea4e",
"content-hash": "6f4d73c9cfd2ee05eb17c28ba921773d",
"packages": [
{
"name": "asm89/stack-cors",
"version": "v2.0.2",
"source": {
"type": "git",
"url": "https://github.com/asm89/stack-cors.git",
"reference": "8d8f88b3b3830916be94292c1fbce84433efb1aa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/asm89/stack-cors/zipball/8d8f88b3b3830916be94292c1fbce84433efb1aa",
"reference": "8d8f88b3b3830916be94292c1fbce84433efb1aa",
"shasum": ""
},
"require": {
"php": "^7.0|^8.0",
"symfony/http-foundation": "~2.7|~3.0|~4.0|~5.0",
"symfony/http-kernel": "~2.7|~3.0|~4.0|~5.0"
},
"require-dev": {
"phpunit/phpunit": "^6|^7|^8|^9",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"psr-4": {
"Asm89\\Stack\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alexander",
"email": "iam.asm89@gmail.com"
}
],
"description": "Cross-origin resource sharing library and stack middleware",
"homepage": "https://github.com/asm89/stack-cors",
"keywords": [
"cors",
"stack"
],
"support": {
"issues": "https://github.com/asm89/stack-cors/issues",
"source": "https://github.com/asm89/stack-cors/tree/v2.0.2"
},
"time": "2020-10-29T16:03:21+00:00"
},
{
"name": "aws/aws-sdk-php",
"version": "3.171.20",
@ -1138,6 +1194,83 @@
},
"time": "2020-10-22T13:48:01+00:00"
},
{
"name": "fruitcake/laravel-cors",
"version": "v2.0.3",
"source": {
"type": "git",
"url": "https://github.com/fruitcake/laravel-cors.git",
"reference": "01de0fe5f71c70d1930ee9a80385f9cc28e0f63a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fruitcake/laravel-cors/zipball/01de0fe5f71c70d1930ee9a80385f9cc28e0f63a",
"reference": "01de0fe5f71c70d1930ee9a80385f9cc28e0f63a",
"shasum": ""
},
"require": {
"asm89/stack-cors": "^2.0.1",
"illuminate/contracts": "^6|^7|^8|^9",
"illuminate/support": "^6|^7|^8|^9",
"php": ">=7.2",
"symfony/http-foundation": "^4|^5",
"symfony/http-kernel": "^4.3.4|^5"
},
"require-dev": {
"laravel/framework": "^6|^7|^8",
"orchestra/testbench-dusk": "^4|^5|^6",
"phpunit/phpunit": "^6|^7|^8",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
},
"laravel": {
"providers": [
"Fruitcake\\Cors\\CorsServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Fruitcake\\Cors\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fruitcake",
"homepage": "https://fruitcake.nl"
},
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application",
"keywords": [
"api",
"cors",
"crossdomain",
"laravel"
],
"support": {
"issues": "https://github.com/fruitcake/laravel-cors/issues",
"source": "https://github.com/fruitcake/laravel-cors/tree/v2.0.3"
},
"funding": [
{
"url": "https://github.com/barryvdh",
"type": "github"
}
],
"time": "2020-10-22T13:57:20+00:00"
},
{
"name": "graham-campbell/result-type",
"version": "v1.0.1",

View File

@ -54,6 +54,8 @@ return [
'url' => env('APP_URL', 'http://localhost'),
'force_https' => env('FORCE_HTTPS', false),
'asset_url' => env('ASSET_URL', null),
/*

View File

@ -4,6 +4,8 @@ return [
'backup' => [
'enabled' => env('BACKUP_ENABLED', false),
/*
* The name of this application. You can use this name to monitor
* the backups.