fix CloudDrive2助手支持HomePage自定义API

This commit is contained in:
thsrite
2024-08-05 11:20:37 +08:00
parent c9be7fbbf5
commit b5bed2d2de
4 changed files with 122 additions and 4 deletions

View File

@@ -42,7 +42,7 @@ MoviePilot三方插件市场https://github.com/thsrite/MoviePilot-Plugins/
- 目录监控(统一入库消息增强版) v1.0
- Sql执行器 v1.3
- 命令执行器 v1.2
- CloudDrive2助手 v1.6
- [CloudDrive2助手](docs%2FCd2Assistant.md) v1.7
- 软连接重定向 v1.1
- 云盘同步删除 v1.5.1
- 媒体库重复媒体检测 v1.9

46
docs/Cd2Assistant.md Normal file
View File

@@ -0,0 +1,46 @@
# CloudDriver HomePage自定义API
![img.png](../img/HomePage/img.png)
HomePage services.yaml配置
```angular2html
- CloudDrive2:
icon: /icons/icon/clouddrive.png
href: http://cd2ip:cd2端口/
ping: http://cd2ip:cd2端口
#server: unraid
#container: CloudDrive
showStats: true
display: list
widget:
type: customapi
url: http://mp_ip:mp_port/api/v1/plugin/Cd2Assistant/homepage?apikey=mp_apikey
method: GET
mappings:
# - field: uptime
# label: 运行时间
- field: upload_count
label: 上传数量
- field: upload_speed
label: 上传速度
- field: download_count
label: 下载数量
- field: download_speed
label: 下载速度
# - field: cloud_space
# label: 剩余空间
```
### 自定义API Response字段
- cpuUsage CPU使用率
- memUsageKB 内存使用量
- uptime 运行时间
- upload_count 上传数量
- upload_speed 上传速度
- download_count 下载数量
- download_speed 下载速度
- cloud_space 剩余空间
### HomePage自定义API文档
https://gethomepage.dev/latest/widgets/services/customapi/#custom-request-body

View File

@@ -587,11 +587,12 @@
"name": "CloudDrive2助手",
"description": "监控上传任务,检测是否有异常,发送通知。",
"labels": "云盘",
"version": "1.6",
"version": "1.7",
"icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/clouddrive.png",
"author": "thsrite",
"level": 2,
"history": {
"v1.7": "增加HomePage自定义API详见插件说明",
"v1.6": "支持交互命令云下载",
"v1.5": "增加云盘同步黑名单(排序挂载本地目录)",
"v1.4": "增加云盘存储空间展示",

View File

@@ -5,6 +5,7 @@ import pytz
from clouddrive import CloudDriveClient, Client
from clouddrive.proto import CloudDrive_pb2
from app import schemas
from app.core.config import settings
from app.core.event import eventmanager, Event
from app.plugins import _PluginBase
@@ -25,7 +26,7 @@ class Cd2Assistant(_PluginBase):
# 插件图标
plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/clouddrive.png"
# 插件版本
plugin_version = "1.6"
plugin_version = "1.7"
# 插件作者
plugin_author = "thsrite"
# 作者主页
@@ -351,6 +352,15 @@ class Cd2Assistant(_PluginBase):
return system_info_dict
def homepage(self, apikey: str) -> Any:
"""
homepage自定义api
"""
if apikey != settings.API_TOKEN:
return schemas.Response(success=False, message="API密钥错误")
return self.cd2_info()
@staticmethod
def __convert_bytes(size_in_bytes):
""" Convert bytes to the most appropriate unit (PB, TB, GB, etc.) """
@@ -437,7 +447,13 @@ class Cd2Assistant(_PluginBase):
]
def get_api(self) -> List[Dict[str, Any]]:
pass
return [{
"path": "/homepage",
"endpoint": self.homepage,
"methods": ["GET"],
"summary": "HomePage",
"description": "HomePage自定义api",
}]
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
"""
@@ -712,6 +728,61 @@ class Cd2Assistant(_PluginBase):
]
}
]
},
{
'component': 'VRow',
'content': [
{
'component': 'VCol',
'props': {
'cols': 12,
},
'content': [
{
'component': 'VAlert',
'props': {
'type': 'success',
'variant': 'tonal'
},
'content': [
{
'component': 'span',
'text': 'HomePage配置教程请参考'
},
{
'component': 'a',
'props': {
'href': 'https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/docs/Cd2Assistant.md',
'target': '_blank'
},
'text': 'https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/docs/Cd2Assistant.md'
}
]
}
]
}
]
},
{
'component': 'VRow',
'content': [
{
'component': 'VCol',
'props': {
'cols': 12,
},
'content': [
{
'component': 'VAlert',
'props': {
'type': 'info',
'variant': 'tonal',
'text': '如安装完启用插件后HomePage提示404重启MoviePilot即可。'
}
}
]
}
]
}
]
}