1
0
Fork 1
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:
Daniel Supernault 2024-10-04 01:07:05 -06:00
parent 8e208b0eb3
commit 78d2783db8
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
2 changed files with 36 additions and 3 deletions

View file

@ -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',

View 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.');
}
}
}