Miguel Diaz commited on
Commit
581b386
1 Parent(s): 26e1cfd
Files changed (3) hide show
  1. main.py +32 -38
  2. static/css/app2.css +35 -0
  3. static/main2.html +81 -0
main.py CHANGED
@@ -22,11 +22,18 @@ for key in users:
22
  password = key+users[key]+users["master"]
23
  users[key] = sha256(password.encode('UTF-8')).hexdigest()
24
 
25
- with open("log.txt", "w") as f:
26
- f.write("incio")
27
- f.write("\n--------------------------\n")
 
 
 
 
 
 
28
 
29
 
 
30
 
31
  fecha_unix = str(int(time.time()))
32
 
@@ -74,6 +81,13 @@ async def root(request: Request, credentials: HTTPBasicCredentials = Depends(sec
74
  with open(os.path.join("static", "main.html")) as f:
75
  return HTMLResponse(f.read().replace("{% token %}", token).replace("{% version %}", fecha_unix))
76
 
 
 
 
 
 
 
 
77
 
78
  @app.post("/chat_stream")
79
  async def chat_stream(data = Depends(validate_token)):
@@ -162,21 +176,14 @@ async def read_log(request: Request, credentials: HTTPBasicCredentials = Depends
162
 
163
  @app.get("/mfdfastapi")
164
  async def webhook_get(request: Request):
165
-
166
- with open("log.txt", "a") as f:
167
- f.write("get mfdfastapi")
168
- f.write("\n")
169
- headers = {}
170
- for name, value in request.headers.items(): headers[name] = value
171
- f.write("head: ")
172
- f.write(json.dumps(headers))
173
- f.write("\n")
174
- parametros_get = request.query_params
175
- f.write("get: ")
176
- f.write(json.dumps(dict(parametros_get.items())))
177
- f.write("\n")
178
- f.write("--------------------------\n")
179
 
 
 
 
 
 
 
 
180
  mode = request.query_params.get('hub.mode', "")
181
  if mode=="subscribe":
182
  challenge = request.query_params.get('hub.challenge', "")
@@ -189,28 +196,15 @@ async def webhook_get(request: Request):
189
  raise HTTPException(status_code=404, detail="Datos no válidos")
190
  return HTMLResponse(str(challenge))
191
 
192
-
193
-
194
-
195
  @app.post("/mfdfastapi")
196
  async def webhook_post(request: Request):
197
- with open("log.txt", "a") as f:
198
- f.write("post mfdfastapi")
199
- f.write("\n")
200
- headers = {}
201
- for name, value in request.headers.items(): headers[name] = value
202
- f.write("head: ")
203
- f.write(json.dumps(headers))
204
- f.write("\n")
205
- parametros_post = await request.json()
206
- parametros_get = request.query_params
207
- f.write("get: ")
208
- f.write(json.dumps(dict(parametros_get.items())))
209
- f.write("\n")
210
- f.write("post: ")
211
- f.write(json.dumps(parametros_post))
212
- f.write("\n")
213
- f.write("--------------------------\n")
214
-
215
  return HTMLResponse("ok")
216
 
 
22
  password = key+users[key]+users["master"]
23
  users[key] = sha256(password.encode('UTF-8')).hexdigest()
24
 
25
+ def write_line(line):
26
+ with open("log.txt", "a") as f:
27
+ f.write(line)
28
+ f.write("\n")
29
+
30
+ def write_multi_line(list_text):
31
+ for line in list_text:
32
+ write_line(line)
33
+ write_line("---------------------------")
34
 
35
 
36
+ write_multi_line(["inicio"])
37
 
38
  fecha_unix = str(int(time.time()))
39
 
 
81
  with open(os.path.join("static", "main.html")) as f:
82
  return HTMLResponse(f.read().replace("{% token %}", token).replace("{% version %}", fecha_unix))
83
 
84
+ @app.get("/tabs", response_class=HTMLResponse)
85
+ async def root_tabs(request: Request, credentials: HTTPBasicCredentials = Depends(security)):
86
+ if authenticate_user(credentials):
87
+ token = create_jwt_token({"user":credentials.username})
88
+ with open(os.path.join("static", "main2.html")) as f:
89
+ return HTMLResponse(f.read().replace("{% token %}", token).replace("{% version %}", fecha_unix))
90
+
91
 
92
  @app.post("/chat_stream")
93
  async def chat_stream(data = Depends(validate_token)):
 
176
 
177
  @app.get("/mfdfastapi")
178
  async def webhook_get(request: Request):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
+ write_multi_line([
181
+ "GET mfdfastapi:",
182
+ "headers: {}".format(json.dumps(dict(request.headers.items()))),
183
+ "params : {}".format(json.dumps(dict(request.query_params.items()))),
184
+
185
+ ])
186
+
187
  mode = request.query_params.get('hub.mode', "")
188
  if mode=="subscribe":
189
  challenge = request.query_params.get('hub.challenge', "")
 
196
  raise HTTPException(status_code=404, detail="Datos no válidos")
197
  return HTMLResponse(str(challenge))
198
 
 
 
 
199
  @app.post("/mfdfastapi")
200
  async def webhook_post(request: Request):
201
+ parametros_post = await request.json()
202
+ write_multi_line([
203
+ "POST mfdfastapi:",
204
+ "headers: {}".format(json.dumps(dict(request.headers.items()))),
205
+ "params : {}".format(json.dumps(dict(request.query_params.items()))),
206
+ "post : {}".format(json.dumps(parametros_post))
207
+ ])
208
+
 
 
 
 
 
 
 
 
 
 
209
  return HTMLResponse("ok")
210
 
static/css/app2.css ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .tab {
3
+ overflow: hidden;
4
+ border: 1px solid #ccc;
5
+ background-color: #f1f1f1;
6
+ }
7
+
8
+ .tab button {
9
+ background-color: inherit;
10
+ float: left;
11
+ border: none;
12
+ outline: none;
13
+ cursor: pointer;
14
+ padding: 14px 16px;
15
+ transition: 0.3s;
16
+ }
17
+
18
+ .tab button:hover {
19
+ background-color: #ddd;
20
+ }
21
+
22
+ .tab button.active {
23
+ background-color: #ccc;
24
+ }
25
+
26
+ .tabcontent {
27
+ display: none;
28
+ padding: 6px 12px;
29
+ border: 1px solid #ccc;
30
+ border-top: none;
31
+ }
32
+
33
+ .tabcontent:first-child {
34
+ display: block;
35
+ }
static/main2.html ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <head>
3
+ <title> Chatbot </title>
4
+ <meta name="viewport" content="width=device-width">
5
+ <link rel="shortcut icon" href="static/favicon.png" type="image/png">
6
+ <link rel="stylesheet" href="static/css/app.css?v={% version %}">
7
+ <link rel="stylesheet" href="static/css/app2.css?v={% version %}">
8
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
9
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css" rel="stylesheet" />
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js" integrity="sha512-9khQRAUBYEJDCDVP2yw3LRUQvjJ0Pjx0EShmaQjcHa6AXiOv6qHQu9lCAIR8O+/D8FtaCoJ2c0Tf9Xo7hYH01Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js" integrity="sha512-SkmBfuA2hqjzEVpmnMt/LINrjop3GKWqsuLSSB3e7iBmYK7JuWw4ldmmxwD9mdm2IRTTi0OxSAfEGvgEi0i2Kw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
12
+ <script src="static/js/chatHandler.js?v={% version %}"></script>
13
+ <script src="static/js/windowHandler.js?v={% version %}"></script>
14
+
15
+ </head>
16
+ <body>
17
+
18
+ <div class="wrapper">
19
+ <div class="tab">
20
+ <button class="tablinks" onclick="openTab(event, 'tab1')">Tab 1</button>
21
+ <button class="tablinks" onclick="openTab(event, 'tab2')">Tab 2</button>
22
+ <button class="tablinks" onclick="openTab(event, 'tab3')">Tab 3</button>
23
+ </div>
24
+ <div id="tab1" class="tabcontent">
25
+ <div class="chat" id="chat1"></div>
26
+ <div class="input-box">
27
+ <textarea class="input-text" id="input-text1" placeholder="Type something" type="text" autofocus></textarea>
28
+ <button class="input-send" id="input-send1"></button>
29
+ <button class="input-delete" id="input-delete1"></button>
30
+ </div>
31
+ </div>
32
+ <div id="tab2" class="tabcontent">
33
+ <div class="chat" id="chat2"></div>
34
+ <div class="input-box">
35
+ <textarea class="input-text" id="input-text2" placeholder="Type something" type="text" autofocus></textarea>
36
+ <button class="input-send" id="input-send2"></button>
37
+ <button class="input-delete" id="input-delete2"></button>
38
+ </div>
39
+ </div>
40
+ <div id="tab3" class="tabcontent">
41
+ <div class="chat" id="chat3"></div>
42
+ <div class="input-box">
43
+ <textarea class="input-text" id="input-text3" placeholder="Type something" type="text" autofocus></textarea>
44
+ <button class="input-send" id="input-send3"></button>
45
+ <button class="input-delete" id="input-delete3"></button>
46
+ </div>
47
+ </div>
48
+ </div>
49
+
50
+
51
+
52
+ <script>
53
+ let windH = null;
54
+ let chatH = null;
55
+
56
+ $(document).ready(function() {
57
+ chatH = new ChatGPT("{% token %}");
58
+ windH = new WindowHandler();
59
+
60
+ $(function() {
61
+ // Al cargar la página se muestra el primer tab y se activa su botón correspondiente
62
+ $('.tabcontent:first-child').show();
63
+ $('.tablinks:first-child').addClass('active');
64
+
65
+ // Al hacer clic en un botón de tab se muestra su contenido correspondiente
66
+ $('.tablinks').click(function(e) {
67
+ e.preventDefault();
68
+ $('.tabcontent').hide();
69
+ $('.tablinks').removeClass('active');
70
+ $(this).addClass('active');
71
+ var tab = $(this).attr('href');
72
+ $(tab).show();
73
+ });
74
+ });
75
+ });
76
+
77
+
78
+
79
+ </script>
80
+ </body>
81
+ </html>