add plugins
This commit is contained in:
@ -1,23 +1,29 @@
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, Optional
|
||||
|
||||
from app.core import settings
|
||||
from app.chain import ChainBase
|
||||
from app.core import settings, Context
|
||||
from app.db.systemconfigs import SystemConfigs
|
||||
|
||||
|
||||
class PluginChian(ChainBase):
|
||||
"""
|
||||
插件处理链
|
||||
"""
|
||||
|
||||
def process(self, *args, **kwargs) -> Optional[Context]:
|
||||
pass
|
||||
|
||||
|
||||
class _PluginBase(metaclass=ABCMeta):
|
||||
"""
|
||||
插件模块基类,通过继续该类实现插件功能
|
||||
除内置属性外,还有以下方法可以扩展或调用:
|
||||
- get_fields() 获取配置字典,用于生成插件配置表单
|
||||
- get_state() 获取插件启用状态,用于展示运行状态
|
||||
- stop_service() 停止插件服务
|
||||
- get_config() 获取配置信息
|
||||
- update_config() 更新配置信息
|
||||
- init_config() 生效配置信息
|
||||
- get_page() 插件额外页面数据,在插件配置页面左下解按钮展示
|
||||
- get_script() 插件额外脚本(Javascript),将会写入插件页面,可在插件元素中绑定使用,,XX_PluginInit为初始化函数
|
||||
- init_plugin() 生效配置信息
|
||||
- get_data_path() 获取插件数据保存目录
|
||||
- get_command() 获取插件命令,使用消息机制通过远程控制
|
||||
|
||||
@ -26,37 +32,9 @@ class _PluginBase(metaclass=ABCMeta):
|
||||
plugin_name: str = ""
|
||||
# 插件描述
|
||||
plugin_desc: str = ""
|
||||
# 插件图标
|
||||
plugin_icon: str = ""
|
||||
# 主题色
|
||||
plugin_color: str = ""
|
||||
# 插件版本
|
||||
plugin_version: str = "1.0"
|
||||
# 插件作者
|
||||
plugin_author: str = ""
|
||||
# 作者主页
|
||||
author_url: str = ""
|
||||
# 插件配置项ID前缀:为了避免各插件配置表单相冲突,配置表单元素ID自动在前面加上此前缀
|
||||
plugin_config_prefix: str = "plugin_"
|
||||
# 显示顺序
|
||||
plugin_order: int = 0
|
||||
# 可使用的用户级别
|
||||
auth_level: int = 1
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def get_fields() -> dict:
|
||||
"""
|
||||
获取配置字典,用于生成表单
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_state(self) -> bool:
|
||||
"""
|
||||
获取插件启用状态
|
||||
"""
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
self.chain = PluginChian()
|
||||
|
||||
@abstractmethod
|
||||
def init_plugin(self, config: dict = None):
|
||||
|
Reference in New Issue
Block a user