mirror of
https://github.com/jxxghp/MoviePilot-Plugins.git
synced 2026-05-24 23:16:49 +00:00
- 数据模型重构: 全面引入 Pydantic 模型(ClashConfig, Proxy, ProxyGroup 等)替代原有字典结构,提供更严格的数据验证与类型安全。 - 数据迁移机制: 新增 v2.1.0 数据升级脚本,支持将旧版代理、策略组及规则数据自动迁移至新架构。 - 配置补丁系统: 实现基于 JSON Patch 的细粒度配置修补机制,替代旧版覆盖逻辑,提升配置修改的灵活性。 - 服务层优化: 重写 ClashRuleProviderService 以适配新对象模型,增强代码可维护性与扩展性。 - API模型同步: 更新相关 API 数据模型以保持与内部数据结构的一致性。 - 用户界面: 批量规则管理和数据项隐藏支持
26 lines
860 B
Python
26 lines
860 B
Python
import time
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from .api import ConfigRequest
|
|
from .types import DataSource
|
|
|
|
|
|
class Metadata(BaseModel):
|
|
"""Metadata model for Clash items"""
|
|
# source of the item
|
|
source: DataSource = Field(default=DataSource.MANUAL)
|
|
# whether the item is disabled
|
|
disabled: bool = Field(default=False)
|
|
# roles that cannot see the item
|
|
invisible_to: list[str] = Field(default_factory=list)
|
|
# additional remarks
|
|
remark: str = Field(default="")
|
|
# last modified time
|
|
time_modified: float = Field(default_factory=lambda: time.time())
|
|
# whether the item has been patched
|
|
patched: bool = Field(default=False)
|
|
|
|
def available(self, param: ConfigRequest | None = None) -> bool:
|
|
return not self.disabled and (param is None or not any(param.resolve(expr) for expr in self.invisible_to))
|