mirror of
https://github.com/jxxghp/MoviePilot-Plugins.git
synced 2026-05-25 07:26:52 +00:00
- 数据模型重构: 全面引入 Pydantic 模型(ClashConfig, Proxy, ProxyGroup 等)替代原有字典结构,提供更严格的数据验证与类型安全。 - 数据迁移机制: 新增 v2.1.0 数据升级脚本,支持将旧版代理、策略组及规则数据自动迁移至新架构。 - 配置补丁系统: 实现基于 JSON Patch 的细粒度配置修补机制,替代旧版覆盖逻辑,提升配置修改的灵活性。 - 服务层优化: 重写 ClashRuleProviderService 以适配新对象模型,增强代码可维护性与扩展性。 - API模型同步: 更新相关 API 数据模型以保持与内部数据结构的一致性。 - 用户界面: 批量规则管理和数据项隐藏支持
72 lines
1.8 KiB
Python
72 lines
1.8 KiB
Python
from typing import List
|
|
|
|
from pydantic import BaseModel, Field, RootModel
|
|
from simpleeval import simple_eval
|
|
|
|
|
|
class ClashApi(BaseModel):
|
|
url: str
|
|
secret: str
|
|
|
|
|
|
class Connectivity(BaseModel):
|
|
clash_apis: List[ClashApi] = Field(default_factory=list)
|
|
sub_links: List[str] = Field(default_factory=list)
|
|
|
|
|
|
class SubscriptionSetting(BaseModel):
|
|
url: str
|
|
enabled: bool
|
|
|
|
|
|
class DataUsage(BaseModel):
|
|
upload: int = 0
|
|
download: int = 0
|
|
total: int = 0
|
|
expire: int = 0
|
|
|
|
@property
|
|
def header(self) -> str:
|
|
return f'upload={self.upload}; download={self.download}; total={self.total}; expire={self.expire};'
|
|
|
|
|
|
class SubscriptionInfo(DataUsage):
|
|
last_update: int = Field(default=0)
|
|
proxy_num: int = Field(default=0)
|
|
enabled: bool = True
|
|
|
|
def update(self, setting: SubscriptionSetting):
|
|
self.enabled = setting.enabled
|
|
|
|
|
|
class SubscriptionsInfo(RootModel[dict[str, SubscriptionInfo]]):
|
|
root: dict[str, SubscriptionInfo] = Field(default_factory=dict)
|
|
|
|
def update(self, urls: list[str]):
|
|
if not urls:
|
|
return
|
|
|
|
self.root.clear()
|
|
for url in urls:
|
|
self.root[url] = self.root.get(url, SubscriptionInfo())
|
|
|
|
def get(self, url: str) -> SubscriptionInfo:
|
|
return self.root.get(url, SubscriptionInfo())
|
|
|
|
def __setitem__(self, key: str, value: SubscriptionInfo):
|
|
self.root[key] = value
|
|
|
|
def set(self, setting: SubscriptionSetting):
|
|
if setting.url in self.root:
|
|
self.root[setting.url].update(setting)
|
|
|
|
|
|
class ConfigRequest(BaseModel):
|
|
url: str
|
|
client_host: str
|
|
identifier: str | None = None
|
|
user_agent : str | None = None
|
|
|
|
def resolve(self, expr) -> bool:
|
|
return bool(simple_eval(expr=expr, names=self.model_dump()))
|