Arcader7171 commited on
Commit
e93886b
·
verified ·
1 Parent(s): 5ccf17c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -24
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import json
 
3
  import traceback
4
 
5
  from flask import Flask, render_template, url_for, redirect, request, make_response, session, abort
@@ -30,29 +31,7 @@ def wipeSession():
30
  def index():
31
  return render_template("index.html")
32
 
33
- @app.route("/app")
34
- async def interApp():
35
- if "username" not in session:
36
- wipeSession()
37
- return redirect(url_for("login"))
38
- if "password" not in session:
39
- wipeSession()
40
- return redirect(url_for("login"))
41
- supabase: AsyncClient = await acreate_client(url, key)
42
- response = (
43
- await supabase.table("messages")
44
- .select("author_name, content")
45
- .execute()
46
- )
47
- msgHistory = []
48
- dbHistory = response.data
49
- for msg in dbHistory:
50
- if msg["author_name"] == session["username"]:
51
- local = True
52
- else:
53
- local = False
54
- msgHistory.append({"user": msg["author_name"], "message": msg["content"], "local": local})
55
- return render_template("app.html", history=msgHistory)
56
 
57
  @app.route("/signup")
58
  def signup():
@@ -112,9 +91,48 @@ async def signupAPI():
112
  )
113
  response = dbResponse["data"][0]
114
  return make_response(response), 200
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
 
117
 
118
  @app.errorhandler(404)
119
  def not_found(e):
120
- return render_template("404.html")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import json
3
+ import asyncio
4
  import traceback
5
 
6
  from flask import Flask, render_template, url_for, redirect, request, make_response, session, abort
 
31
  def index():
32
  return render_template("index.html")
33
 
34
+ # The route for /app used to be here, but has been moved to be the end of the file to minimize scrolling for other routes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  @app.route("/signup")
37
  def signup():
 
91
  )
92
  response = dbResponse["data"][0]
93
  return make_response(response), 200
94
+
95
+ @app.post("/api/message")
96
+ async def messageAPI():
97
+ supabase: AsyncClient = await acreate_client(url, key)
98
+ if request.method == 'POST':
99
+ data = json.loads(request.data)
100
+ msg = data["msg"]
101
+ author = data["author"]
102
+ response = (
103
+ supabase.table("messages")
104
+ .insert()
105
+ )
106
 
107
 
108
 
109
  @app.errorhandler(404)
110
  def not_found(e):
111
+ return render_template("404.html")
112
+
113
+
114
+
115
+
116
+ @app.route("/app")
117
+ async def interApp():
118
+ if "username" not in session:
119
+ wipeSession()
120
+ return redirect(url_for("login"))
121
+ if "password" not in session:
122
+ wipeSession()
123
+ return redirect(url_for("login"))
124
+ supabase: AsyncClient = await acreate_client(url, key)
125
+ response = (
126
+ await supabase.table("messages")
127
+ .select("author_name, content")
128
+ .execute()
129
+ )
130
+ channel = supabase.channel("main/general")
131
+ msgHistory = []
132
+ dbHistory = response.data
133
+ for msg in dbHistory:
134
+ local = False
135
+ if msg["author_name"] == session["username"]:
136
+ local = True
137
+ msgHistory.append({"user": msg["author_name"], "message": msg["content"], "local": local})
138
+ return render_template("app.html", history=msgHistory)