You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.9 KiB

  1. # maunium-stickerpicker - A fast and simple Matrix sticker picker widget.
  2. # Copyright (C) 2020 Tulir Asokan
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. from pkg_resources import resource_filename
  17. from aiohttp import web
  18. from .api import packs_app, setup_app, integrations_app, init as init_api
  19. from .static import StaticResource
  20. from .config import Config
  21. class Server:
  22. config: Config
  23. runner: web.AppRunner
  24. app: web.Application
  25. site: web.TCPSite
  26. def __init__(self, config: Config) -> None:
  27. init_api(config)
  28. self.config = config
  29. self.app = web.Application()
  30. self.app.add_subapp("/_matrix/integrations/v1", integrations_app)
  31. self.app.add_subapp("/setup/api", setup_app)
  32. self.app.add_subapp("/packs", packs_app)
  33. resource_path = (config["server.override_resource_path"]
  34. or resource_filename("sticker.server", "frontend"))
  35. self.app.router.register_resource(StaticResource("/", resource_path, name="frontend"))
  36. self.runner = web.AppRunner(self.app)
  37. async def start(self) -> None:
  38. await self.runner.setup()
  39. self.site = web.TCPSite(self.runner, self.config["server.host"],
  40. self.config["server.port"])
  41. await self.site.start()
  42. async def stop(self) -> None:
  43. await self.runner.cleanup()