Files
ai-web/app/Models/CrawlRule.php

75 lines
1.7 KiB
PHP
Raw Normal View History

2026-02-18 12:56:36 +08:00
<?php
declare(strict_types=1);
namespace App\Models;
use App\Enums\CrawlTargetModule;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class CrawlRule extends Model
{
use HasFactory;
protected $fillable = [
'name',
'target_module',
'enabled',
'entry_urls',
'cron_expression',
'timezone',
'max_pages',
'render_js',
'user_agent',
'headers',
'cookies',
'proxy',
'rate_limit_per_minute',
'retry_max',
'retry_backoff_seconds',
'extractor_config',
'mapping_config',
'dedupe_config',
'ai_fallback_enabled',
'ai_provider',
'ai_model',
'publish_policy',
'alert_email',
'last_run_at',
'next_run_at',
'created_by',
'updated_by',
];
protected function casts(): array
{
return [
'target_module' => CrawlTargetModule::class,
'enabled' => 'boolean',
'entry_urls' => 'array',
'headers' => 'array',
'cookies' => 'array',
'extractor_config' => 'array',
'mapping_config' => 'array',
'dedupe_config' => 'array',
'render_js' => 'boolean',
'ai_fallback_enabled' => 'boolean',
'last_run_at' => 'datetime',
'next_run_at' => 'datetime',
];
}
public function runs(): HasMany
{
return $this->hasMany(CrawlRun::class, 'rule_id');
}
public function alerts(): HasMany
{
return $this->hasMany(CrawlAlert::class, 'rule_id');
}
}