website.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import uuid
  2. from flask import render_template, redirect
  3. class Website:
  4. def __init__(self, app) -> None:
  5. self.app = app
  6. def redirect_home():
  7. return redirect('/chat')
  8. self.routes = {
  9. '/': {
  10. 'function': redirect_home,
  11. 'methods': ['GET', 'POST']
  12. },
  13. '/chat/': {
  14. 'function': self._index,
  15. 'methods': ['GET', 'POST']
  16. },
  17. '/chat/<conversation_id>': {
  18. 'function': self._chat,
  19. 'methods': ['GET', 'POST']
  20. },
  21. '/menu/': {
  22. 'function': redirect_home,
  23. 'methods': ['GET', 'POST']
  24. },
  25. '/settings/': {
  26. 'function': redirect_home,
  27. 'methods': ['GET', 'POST']
  28. },
  29. '/images/': {
  30. 'function': redirect_home,
  31. 'methods': ['GET', 'POST']
  32. },
  33. }
  34. def _chat(self, conversation_id):
  35. if '-' not in conversation_id:
  36. return redirect('/chat')
  37. return render_template('index.html', chat_id=conversation_id)
  38. def _index(self):
  39. return render_template('index.html', chat_id=str(uuid.uuid4()))