feat: implement AI styling foundation and billing scope rework
This commit is contained in:
63
app/Models/AiEditingSetting.php
Normal file
63
app/Models/AiEditingSetting.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Throwable;
|
||||
|
||||
class AiEditingSetting extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_enabled' => 'boolean',
|
||||
'queue_auto_dispatch' => 'boolean',
|
||||
'queue_max_polls' => 'integer',
|
||||
'blocked_terms' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saved(fn () => static::flushCache());
|
||||
static::deleted(fn () => static::flushCache());
|
||||
}
|
||||
|
||||
public static function current(): self
|
||||
{
|
||||
/** @var self */
|
||||
return Cache::remember('ai_editing.settings', now()->addMinutes(10), static function (): self {
|
||||
try {
|
||||
return static::query()->firstOrCreate(['id' => 1], static::defaults());
|
||||
} catch (Throwable) {
|
||||
return new static(static::defaults());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function defaults(): array
|
||||
{
|
||||
return [
|
||||
'is_enabled' => true,
|
||||
'default_provider' => (string) config('ai-editing.default_provider', 'runware'),
|
||||
'fallback_provider' => null,
|
||||
'runware_mode' => (string) config('ai-editing.providers.runware.mode', 'live'),
|
||||
'queue_auto_dispatch' => (bool) config('ai-editing.queue.auto_dispatch', false),
|
||||
'queue_name' => (string) config('ai-editing.queue.name', 'default'),
|
||||
'queue_max_polls' => max(1, (int) config('ai-editing.queue.max_polls', 6)),
|
||||
'blocked_terms' => array_values(array_filter((array) config('ai-editing.safety.prompt.blocked_terms', []))),
|
||||
'status_message' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public static function flushCache(): void
|
||||
{
|
||||
Cache::forget('ai_editing.settings');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user