diff --git a/README.md b/README.md index eb66e05..b6b2a29 100644 --- a/README.md +++ b/README.md @@ -29,5 +29,5 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ - [源文件恢复 1.2](docs%2FLinkToSrc.md) - [微信消息转发 1.3](docs%2FWeChatForward.md) - [订阅下载统计 1.5](docs%2FSubscribeStatistic.md) -- [自定义命令 1.1](docs%2FCustomCommand.md) +- [自定义命令 1.2](docs%2FCustomCommand.md) diff --git a/docs/CustomCommand.md b/docs/CustomCommand.md index dcf5ea4..12a7a47 100644 --- a/docs/CustomCommand.md +++ b/docs/CustomCommand.md @@ -2,6 +2,7 @@ ### 更新记录 +- 1.2 增加执行历史 - 1.1 打印命令日志 - 1.0 自定义执行周期执行命令并推送结果 diff --git a/package.json b/package.json index 82bf2ab..0d638c7 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,7 @@ "CustomCommand": { "name": "自定义命令", "description": "自定义执行周期执行命令并推送结果。", - "version": "1.1", + "version": "1.2", "icon": "Ntfy_A.png", "author": "thsrite", "level": 1 diff --git a/plugins/customcommand/__init__.py b/plugins/customcommand/__init__.py index b323db0..0d9efd8 100644 --- a/plugins/customcommand/__init__.py +++ b/plugins/customcommand/__init__.py @@ -22,7 +22,7 @@ class CustomCommand(_PluginBase): # 插件图标 plugin_icon = "Ntfy_A.png" # 插件版本 - plugin_version = "1.1" + plugin_version = "1.2" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -129,6 +129,18 @@ class CustomCommand(_PluginBase): logger.info( f"执行命令:{command} {'成功' if result.returncode == 0 else '失败'} 返回值:{last_output if last_output else last_error}") + # 读取历史记录 + history = self.get_data('history') or [] + + history.append({ + "name": name, + "command": command, + "result": last_output if last_output else last_error, + "time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) + }) + # 保存历史 + self.save_data(key="history", value=history) + if self._notify and self._msgtype: # 发送通知 mtype = NotificationType.Manual @@ -321,7 +333,106 @@ class CustomCommand(_PluginBase): } def get_page(self) -> List[dict]: - pass + # 查询同步详情 + historys = self.get_data('history') + if not historys: + return [ + { + 'component': 'div', + 'text': '暂无数据', + 'props': { + 'class': 'text-center', + } + } + ] + + if not isinstance(historys, list): + historys = [historys] + + # 按照签到时间倒序 + historys = sorted(historys, key=lambda x: x.get("time") or 0, reverse=True) + + # 签到消息 + sign_msgs = [ + { + 'component': 'tr', + 'props': { + 'class': 'text-sm' + }, + 'content': [ + { + 'component': 'td', + 'props': { + 'class': 'whitespace-nowrap break-keep text-high-emphasis' + }, + 'text': history.get("time") + }, + { + 'component': 'td', + 'text': history.get("name") + }, + { + 'component': 'td', + 'text': history.get("result") + } + ] + } for history in historys + ] + + # 拼装页面 + return [ + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VTable', + 'props': { + 'hover': True + }, + 'content': [ + { + 'component': 'thead', + 'content': [ + { + 'component': 'th', + 'props': { + 'class': 'text-start ps-4' + }, + 'text': '执行时间' + }, + { + 'component': 'th', + 'props': { + 'class': 'text-start ps-4' + }, + 'text': '命令名称' + }, + { + 'component': 'th', + 'props': { + 'class': 'text-start ps-4' + }, + 'text': '执行结果' + }, + ] + }, + { + 'component': 'tbody', + 'content': sign_msgs + } + ] + } + ] + } + ] + } + ] def stop_service(self): """