home_router.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from fastapi import APIRouter
  5. from module.logger import logger
  6. from module.server.main_manager import MainManager
  7. from module.server.updater import Updater
  8. home_app = APIRouter(
  9. prefix="/home",
  10. tags=["home"],
  11. )
  12. @home_app.get('/test')
  13. async def home_test():
  14. return {'message': 'test'}
  15. # gcc -Wall -pedantic -shared -fPIC -o group_work.so group_work.c -lwiringPi
  16. @home_app.get('/home_menu')
  17. async def home_menu():
  18. return {'Home': [], 'Updater': [], 'Tool': []}
  19. @home_app.post('/notify_test')
  20. async def notify_test(setting: str, title: str, content: str):
  21. from module.notify.notify import Notifier
  22. try:
  23. notifier = Notifier(setting, True)
  24. if notifier.push(title=title, content=content):
  25. del notifier
  26. return True
  27. else:
  28. del notifier
  29. return False
  30. except Exception as e:
  31. logger.exception(e)
  32. return str(e)
  33. @home_app.get('/kill_server')
  34. async def kill_server():
  35. MainManager.signal_kill_server = True
  36. return 'success'
  37. @home_app.get('/update_info')
  38. async def update_info():
  39. try:
  40. updater = Updater()
  41. result = {'is_update': updater.check_update(),
  42. 'branch': updater.current_branch(),
  43. 'current_commit': updater.current_commit(),
  44. 'latest_commit': updater.latest_commit(),
  45. 'commit': updater.get_commit(n=15),
  46. }
  47. return result
  48. except Exception as e:
  49. logger.error(e)
  50. return None
  51. @home_app.get('/execute_update')
  52. async def execute_update():
  53. # 下拉仓库 -> 关闭所有脚本进程 -> 最后重启oasx
  54. try:
  55. updater = Updater()
  56. updater.execute_pull()
  57. except Exception as e:
  58. logger.error(e)
  59. return '手动更新将会立即结束运行中的脚本服务, 最后你还需重启oasx'