Rename project from any-llm to laravel-llm
- Remove old any-llm related files (Dockerfile, config.yml, web/, setup-laravel.sh) - Update README.md with new Laravel LLM Gateway documentation - Keep docker-compose.yml with laravel-llm container names - Clean project structure for Laravel-only implementation
This commit is contained in:
@@ -2,34 +2,73 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ApiKey extends Model
|
||||
{
|
||||
protected $primaryKey = 'id';
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'api_keys';
|
||||
protected $primaryKey = 'token';
|
||||
public $incrementing = false;
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'key_hash',
|
||||
'key_name',
|
||||
'token',
|
||||
'user_id',
|
||||
'last_used_at',
|
||||
'expires_at',
|
||||
'is_active',
|
||||
'key_alias',
|
||||
'key_name',
|
||||
'permissions',
|
||||
'models',
|
||||
'metadata',
|
||||
'expires',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
protected $casts = [
|
||||
'permissions' => 'array',
|
||||
'models' => 'array',
|
||||
'metadata' => 'array',
|
||||
'expires' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get masked version of the key
|
||||
*/
|
||||
public function getMaskedKeyAttribute(): string
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
'metadata' => 'array',
|
||||
'created_at' => 'datetime',
|
||||
'last_used_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
];
|
||||
return substr($this->token, 0, 8) . '...' . substr($this->token, -4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if key is active (not explicitly marked inactive)
|
||||
*/
|
||||
public function getIsActiveAttribute(): bool
|
||||
{
|
||||
// For now, consider all keys active unless explicitly deleted
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if key is expired
|
||||
*/
|
||||
public function getIsExpiredAttribute(): bool
|
||||
{
|
||||
if (!$this->expires) {
|
||||
return false;
|
||||
}
|
||||
return $this->expires->isPast();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last used at timestamp
|
||||
*/
|
||||
public function getLastUsedAtAttribute()
|
||||
{
|
||||
$latestLog = $this->usageLogs()->latest('timestamp')->first();
|
||||
return $latestLog ? $latestLog->timestamp : null;
|
||||
}
|
||||
|
||||
public function gatewayUser()
|
||||
@@ -37,33 +76,14 @@ class ApiKey extends Model
|
||||
return $this->belongsTo(GatewayUser::class, 'user_id', 'user_id');
|
||||
}
|
||||
|
||||
// Alias for backwards compatibility
|
||||
public function user()
|
||||
{
|
||||
return $this->gatewayUser();
|
||||
}
|
||||
|
||||
public function usageLogs()
|
||||
{
|
||||
return $this->hasMany(UsageLog::class, 'api_key_id', 'id');
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true)
|
||||
->where(function ($q) {
|
||||
$q->whereNull('expires_at')
|
||||
->orWhere('expires_at', '>', now());
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeExpired($query)
|
||||
{
|
||||
return $query->whereNotNull('expires_at')
|
||||
->where('expires_at', '<=', now());
|
||||
}
|
||||
|
||||
public function getMaskedKeyAttribute()
|
||||
{
|
||||
return 'gw-' . substr($this->id, 0, 8) . '...' . substr($this->id, -8);
|
||||
}
|
||||
|
||||
public function getIsExpiredAttribute()
|
||||
{
|
||||
return $this->expires_at && $this->expires_at->isPast();
|
||||
return $this->hasMany(UsageLog::class, 'api_key', 'token');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user