mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-21 23:32:39 +00:00
Fix push token for php8.2
This commit is contained in:
parent
8e208b0eb3
commit
78d2783db8
2 changed files with 36 additions and 3 deletions
|
@ -19,6 +19,7 @@ use App\Media;
|
|||
use App\Place;
|
||||
use App\Profile;
|
||||
use App\Report;
|
||||
use App\Rules\ExpoPushTokenRule;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\BouncerService;
|
||||
use App\Services\EmailService;
|
||||
|
@ -48,7 +49,6 @@ use Jenssegers\Agent\Agent;
|
|||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use Mail;
|
||||
use NotificationChannels\Expo\ExpoPushToken;
|
||||
|
||||
class ApiV1Dot1Controller extends Controller
|
||||
{
|
||||
|
@ -1087,7 +1087,7 @@ class ApiV1Dot1Controller extends Controller
|
|||
abort_if($request->user()->status, 422, 'Cannot access this resource at this time');
|
||||
|
||||
$this->validate($request, [
|
||||
'expo_token' => ['required', ExpoPushToken::rule()],
|
||||
'expo_token' => ['required', 'string', new ExpoPushTokenRule],
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
@ -1127,7 +1127,7 @@ class ApiV1Dot1Controller extends Controller
|
|||
|
||||
$this->validate($request, [
|
||||
'notify_enabled' => 'required',
|
||||
'token' => ['required', ExpoPushToken::rule()],
|
||||
'token' => ['required', 'string', new ExpoPushTokenRule],
|
||||
'notify_like' => 'sometimes',
|
||||
'notify_follow' => 'sometimes',
|
||||
'notify_mention' => 'sometimes',
|
||||
|
|
33
app/Rules/ExpoPushTokenRule.php
Normal file
33
app/Rules/ExpoPushTokenRule.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
class ExpoPushTokenRule implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*
|
||||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (! $value || empty($value)) {
|
||||
$fail('The :attribute must not be empty.');
|
||||
}
|
||||
|
||||
if (str_starts_with($value, 'ExponentPushToken[') && mb_strlen($value) < 26) {
|
||||
$fail('The :attribute is not a valid push token.');
|
||||
}
|
||||
|
||||
if (! str_starts_with($value, 'ExponentPushToken[') && ! str_starts_with($value, 'ExpoPushToken[')) {
|
||||
$fail('The :attribute is not a valid push token.');
|
||||
}
|
||||
|
||||
if (! str_ends_with($value, ']')) {
|
||||
$fail('The :attribute is not a valid push token.');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue