feat:插件支持API调用

This commit is contained in:
jxxghp
2024-04-25 13:50:45 +08:00
parent 0a4bf30b79
commit c835d021ff
3 changed files with 64 additions and 6 deletions

View File

@@ -424,7 +424,28 @@ class EventType(Enum):
- 需要注意的是,如果你没有完成用户认证,通过插件配置进去的索引站点也是无法正常使用的。
- **请不要添加对黄赌毒站点的支持,否则随时封闭接口。**
### 7. 如何发布插件版本
### 7. 如何在插件中调用API接口
- 目前仅在插件的数据页面支持`GET/POST`API接口调用可调用插件自身、主程序或其它插件的APIv1.8.4+)。
- 在`get_page`中定义好元素的事件以及相应的API参数具体可参考插件`豆瓣想看`
```json
{
"component": "VDialogCloseBtn", // 触发事件的元素
'events': {
// 点击事件
'click': {
'api': 'plugin/DoubanSync/delete_history', // API的相对路径
'method': 'get', // GET/POST
// API上送参数
'params': {
'doubanid': doubanid
}
}
},
}
```
- 每次API调用完成后均会自动刷新一次插件数据页。
### 8. 如何发布插件版本?
- 修改插件代码后,需要修改`package.json`中的`version`版本号MoviePilot才会提示用户有更新注意版本号需要与`__init__.py`文件中的`plugin_version`保持一致。
- `package.json`中的`level`用于定义插件用户可见权限,`1`为所有用户可见,`2`为仅认证用户可见,`3`为需要密钥才可见一般用于测试。如果插件功能需要使用到站点则应该为2否则即使插件对用户可见但因为用户未认证相关功能也无法正常使用。
- `package.json`中的`history`用于记录插件更新日志,格式如下:

View File

@@ -43,11 +43,12 @@
"DoubanSync": {
"name": "豆瓣想看",
"description": "同步豆瓣想看数据,自动添加订阅。",
"version": "1.5",
"version": "1.6",
"icon": "douban.png",
"author": "jxxghp",
"level": 2,
"history": {
"v1.6": "同步历史记录支持手动删除需要主程序升级至v1.8.4+版本",
"v1.5": "豆瓣信息识别后直接添加订阅,不进行搜索下载"
}
},

View File

@@ -7,6 +7,7 @@ import pytz
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger
from app import schemas
from app.chain.media import MediaChain
from app.schemas.types import MediaType
@@ -33,7 +34,7 @@ class DoubanSync(_PluginBase):
# 插件图标
plugin_icon = "douban.png"
# 插件版本
plugin_version = "1.5"
plugin_version = "1.6"
# 插件作者
plugin_author = "jxxghp"
# 作者主页
@@ -138,7 +139,14 @@ class DoubanSync(_PluginBase):
"summary": "API说明"
}]
"""
pass
return [
{
"path": "/delete_history",
"endpoint": self.delete_history,
"methods": ["GET"],
"summary": "删除豆瓣同步历史记录"
}
]
def get_service(self) -> List[Dict[str, Any]]:
"""
@@ -353,6 +361,21 @@ class DoubanSync(_PluginBase):
{
'component': 'VCard',
'content': [
{
"component": "VDialogCloseBtn",
"props": {
'innerClass': 'absolute top-0 right-0',
},
'events': {
'click': {
'api': 'plugin/DoubanSync/delete_history',
'method': 'get',
'params': {
'doubanid': doubanid
}
}
},
},
{
'component': 'div',
'props': {
@@ -379,9 +402,9 @@ class DoubanSync(_PluginBase):
'component': 'div',
'content': [
{
'component': 'VCardSubtitle',
'component': 'VCardTitle',
'props': {
'class': 'pa-2 font-bold break-words whitespace-break-spaces'
'class': 'ps-1 break-words whitespace-break-spaces'
},
'content': [
{
@@ -440,6 +463,19 @@ class DoubanSync(_PluginBase):
"clear": self._clear
})
def delete_history(self, doubanid: str):
"""
删除同步历史记录
"""
# 历史记录
historys = self.get_data('history')
if not historys:
return schemas.Response(success=False, message="未找到历史记录")
# 删除指定记录
historys = [h for h in historys if h.get("doubanid") != doubanid]
self.save_data('history', historys)
return schemas.Response(success=True, message="删除成功")
def stop_service(self):
"""
退出插件