Repo rebuild
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ChatGPT\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ChatGptApiSetting extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'chatgpt_api_settings';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'api_key',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'api_key' => 'encrypted',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'api_key',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the currently active OpenAI API setting.
|
||||
*/
|
||||
public static function active(): ?self
|
||||
{
|
||||
return self::query()
|
||||
->where('is_active', true)
|
||||
->latest('id')
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a masked version of the stored API key for display.
|
||||
*/
|
||||
public function maskedApiKey(): string
|
||||
{
|
||||
$key = (string) $this->api_key;
|
||||
|
||||
if ($key === '') {
|
||||
return 'Not set';
|
||||
}
|
||||
|
||||
return substr($key, 0, 7) . '...' . substr($key, -4);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user