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

@@ -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):
"""
退出插件