mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
fix(graphql): fix enum filter validation (#1042)
This commit is contained in:
@@ -18,6 +18,6 @@ enum ThemeType: int implements HasLabel
|
||||
#[Description('Ending')]
|
||||
case ED = 1;
|
||||
|
||||
#[Description("Insert Song\n\nNote: Not retrieved by default, include it in the type_in argument to do so.")]
|
||||
#[Description("Insert Song")]
|
||||
case IN = 2;
|
||||
}
|
||||
|
||||
@@ -59,9 +59,8 @@ class EnumFilter extends Filter
|
||||
'required',
|
||||
function ($attribute, mixed $value, Closure $fail): void {
|
||||
if (
|
||||
! is_string($value)
|
||||
|| ! enum_exists($this->enumClass)
|
||||
|| Arr::first($this->enumClass::cases(), fn (UnitEnum $enum): bool => $enum->name === $value) === null
|
||||
Arr::first($this->enumClass::cases(), fn (UnitEnum $enum): bool => $enum->name === $value) === null
|
||||
&& ! $value instanceof BackedEnum
|
||||
) {
|
||||
$fail("'{$value}' does not exist in the ".class_basename($this->enumClass).' enum.');
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Translation\PotentiallyTranslatedString;
|
||||
use RuntimeException;
|
||||
|
||||
@@ -40,6 +41,14 @@ class ModerationRule implements ValidationRule
|
||||
*/
|
||||
private function validateForOpenAI(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
$key = 'openai-moderation';
|
||||
|
||||
if (RateLimiter::tooManyAttempts($key, 60)) {
|
||||
return;
|
||||
}
|
||||
|
||||
RateLimiter::hit($key, 60);
|
||||
|
||||
try {
|
||||
$response = Http::acceptJson()
|
||||
->withToken(Config::get(ServiceConstants::OPENAI_BEARER_TOKEN))
|
||||
|
||||
Reference in New Issue
Block a user