2024-02-04 04:18:54 +08:00
|
|
|
from tortoise import fields
|
|
|
|
|
|
2026-01-28 10:15:24 +08:00
|
|
|
from zhenxun.services.cache.runtime_cache import PluginLimitMemoryCache
|
2024-02-04 04:18:54 +08:00
|
|
|
from zhenxun.services.db_context import Model
|
2024-07-30 22:36:09 +08:00
|
|
|
from zhenxun.utils.enum import LimitCheckType, LimitWatchType, PluginLimitType
|
2024-02-04 04:18:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class PluginLimit(Model):
|
|
|
|
|
id = fields.IntField(pk=True, generated=True, auto_increment=True)
|
|
|
|
|
"""自增id"""
|
|
|
|
|
module = fields.CharField(255, description="模块名")
|
|
|
|
|
"""模块名"""
|
|
|
|
|
module_path = fields.CharField(255, description="模块路径")
|
|
|
|
|
"""模块路径"""
|
|
|
|
|
plugin = fields.ForeignKeyField(
|
|
|
|
|
"models.PluginInfo",
|
|
|
|
|
related_name="plugin_limit",
|
|
|
|
|
on_delete=fields.CASCADE,
|
|
|
|
|
description="所属插件",
|
|
|
|
|
)
|
2024-02-25 03:18:34 +08:00
|
|
|
"""所属插件"""
|
2024-02-04 04:18:54 +08:00
|
|
|
limit_type = fields.CharEnumField(PluginLimitType, description="限制类型")
|
|
|
|
|
"""限制类型"""
|
|
|
|
|
watch_type = fields.CharEnumField(LimitWatchType, description="监听类型")
|
2024-02-26 03:04:32 +08:00
|
|
|
"""监听类型"""
|
2024-02-04 04:18:54 +08:00
|
|
|
status = fields.BooleanField(default=True, description="限制的开关状态")
|
|
|
|
|
"""限制的开关状态"""
|
|
|
|
|
check_type = fields.CharEnumField(
|
2024-07-30 22:36:09 +08:00
|
|
|
LimitCheckType, default=LimitCheckType.ALL, description="检查类型"
|
2024-02-04 04:18:54 +08:00
|
|
|
)
|
|
|
|
|
"""检查类型"""
|
|
|
|
|
result = fields.CharField(max_length=255, null=True, description="返回信息")
|
|
|
|
|
"""返回信息"""
|
|
|
|
|
cd = fields.IntField(null=True, description="cd")
|
|
|
|
|
"""cd"""
|
|
|
|
|
max_count = fields.IntField(null=True, description="最大调用次数")
|
|
|
|
|
"""最大调用次数"""
|
|
|
|
|
|
2025-01-07 14:36:22 +08:00
|
|
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
2024-02-04 04:18:54 +08:00
|
|
|
table = "plugin_limit"
|
|
|
|
|
table_description = "插件限制"
|
2026-01-28 10:15:24 +08:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
async def create(cls, *args, **kwargs):
|
|
|
|
|
result = await super().create(*args, **kwargs)
|
|
|
|
|
await PluginLimitMemoryCache.upsert_from_model(result)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
async def update_or_create(cls, *args, **kwargs):
|
|
|
|
|
result = await super().update_or_create(*args, **kwargs)
|
|
|
|
|
await PluginLimitMemoryCache.upsert_from_model(result[0])
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
async def save(self, *args, **kwargs):
|
|
|
|
|
await super().save(*args, **kwargs)
|
|
|
|
|
await PluginLimitMemoryCache.upsert_from_model(self)
|
|
|
|
|
|
|
|
|
|
async def delete(self, *args, **kwargs):
|
|
|
|
|
limit_id = self.id
|
|
|
|
|
await super().delete(*args, **kwargs)
|
|
|
|
|
await PluginLimitMemoryCache.remove_by_id(limit_id)
|