Spaces:
Sleeping
Sleeping
kltn20133118
commited on
Update main.py
Browse files
main.py
CHANGED
@@ -6,16 +6,16 @@ import firebase_admin
|
|
6 |
from controller import ChatController
|
7 |
from firebase_admin import credentials
|
8 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
9 |
-
from service import MySQLService,LoginService,ChatService
|
10 |
-
from request import RequestMySQL,RequestLogin,RequestDefault
|
11 |
from auth.authentication import decodeJWT
|
12 |
from repository import UserRepository
|
13 |
from auth import authentication
|
14 |
from datetime import datetime, timedelta
|
15 |
from fastapi import Depends, HTTPException, Form, File, UploadFile
|
16 |
from typing import List
|
17 |
-
from service import FileService,DefaultService,LoginService
|
18 |
-
from request import RequestFile,RequestChat,RequestDefault
|
19 |
from fastapi import FastAPI, Request, HTTPException
|
20 |
from fastapi.responses import JSONResponse
|
21 |
from pydantic.error_wrappers import ErrorWrapper
|
@@ -42,7 +42,6 @@ app = FastAPI(
|
|
42 |
)
|
43 |
origins = [
|
44 |
"https://kltn20133118-pychatbot.hf.space",
|
45 |
-
"http://localhost:8501"
|
46 |
]
|
47 |
|
48 |
app.add_middleware(
|
@@ -54,13 +53,16 @@ app.add_middleware(
|
|
54 |
)
|
55 |
ALLOWED_EXTENSIONS = {'csv', 'txt', 'doc', 'docx', 'pdf', 'xlsx', 'pptx', 'json', 'md', 'xlsx'}
|
56 |
|
|
|
57 |
def allowed_file(filename):
|
58 |
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
59 |
|
|
|
60 |
if not firebase_admin._apps:
|
61 |
cred = credentials.Certificate("firebase_certificate.json")
|
62 |
fred = firebase_admin.initialize_app(cred)
|
63 |
|
|
|
64 |
class JWTBearer(HTTPBearer):
|
65 |
def __init__(self, auto_error: bool = True):
|
66 |
super(JWTBearer, self).__init__(auto_error=auto_error)
|
@@ -79,8 +81,9 @@ class JWTBearer(HTTPBearer):
|
|
79 |
raise HTTPException(status_code=401, detail="Invalid authorization code.")
|
80 |
|
81 |
def verify_accesstoken(self, jwtoken: str) -> bool:
|
82 |
-
|
83 |
-
|
|
|
84 |
def verify_jwt(self, jwtoken: str) -> bool:
|
85 |
try:
|
86 |
payload = decodeJWT(jwtoken)
|
@@ -91,6 +94,7 @@ class JWTBearer(HTTPBearer):
|
|
91 |
print(e)
|
92 |
return False
|
93 |
|
|
|
94 |
def get_current_user_email(credentials: str = Depends(JWTBearer())):
|
95 |
try:
|
96 |
payload = decodeJWT(credentials)
|
@@ -101,16 +105,20 @@ def get_current_user_email(credentials: str = Depends(JWTBearer())):
|
|
101 |
print(e)
|
102 |
raise HTTPException(status_code=403, detail="Invalid token or expired token.")
|
103 |
|
104 |
-
|
105 |
-
|
|
|
|
|
106 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
107 |
if check is not True:
|
108 |
return check
|
109 |
request = RequestMySQL.RequestRenderChatHistory(user_id=user_id)
|
110 |
return MySQLService.render_chat_history(request)
|
111 |
|
|
|
112 |
@app.put("/api/mysql/edit_chat/", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
113 |
-
async def override_edit_chat(request: RequestMySQL.RequestEditNameChat,
|
|
|
114 |
user_id = request.user_id
|
115 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
116 |
if check is not True:
|
@@ -123,20 +131,23 @@ async def override_edit_chat(request: RequestMySQL.RequestEditNameChat, current_
|
|
123 |
raise HTTPException(status_code=400, detail="name_old field is required.")
|
124 |
return MySQLService.edit_chat(request)
|
125 |
|
|
|
126 |
@app.delete("/api/mysql/delete_chat/", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
127 |
-
async def override_delete_chat(request: RequestMySQL.RequestDeleteChat,
|
|
|
128 |
user_id = request.user_id
|
129 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
130 |
if check is not True:
|
131 |
return check
|
132 |
-
chat_name= request.chat_name
|
133 |
if chat_name is None or chat_name.strip() == "":
|
134 |
raise HTTPException(status_code=400, detail="chat_name field is required.")
|
135 |
return MySQLService.delete_chat(request)
|
136 |
|
137 |
|
138 |
-
@app.get("/api/mysql/load_chat_history",dependencies=[Depends(JWTBearer())]
|
139 |
-
async def override_load_chat(chat_id: Optional[str] = Query(None), user_id: Optional[str] = Query(None),
|
|
|
140 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
141 |
if check is not True:
|
142 |
return check
|
@@ -152,19 +163,22 @@ async def override_load_chat(chat_id: Optional[str] = Query(None), user_id: Opti
|
|
152 |
if not support_function.is_positive_integer(chat_id_int):
|
153 |
return res.ReponseError(status=400,
|
154 |
data=res.Message(message="chat_id must be greater than 0"))
|
155 |
-
request = RequestMySQL.RequestLoadChatHistory(chat_id=chat_id,user_id
|
156 |
return MySQLService.load_chat_history(request)
|
157 |
|
158 |
-
|
159 |
-
|
|
|
160 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
161 |
if check is not True:
|
162 |
return check
|
163 |
request = RequestDefault.RequestInfoUser(user_id=user_id)
|
164 |
return DefaultService.info_user(request)
|
165 |
|
|
|
166 |
@app.post("/api/users/update_user_info", dependencies=[Depends(JWTBearer())], tags=["Login"])
|
167 |
-
async def override_update_user_info(request: RequestLogin.RequestUpdateUserInfo,
|
|
|
168 |
user_id = request.user_id
|
169 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
170 |
if check != True:
|
@@ -186,8 +200,10 @@ async def override_update_user_info(request: RequestLogin.RequestUpdateUserInfo,
|
|
186 |
data=res.Message(message="photo_url field is required."))
|
187 |
return LoginService.update_user_info(request)
|
188 |
|
|
|
189 |
@app.put('/api/users/change_password', dependencies=[Depends(JWTBearer())], tags=["Login"])
|
190 |
-
async def override_reset_password_firebase(request: RequestLogin.RequestChangePassword,
|
|
|
191 |
user_id = request.user_id
|
192 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
193 |
if check != True:
|
@@ -201,14 +217,20 @@ async def override_reset_password_firebase(request: RequestLogin.RequestChangePa
|
|
201 |
return res.ReponseError(status=400,
|
202 |
data=res.Message(message="current_password field is required."))
|
203 |
return LoginService.change_password(request)
|
|
|
|
|
204 |
@app.delete("/api/file/delete_all_file/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
205 |
-
async def override_delete_folder(request: RequestFile.RequestDeleteAllFile,
|
|
|
206 |
check = support_function.check_value_user_id(request.user_id, current_user_email)
|
207 |
if check != True:
|
208 |
return check
|
209 |
return FileService.deleteAllFile(request)
|
|
|
|
|
210 |
@app.delete("/api/file/delete_one_file/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
211 |
-
async def override_delete_one_file(request: RequestFile.RequestDeleteFile,
|
|
|
212 |
user_id = request.user_id
|
213 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
214 |
if check != True:
|
@@ -219,27 +241,32 @@ async def override_delete_one_file(request: RequestFile.RequestDeleteFile, curre
|
|
219 |
data=res.Message(message="name_file is required."))
|
220 |
return FileService.deleteFile(request)
|
221 |
|
|
|
222 |
@app.post("/api/file/chatbot/download_folder/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
223 |
-
async def override_download_folder_from_dropbox(request: RequestFile.RequestDownLoadFolder,
|
|
|
224 |
user_id = request.user_id
|
225 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
226 |
if check is not True:
|
227 |
return check
|
228 |
return FileService.download_folder(request)
|
229 |
|
|
|
230 |
@app.post("/api/file/chatbot/download_files/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
231 |
-
async def override_download_file_by_id(request: RequestFile.RequestDownLoadFile,
|
|
|
232 |
user_id = request.user_id
|
233 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
234 |
if check is not True:
|
235 |
return check
|
236 |
return FileService.download_file(request)
|
237 |
|
|
|
238 |
@app.post("/api/file/upload_files/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
239 |
async def override_upload_files_dropbox(
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
):
|
244 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
245 |
if check is not True:
|
@@ -247,38 +274,47 @@ async def override_upload_files_dropbox(
|
|
247 |
request = RequestFile.RequestUploadFile(files=files, user_id=user_id)
|
248 |
return FileService.upload_files(request)
|
249 |
|
|
|
250 |
@app.post("/api/chat/chatbot/query/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
251 |
-
async def override_handle_query2_upgrade_old(request: Request, user_id: str = Form(None), text_all: str = Form(...),
|
|
|
|
|
252 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
253 |
if check is not True:
|
254 |
return check
|
255 |
-
request = RequestChat.RequestQuery2UpgradeOld(user_id=user_id, text_all=text_all, question=question,
|
|
|
256 |
return ChatService.query2_upgrade_old(request)
|
257 |
|
|
|
258 |
@app.get("/api/chat/chatbot/extract_file/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
259 |
async def override_extract_file(user_id: str, current_user_email: str = Depends(get_current_user_email)):
|
260 |
-
check = support_function.check_value_user_id(user_id,current_user_email)
|
261 |
if check is not True:
|
262 |
return check
|
263 |
request = RequestChat.RequestExtractFile(user_id=user_id)
|
264 |
return ChatService.extract_file(request)
|
265 |
|
|
|
266 |
@app.get("/api/chat/chatbot/generate_question/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
267 |
-
async def override_generate_question(user_id: str
|
268 |
-
check = support_function.check_value_user_id(user_id,current_user_email)
|
269 |
if check is not True:
|
270 |
return check
|
271 |
request = RequestChat.RequestGenerateQuestion(user_id=user_id)
|
272 |
return ChatService.generate_question(request)
|
273 |
|
|
|
274 |
@app.post("/api/default/upload_image/", dependencies=[Depends(JWTBearer())], tags=["Default"])
|
275 |
-
async def override_upload_image(user_id: str = Form(None), file: UploadFile = File(...),
|
276 |
-
|
|
|
277 |
if check is not True:
|
278 |
return check
|
279 |
request = RequestDefault.RequestUpLoadImage(user_id=user_id, files=file)
|
280 |
return DefaultService.upload_image_service(request)
|
281 |
|
|
|
282 |
app.include_router(MySQLController.router, prefix="/api/mysql")
|
283 |
app.include_router(LoginController.router, prefix="/api/users")
|
284 |
app.include_router(FileController.router, prefix="/api/file")
|
@@ -303,31 +339,47 @@ routes_to_override = {
|
|
303 |
"/api/chat/chatbot/generate_question/": {"GET"},
|
304 |
"/api/default/upload_image/": {"POST"},
|
305 |
"/api/default/info_user": {"GET"}
|
306 |
-
|
307 |
}
|
308 |
|
309 |
app.router.routes = [
|
310 |
route for route in app.router.routes
|
311 |
if not (
|
312 |
-
|
313 |
-
|
314 |
)
|
315 |
]
|
316 |
|
317 |
-
app.add_api_route("/api/mysql/render_chat_history", override_render_chat, methods=["GET"],
|
318 |
-
|
319 |
-
app.add_api_route("/api/mysql/
|
320 |
-
|
321 |
-
app.add_api_route("/api/
|
322 |
-
|
323 |
-
app.add_api_route("/api/
|
324 |
-
|
325 |
-
app.add_api_route("/api/
|
326 |
-
|
327 |
-
app.add_api_route("/api/
|
328 |
-
|
329 |
-
app.add_api_route("/api/
|
330 |
-
|
331 |
-
app.add_api_route("/api/
|
332 |
-
|
333 |
-
app.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
from controller import ChatController
|
7 |
from firebase_admin import credentials
|
8 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
9 |
+
from service import MySQLService, LoginService, ChatService
|
10 |
+
from request import RequestMySQL, RequestLogin, RequestDefault
|
11 |
from auth.authentication import decodeJWT
|
12 |
from repository import UserRepository
|
13 |
from auth import authentication
|
14 |
from datetime import datetime, timedelta
|
15 |
from fastapi import Depends, HTTPException, Form, File, UploadFile
|
16 |
from typing import List
|
17 |
+
from service import FileService, DefaultService, LoginService
|
18 |
+
from request import RequestFile, RequestChat, RequestDefault
|
19 |
from fastapi import FastAPI, Request, HTTPException
|
20 |
from fastapi.responses import JSONResponse
|
21 |
from pydantic.error_wrappers import ErrorWrapper
|
|
|
42 |
)
|
43 |
origins = [
|
44 |
"https://kltn20133118-pychatbot.hf.space",
|
|
|
45 |
]
|
46 |
|
47 |
app.add_middleware(
|
|
|
53 |
)
|
54 |
ALLOWED_EXTENSIONS = {'csv', 'txt', 'doc', 'docx', 'pdf', 'xlsx', 'pptx', 'json', 'md', 'xlsx'}
|
55 |
|
56 |
+
|
57 |
def allowed_file(filename):
|
58 |
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
59 |
|
60 |
+
|
61 |
if not firebase_admin._apps:
|
62 |
cred = credentials.Certificate("firebase_certificate.json")
|
63 |
fred = firebase_admin.initialize_app(cred)
|
64 |
|
65 |
+
|
66 |
class JWTBearer(HTTPBearer):
|
67 |
def __init__(self, auto_error: bool = True):
|
68 |
super(JWTBearer, self).__init__(auto_error=auto_error)
|
|
|
81 |
raise HTTPException(status_code=401, detail="Invalid authorization code.")
|
82 |
|
83 |
def verify_accesstoken(self, jwtoken: str) -> bool:
|
84 |
+
check = LoginService.check_token_is_valid(jwtoken)
|
85 |
+
return check
|
86 |
+
|
87 |
def verify_jwt(self, jwtoken: str) -> bool:
|
88 |
try:
|
89 |
payload = decodeJWT(jwtoken)
|
|
|
94 |
print(e)
|
95 |
return False
|
96 |
|
97 |
+
|
98 |
def get_current_user_email(credentials: str = Depends(JWTBearer())):
|
99 |
try:
|
100 |
payload = decodeJWT(credentials)
|
|
|
105 |
print(e)
|
106 |
raise HTTPException(status_code=403, detail="Invalid token or expired token.")
|
107 |
|
108 |
+
|
109 |
+
@app.get("/api/mysql/render_chat_history", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
110 |
+
async def override_render_chat(user_id: Optional[str] = Query(None),
|
111 |
+
current_user_email: str = Depends(get_current_user_email)):
|
112 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
113 |
if check is not True:
|
114 |
return check
|
115 |
request = RequestMySQL.RequestRenderChatHistory(user_id=user_id)
|
116 |
return MySQLService.render_chat_history(request)
|
117 |
|
118 |
+
|
119 |
@app.put("/api/mysql/edit_chat/", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
120 |
+
async def override_edit_chat(request: RequestMySQL.RequestEditNameChat,
|
121 |
+
current_user_email: str = Depends(get_current_user_email)):
|
122 |
user_id = request.user_id
|
123 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
124 |
if check is not True:
|
|
|
131 |
raise HTTPException(status_code=400, detail="name_old field is required.")
|
132 |
return MySQLService.edit_chat(request)
|
133 |
|
134 |
+
|
135 |
@app.delete("/api/mysql/delete_chat/", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
136 |
+
async def override_delete_chat(request: RequestMySQL.RequestDeleteChat,
|
137 |
+
current_user_email: str = Depends(get_current_user_email)):
|
138 |
user_id = request.user_id
|
139 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
140 |
if check is not True:
|
141 |
return check
|
142 |
+
chat_name = request.chat_name
|
143 |
if chat_name is None or chat_name.strip() == "":
|
144 |
raise HTTPException(status_code=400, detail="chat_name field is required.")
|
145 |
return MySQLService.delete_chat(request)
|
146 |
|
147 |
|
148 |
+
@app.get("/api/mysql/load_chat_history", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
149 |
+
async def override_load_chat(chat_id: Optional[str] = Query(None), user_id: Optional[str] = Query(None),
|
150 |
+
current_user_email: str = Depends(get_current_user_email)):
|
151 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
152 |
if check is not True:
|
153 |
return check
|
|
|
163 |
if not support_function.is_positive_integer(chat_id_int):
|
164 |
return res.ReponseError(status=400,
|
165 |
data=res.Message(message="chat_id must be greater than 0"))
|
166 |
+
request = RequestMySQL.RequestLoadChatHistory(chat_id=chat_id, user_id=user_id)
|
167 |
return MySQLService.load_chat_history(request)
|
168 |
|
169 |
+
|
170 |
+
@app.get("/api/default/info_user", dependencies=[Depends(JWTBearer())], tags=["Default"])
|
171 |
+
async def override_get_user(user_id: str = Query(None), current_user_email: str = Depends(get_current_user_email)):
|
172 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
173 |
if check is not True:
|
174 |
return check
|
175 |
request = RequestDefault.RequestInfoUser(user_id=user_id)
|
176 |
return DefaultService.info_user(request)
|
177 |
|
178 |
+
|
179 |
@app.post("/api/users/update_user_info", dependencies=[Depends(JWTBearer())], tags=["Login"])
|
180 |
+
async def override_update_user_info(request: RequestLogin.RequestUpdateUserInfo,
|
181 |
+
current_user_email: str = Depends(get_current_user_email)):
|
182 |
user_id = request.user_id
|
183 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
184 |
if check != True:
|
|
|
200 |
data=res.Message(message="photo_url field is required."))
|
201 |
return LoginService.update_user_info(request)
|
202 |
|
203 |
+
|
204 |
@app.put('/api/users/change_password', dependencies=[Depends(JWTBearer())], tags=["Login"])
|
205 |
+
async def override_reset_password_firebase(request: RequestLogin.RequestChangePassword,
|
206 |
+
current_user_email: str = Depends(get_current_user_email)):
|
207 |
user_id = request.user_id
|
208 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
209 |
if check != True:
|
|
|
217 |
return res.ReponseError(status=400,
|
218 |
data=res.Message(message="current_password field is required."))
|
219 |
return LoginService.change_password(request)
|
220 |
+
|
221 |
+
|
222 |
@app.delete("/api/file/delete_all_file/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
223 |
+
async def override_delete_folder(request: RequestFile.RequestDeleteAllFile,
|
224 |
+
current_user_email: str = Depends(get_current_user_email)):
|
225 |
check = support_function.check_value_user_id(request.user_id, current_user_email)
|
226 |
if check != True:
|
227 |
return check
|
228 |
return FileService.deleteAllFile(request)
|
229 |
+
|
230 |
+
|
231 |
@app.delete("/api/file/delete_one_file/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
232 |
+
async def override_delete_one_file(request: RequestFile.RequestDeleteFile,
|
233 |
+
current_user_email: str = Depends(get_current_user_email)):
|
234 |
user_id = request.user_id
|
235 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
236 |
if check != True:
|
|
|
241 |
data=res.Message(message="name_file is required."))
|
242 |
return FileService.deleteFile(request)
|
243 |
|
244 |
+
|
245 |
@app.post("/api/file/chatbot/download_folder/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
246 |
+
async def override_download_folder_from_dropbox(request: RequestFile.RequestDownLoadFolder,
|
247 |
+
current_user_email: str = Depends(get_current_user_email)):
|
248 |
user_id = request.user_id
|
249 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
250 |
if check is not True:
|
251 |
return check
|
252 |
return FileService.download_folder(request)
|
253 |
|
254 |
+
|
255 |
@app.post("/api/file/chatbot/download_files/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
256 |
+
async def override_download_file_by_id(request: RequestFile.RequestDownLoadFile,
|
257 |
+
current_user_email: str = Depends(get_current_user_email)):
|
258 |
user_id = request.user_id
|
259 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
260 |
if check is not True:
|
261 |
return check
|
262 |
return FileService.download_file(request)
|
263 |
|
264 |
+
|
265 |
@app.post("/api/file/upload_files/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
266 |
async def override_upload_files_dropbox(
|
267 |
+
user_id: str = Form(None),
|
268 |
+
files: List[UploadFile] = File(None),
|
269 |
+
current_user_email: str = Depends(get_current_user_email)
|
270 |
):
|
271 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
272 |
if check is not True:
|
|
|
274 |
request = RequestFile.RequestUploadFile(files=files, user_id=user_id)
|
275 |
return FileService.upload_files(request)
|
276 |
|
277 |
+
|
278 |
@app.post("/api/chat/chatbot/query/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
279 |
+
async def override_handle_query2_upgrade_old(request: Request, user_id: str = Form(None), text_all: str = Form(...),
|
280 |
+
question: str = Form(None), chat_name: str = Form(None),
|
281 |
+
current_user_email: str = Depends(get_current_user_email)):
|
282 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
283 |
if check is not True:
|
284 |
return check
|
285 |
+
request = RequestChat.RequestQuery2UpgradeOld(user_id=user_id, text_all=text_all, question=question,
|
286 |
+
chat_name=chat_name)
|
287 |
return ChatService.query2_upgrade_old(request)
|
288 |
|
289 |
+
|
290 |
@app.get("/api/chat/chatbot/extract_file/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
291 |
async def override_extract_file(user_id: str, current_user_email: str = Depends(get_current_user_email)):
|
292 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
293 |
if check is not True:
|
294 |
return check
|
295 |
request = RequestChat.RequestExtractFile(user_id=user_id)
|
296 |
return ChatService.extract_file(request)
|
297 |
|
298 |
+
|
299 |
@app.get("/api/chat/chatbot/generate_question/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
300 |
+
async def override_generate_question(user_id: str, current_user_email: str = Depends(get_current_user_email)):
|
301 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
302 |
if check is not True:
|
303 |
return check
|
304 |
request = RequestChat.RequestGenerateQuestion(user_id=user_id)
|
305 |
return ChatService.generate_question(request)
|
306 |
|
307 |
+
|
308 |
@app.post("/api/default/upload_image/", dependencies=[Depends(JWTBearer())], tags=["Default"])
|
309 |
+
async def override_upload_image(user_id: str = Form(None), file: UploadFile = File(...),
|
310 |
+
current_user_email: str = Depends(get_current_user_email)):
|
311 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
312 |
if check is not True:
|
313 |
return check
|
314 |
request = RequestDefault.RequestUpLoadImage(user_id=user_id, files=file)
|
315 |
return DefaultService.upload_image_service(request)
|
316 |
|
317 |
+
|
318 |
app.include_router(MySQLController.router, prefix="/api/mysql")
|
319 |
app.include_router(LoginController.router, prefix="/api/users")
|
320 |
app.include_router(FileController.router, prefix="/api/file")
|
|
|
339 |
"/api/chat/chatbot/generate_question/": {"GET"},
|
340 |
"/api/default/upload_image/": {"POST"},
|
341 |
"/api/default/info_user": {"GET"}
|
342 |
+
|
343 |
}
|
344 |
|
345 |
app.router.routes = [
|
346 |
route for route in app.router.routes
|
347 |
if not (
|
348 |
+
route.path in routes_to_override and
|
349 |
+
route.methods.intersection(routes_to_override[route.path])
|
350 |
)
|
351 |
]
|
352 |
|
353 |
+
app.add_api_route("/api/mysql/render_chat_history", override_render_chat, methods=["GET"],
|
354 |
+
dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
355 |
+
app.add_api_route("/api/mysql/load_chat_history", override_load_chat, methods=["GET"],
|
356 |
+
dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
357 |
+
app.add_api_route("/api/mysql/edit_chat/", override_edit_chat, methods=["PUT"], dependencies=[Depends(JWTBearer())],
|
358 |
+
tags=["MySQL"])
|
359 |
+
app.add_api_route("/api/mysql/delete_chat/", override_delete_chat, methods=["DELETE"],
|
360 |
+
dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
361 |
+
app.add_api_route("/api/users/update_user_info", override_update_user_info, methods=["POST"],
|
362 |
+
dependencies=[Depends(JWTBearer())], tags=["Login"])
|
363 |
+
app.add_api_route("/api/users/change_password", override_reset_password_firebase, methods=["PUT"],
|
364 |
+
dependencies=[Depends(JWTBearer())], tags=["Login"])
|
365 |
+
app.add_api_route("/api/file/delete_all_file/", override_delete_folder, methods=["DELETE"],
|
366 |
+
dependencies=[Depends(JWTBearer())], tags=["File"])
|
367 |
+
app.add_api_route("/api/file/delete_one_file/", override_delete_one_file, methods=["DELETE"],
|
368 |
+
dependencies=[Depends(JWTBearer())], tags=["File"])
|
369 |
+
app.add_api_route("/api/file/chatbot/download_folder/", override_download_folder_from_dropbox, methods=["POST"],
|
370 |
+
dependencies=[Depends(JWTBearer())], tags=["File"])
|
371 |
+
app.add_api_route("/api/file/chatbot/download_files/", override_download_file_by_id, methods=["POST"],
|
372 |
+
dependencies=[Depends(JWTBearer())], tags=["File"])
|
373 |
+
app.add_api_route("/api/file/upload_files/", override_upload_files_dropbox, methods=["POST"],
|
374 |
+
dependencies=[Depends(JWTBearer())], tags=["File"])
|
375 |
+
app.add_api_route("/api/chat/chatbot/query/", override_handle_query2_upgrade_old, methods=["POST"],
|
376 |
+
dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
377 |
+
app.add_api_route("/api/chat/chatbot/extract_file/", override_extract_file, methods=["GET"],
|
378 |
+
dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
379 |
+
app.add_api_route("/api/chat/chatbot/generate_question/", override_generate_question, methods=["GET"],
|
380 |
+
dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
381 |
+
app.add_api_route("/api/default/upload_image/", override_upload_image, methods=["POST"],
|
382 |
+
dependencies=[Depends(JWTBearer())], tags=["Default"])
|
383 |
+
app.add_api_route("/api/default/info_user", override_get_user, methods=["GET"], dependencies=[Depends(JWTBearer())],
|
384 |
+
tags=["Default"])
|
385 |
+
app.include_router(OTPController.router, tags=["OTP"], prefix="/api/otp")
|