home_router.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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