register the system ui view
(self, app: Quart)
| 620 | ]) |
| 621 | |
| 622 | async def register_ui_view(self, app: Quart) -> None: |
| 623 | """register the system ui view""" |
| 624 | @app.route('/') |
| 625 | async def wechaty_ui_home_page() -> Response: |
| 626 | """home page of wechaty ui""" |
| 627 | response = await send_file( |
| 628 | os.path.join( |
| 629 | os.path.dirname(__file__), |
| 630 | 'ui', |
| 631 | 'index.html' |
| 632 | ) |
| 633 | ) |
| 634 | return response |
| 635 | |
| 636 | @app.route('/plugins/list') |
| 637 | async def get_plugins_nav() -> Response: |
| 638 | |
| 639 | navs = [] |
| 640 | for plugin in self.plugins(): |
| 641 | if not plugin.VISIABLE: |
| 642 | continue |
| 643 | |
| 644 | nav = NavDTO( |
| 645 | name=plugin.name, |
| 646 | status=int( |
| 647 | self._plugin_status[plugin.name] == PluginStatus.Running |
| 648 | )) |
| 649 | nav.update_metadata(plugin.metadata()) |
| 650 | navs.append(asdict(nav)) |
| 651 | return success(navs) |
| 652 | |
| 653 | @app.route('/plugins/status', methods=["POST", 'PUT']) |
| 654 | async def change_status() -> Response: |
| 655 | data = await request.get_json() |
| 656 | name = data.get('plugin_name', None) |
| 657 | status = data.get('status', None) |
| 658 | if name is None or status is None: |
| 659 | return error('the plugin_name and status field is required ...') |
| 660 | status = int(status) |
| 661 | if status == 0: |
| 662 | await self.stop_plugin(name) |
| 663 | elif status == 1: |
| 664 | await self.start_plugin(name) |
| 665 | else: |
| 666 | return error("unexpected plugin status, which should be one of<Stopped, Running>") |
| 667 | return success('changes success ...') |
| 668 | |
| 669 | @app.route('/plugins/setting', methods=['GET']) |
| 670 | async def get_plugin_setting() -> Response: |
| 671 | name = request.args.get('plugin_name', None) |
| 672 | if name is None: |
| 673 | return error('plugin_name field is required') |
| 674 | |
| 675 | if name not in self._plugins: |
| 676 | return error(f'plugin<{name}> not exist ...') |
| 677 | plugin: WechatyPlugin = self._plugins[name] |
| 678 | |
| 679 | return success(plugin.setting.to_dict()) |