Merge pull request #918 from thsrite/main
This commit is contained in:
commit
98be091ca6
@ -1,5 +1,4 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from typing import Union
|
||||
|
||||
@ -18,7 +17,6 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
||||
"""
|
||||
|
||||
_restart_file = "__system_restart__"
|
||||
_update_file = "__system_update__"
|
||||
|
||||
def remote_clear_cache(self, channel: MessageChannel, userid: Union[int, str]):
|
||||
"""
|
||||
@ -42,31 +40,6 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
||||
}, self._restart_file)
|
||||
SystemUtils.restart()
|
||||
|
||||
def update(self, channel: MessageChannel = None, userid: Union[int, str] = None):
|
||||
"""
|
||||
重启系统
|
||||
"""
|
||||
if not SystemUtils.is_docker():
|
||||
logger.error("非Docker版本不支持自动更新!")
|
||||
return
|
||||
|
||||
if channel and userid:
|
||||
self.post_message(Notification(channel=channel,
|
||||
title="系统正在更新,请耐心等候!", userid=userid))
|
||||
# 保存重启信息
|
||||
self.save_cache({
|
||||
"channel": channel.value,
|
||||
"userid": userid
|
||||
}, self._update_file)
|
||||
|
||||
# 重启系统
|
||||
os.system("bash /usr/local/bin/mp_update")
|
||||
|
||||
if channel and userid:
|
||||
self.post_message(Notification(channel=channel,
|
||||
title="暂无新版本!", userid=userid))
|
||||
self.remove_cache(self._update_file)
|
||||
|
||||
def version(self, channel: MessageChannel, userid: Union[int, str]):
|
||||
"""
|
||||
查看当前版本、远程版本
|
||||
@ -86,12 +59,9 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
||||
如通过交互命令重启,
|
||||
重启完发送msg
|
||||
"""
|
||||
cache_file, action, channel, userid = None, None, None, None
|
||||
# 重启消息
|
||||
restart_channel = self.load_cache(self._restart_file)
|
||||
if restart_channel:
|
||||
cache_file = self._restart_file
|
||||
action = "重启"
|
||||
# 发送重启完成msg
|
||||
if not isinstance(restart_channel, dict):
|
||||
restart_channel = json.loads(restart_channel)
|
||||
@ -100,21 +70,6 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
||||
channel.value == restart_channel.get('channel')), None)
|
||||
userid = restart_channel.get('userid')
|
||||
|
||||
# 更新消息
|
||||
update_channel = self.load_cache(self._update_file)
|
||||
if update_channel:
|
||||
cache_file = self._update_file
|
||||
action = "更新"
|
||||
# 发送重启完成msg
|
||||
if not isinstance(update_channel, dict):
|
||||
update_channel = json.loads(update_channel)
|
||||
channel = next(
|
||||
(channel for channel in MessageChannel.__members__.values() if
|
||||
channel.value == update_channel.get('channel')), None)
|
||||
userid = update_channel.get('userid')
|
||||
|
||||
# 发送消息
|
||||
if channel and userid:
|
||||
# 版本号
|
||||
release_version = self.__get_release_version()
|
||||
local_version = self.get_local_version()
|
||||
@ -123,9 +78,9 @@ class SystemChain(ChainBase, metaclass=Singleton):
|
||||
else:
|
||||
title = f"当前版本:{local_version},远程版本:{release_version}"
|
||||
self.post_message(Notification(channel=channel,
|
||||
title=f"系统已{action}完成!{title}",
|
||||
title=f"系统已重启完成!{title}",
|
||||
userid=userid))
|
||||
self.remove_cache(cache_file)
|
||||
self.remove_cache(self._restart_file)
|
||||
|
||||
@staticmethod
|
||||
def __get_release_version():
|
||||
|
@ -149,12 +149,6 @@ class Command(metaclass=Singleton):
|
||||
"description": "当前版本",
|
||||
"category": "管理",
|
||||
"data": {}
|
||||
},
|
||||
"/update": {
|
||||
"func": SystemChain().update,
|
||||
"description": "更新系统",
|
||||
"category": "管理",
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
# 汇总插件命令
|
||||
|
@ -450,7 +450,7 @@ class DoubanSync(_PluginBase):
|
||||
url = self._interests_url % user_id
|
||||
results = self.rsshelper.parse(url)
|
||||
if not results:
|
||||
logger.error(f"未获取到用户 {user_id} 豆瓣RSS数据:{url}")
|
||||
logger.warn(f"未获取到用户 {user_id} 豆瓣RSS数据:{url}")
|
||||
continue
|
||||
else:
|
||||
logger.info(f"获取到用户 {user_id} 豆瓣RSS数据:{len(results)}")
|
||||
|
@ -10,13 +10,14 @@ from typing import Any, List, Dict, Tuple, Optional
|
||||
from app.log import logger
|
||||
from app.schemas import NotificationType
|
||||
from app.utils.http import RequestUtils
|
||||
from app.utils.system import SystemUtils
|
||||
|
||||
|
||||
class MoviePilotUpdateNotify(_PluginBase):
|
||||
# 插件名称
|
||||
plugin_name = "MoviePilot更新推送"
|
||||
# 插件描述
|
||||
plugin_desc = "MoviePilot推送release更新通知、自动更新。"
|
||||
plugin_desc = "MoviePilot推送release更新通知、自动重启。"
|
||||
# 插件图标
|
||||
plugin_icon = "update.png"
|
||||
# 主题色
|
||||
@ -38,7 +39,7 @@ class MoviePilotUpdateNotify(_PluginBase):
|
||||
_enabled = False
|
||||
# 任务执行间隔
|
||||
_cron = None
|
||||
_update = False
|
||||
_restart = False
|
||||
_notify = False
|
||||
|
||||
# 定时器
|
||||
@ -51,7 +52,7 @@ class MoviePilotUpdateNotify(_PluginBase):
|
||||
if config:
|
||||
self._enabled = config.get("enabled")
|
||||
self._cron = config.get("cron")
|
||||
self._update = config.get("update")
|
||||
self._restart = config.get("restart")
|
||||
self._notify = config.get("notify")
|
||||
|
||||
# 加载模块
|
||||
@ -97,12 +98,13 @@ class MoviePilotUpdateNotify(_PluginBase):
|
||||
text=f"{release_version} \n"
|
||||
f"\n"
|
||||
f"{description} \n"
|
||||
f"\n"
|
||||
f"{update_time}")
|
||||
|
||||
# 自动更新
|
||||
if self._update:
|
||||
logger.info("开始执行自动更新…")
|
||||
SystemChain().update()
|
||||
# 自动重启
|
||||
if self._restart:
|
||||
logger.info("开始执行自动重启…")
|
||||
SystemUtils.restart()
|
||||
|
||||
@staticmethod
|
||||
def __get_release_version():
|
||||
@ -167,8 +169,8 @@ class MoviePilotUpdateNotify(_PluginBase):
|
||||
{
|
||||
'component': 'VSwitch',
|
||||
'props': {
|
||||
'model': 'update',
|
||||
'label': '自动更新',
|
||||
'model': 'restart',
|
||||
'label': '自动重启',
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -211,12 +213,31 @@ class MoviePilotUpdateNotify(_PluginBase):
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
'component': 'VRow',
|
||||
'content': [
|
||||
{
|
||||
'component': 'VCol',
|
||||
'props': {
|
||||
'cols': 12,
|
||||
},
|
||||
'content': [
|
||||
{
|
||||
'component': 'VAlert',
|
||||
'props': {
|
||||
'text': '如要开启自动重启,请确认MOVIEPILOT_AUTO_UPDATE设置为true,重启即更新。'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
], {
|
||||
"enabled": False,
|
||||
"update": False,
|
||||
"restart": False,
|
||||
"notify": False,
|
||||
"cron": "0 9 * * *"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user