fix plugin api
This commit is contained in:
parent
db3040a50e
commit
bbc4a1bfa5
@ -9,6 +9,7 @@ import pytz
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
|
||||
from app import schemas
|
||||
from app.core.config import settings
|
||||
from app.plugins import _PluginBase
|
||||
from typing import Any, List, Dict, Tuple, Optional
|
||||
@ -67,7 +68,7 @@ class AutoBackup(_PluginBase):
|
||||
|
||||
if self._cron:
|
||||
try:
|
||||
self._scheduler.add_job(func=self.backup,
|
||||
self._scheduler.add_job(func=self.__backup,
|
||||
trigger=CronTrigger.from_crontab(self._cron),
|
||||
name="自动备份")
|
||||
except Exception as err:
|
||||
@ -75,7 +76,7 @@ class AutoBackup(_PluginBase):
|
||||
|
||||
if self._onlyonce:
|
||||
logger.info(f"自动备份服务启动,立即运行一次")
|
||||
self._scheduler.add_job(func=self.backup, trigger='date',
|
||||
self._scheduler.add_job(func=self.__backup, trigger='date',
|
||||
run_date=datetime.now(tz=pytz.timezone(settings.TZ)) + timedelta(seconds=3),
|
||||
name="自动备份")
|
||||
# 关闭一次性开关
|
||||
@ -93,7 +94,7 @@ class AutoBackup(_PluginBase):
|
||||
self._scheduler.print_jobs()
|
||||
self._scheduler.start()
|
||||
|
||||
def backup(self):
|
||||
def __backup(self):
|
||||
"""
|
||||
自动备份、删除备份
|
||||
"""
|
||||
@ -103,12 +104,16 @@ class AutoBackup(_PluginBase):
|
||||
bk_path = self.get_data_path()
|
||||
|
||||
# 备份
|
||||
zip_file = self.backup(bk_path=bk_path)
|
||||
zip_file = self.backup_file(bk_path=bk_path)
|
||||
|
||||
if zip_file:
|
||||
logger.info(f"备份完成 备份文件 {zip_file} ")
|
||||
success = True
|
||||
msg = f"备份完成 备份文件 {zip_file}"
|
||||
logger.info(msg)
|
||||
else:
|
||||
logger.error("创建备份失败")
|
||||
success = False
|
||||
msg = "创建备份失败"
|
||||
logger.error(msg)
|
||||
|
||||
# 清理备份
|
||||
bk_cnt = 0
|
||||
@ -140,8 +145,10 @@ class AutoBackup(_PluginBase):
|
||||
f"清理备份数量 {del_cnt}\n"
|
||||
f"剩余备份数量 {bk_cnt - del_cnt}")
|
||||
|
||||
return success, msg
|
||||
|
||||
@staticmethod
|
||||
def backup(bk_path: Path = None):
|
||||
def backup_file(bk_path: Path = None):
|
||||
"""
|
||||
@param bk_path 自定义备份路径
|
||||
"""
|
||||
@ -175,12 +182,22 @@ class AutoBackup(_PluginBase):
|
||||
def get_api(self) -> List[Dict[str, Any]]:
|
||||
return [{
|
||||
"path": "/backup",
|
||||
"endpoint": self.backup,
|
||||
"endpoint": self.__backup,
|
||||
"methods": ["GET"],
|
||||
"summary": "MoviePilot备份",
|
||||
"description": "MoviePilot备份",
|
||||
}]
|
||||
|
||||
def backup(self) -> schemas.Response:
|
||||
"""
|
||||
API调用备份
|
||||
"""
|
||||
success, msg = self.__backup()
|
||||
return schemas.Response(
|
||||
success=success,
|
||||
message=msg
|
||||
)
|
||||
|
||||
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
|
||||
"""
|
||||
拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构
|
||||
|
@ -13,6 +13,7 @@ from apscheduler.triggers.cron import CronTrigger
|
||||
from python_hosts import Hosts, HostsEntry
|
||||
from requests import Response
|
||||
|
||||
from app import schemas
|
||||
from app.core.config import settings
|
||||
from app.core.event import eventmanager, Event
|
||||
from app.log import logger
|
||||
@ -88,13 +89,13 @@ class CloudflareSpeedTest(_PluginBase):
|
||||
try:
|
||||
if self.get_state() and self._cron:
|
||||
logger.info(f"Cloudflare CDN优选服务启动,周期:{self._cron}")
|
||||
self._scheduler.add_job(func=self.cloudflareSpeedTest,
|
||||
self._scheduler.add_job(func=self.__cloudflareSpeedTest,
|
||||
trigger=CronTrigger.from_crontab(self._cron),
|
||||
name="Cloudflare优选")
|
||||
|
||||
if self._onlyonce:
|
||||
logger.info(f"Cloudflare CDN优选服务启动,立即运行一次")
|
||||
self._scheduler.add_job(func=self.cloudflareSpeedTest, trigger='date',
|
||||
self._scheduler.add_job(func=self.__cloudflareSpeedTest, trigger='date',
|
||||
run_date=datetime.now(tz=pytz.timezone(settings.TZ)) + timedelta(seconds=3),
|
||||
name="Cloudflare优选")
|
||||
# 关闭一次性开关
|
||||
@ -111,7 +112,7 @@ class CloudflareSpeedTest(_PluginBase):
|
||||
self._scheduler.start()
|
||||
|
||||
@eventmanager.register(EventType.CloudFlareSpeedTest)
|
||||
def cloudflareSpeedTest(self, event: Event = None):
|
||||
def __cloudflareSpeedTest(self, event: Event = None):
|
||||
"""
|
||||
CloudflareSpeedTest优选
|
||||
"""
|
||||
@ -491,7 +492,7 @@ class CloudflareSpeedTest(_PluginBase):
|
||||
def get_api(self) -> List[Dict[str, Any]]:
|
||||
return [{
|
||||
"path": "/cloudflare_speedtest",
|
||||
"endpoint": self.cloudflareSpeedTest,
|
||||
"endpoint": self.cloudflare_speedtest,
|
||||
"methods": ["GET"],
|
||||
"summary": "Cloudflare IP优选",
|
||||
"description": "Cloudflare IP优选",
|
||||
@ -726,6 +727,13 @@ class CloudflareSpeedTest(_PluginBase):
|
||||
def get_page(self) -> List[dict]:
|
||||
pass
|
||||
|
||||
def cloudflare_speedtest(self) -> schemas.Response:
|
||||
"""
|
||||
API调用CloudflareSpeedTest IP优选
|
||||
"""
|
||||
self.__cloudflareSpeedTest()
|
||||
return schemas.Response(success=True)
|
||||
|
||||
@staticmethod
|
||||
def __read_system_hosts():
|
||||
"""
|
||||
|
@ -12,6 +12,7 @@ from watchdog.events import FileSystemEventHandler
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.observers.polling import PollingObserver
|
||||
|
||||
from app import schemas
|
||||
from app.chain.tmdb import TmdbChain
|
||||
from app.chain.transfer import TransferChain
|
||||
from app.core.config import settings
|
||||
@ -602,12 +603,19 @@ class DirMonitor(_PluginBase):
|
||||
def get_api(self) -> List[Dict[str, Any]]:
|
||||
return [{
|
||||
"path": "/directory_sync",
|
||||
"endpoint": self.sync_all,
|
||||
"endpoint": self.sync,
|
||||
"methods": ["GET"],
|
||||
"summary": "目录监控同步",
|
||||
"description": "目录监控同步",
|
||||
}]
|
||||
|
||||
def sync(self) -> schemas.Response:
|
||||
"""
|
||||
API调用目录同步
|
||||
"""
|
||||
self.sync_all()
|
||||
return schemas.Response(success=True)
|
||||
|
||||
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
|
||||
return [
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user