|
@@ -100,13 +100,13 @@ async def get_home_page(request: Request, response: Response):
|
|
async def get_home_page(request: Request, response: Response):
|
|
async def get_home_page(request: Request, response: Response):
|
|
return templates.TemplateResponse("index.html", {"request": request, "response": response})
|
|
return templates.TemplateResponse("index.html", {"request": request, "response": response})
|
|
|
|
|
|
-@app.get("/make_video", response_class=HTMLResponse)
|
|
|
|
|
|
+@app.get("/make_video")
|
|
async def get_home_page(request: Request, response: Response, Authorize: AuthJWT = Depends()):
|
|
async def get_home_page(request: Request, response: Response, Authorize: AuthJWT = Depends()):
|
|
try:
|
|
try:
|
|
Authorize.jwt_required()
|
|
Authorize.jwt_required()
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(e)
|
|
print(e)
|
|
- return '請先登入帳號'
|
|
|
|
|
|
+ return {'msg':{'eng':'Please login first','zh':'請先登入帳號'}}
|
|
current_user = Authorize.get_jwt_subject()
|
|
current_user = Authorize.get_jwt_subject()
|
|
return templates.TemplateResponse("make_video.html", {"request": request, "response": response})
|
|
return templates.TemplateResponse("make_video.html", {"request": request, "response": response})
|
|
|
|
|
|
@@ -116,7 +116,7 @@ async def get_home_page(request: Request, response: Response, Authorize: AuthJWT
|
|
Authorize.jwt_required()
|
|
Authorize.jwt_required()
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(e)
|
|
print(e)
|
|
- return '請先登入帳號'
|
|
|
|
|
|
+ return {'msg':{'eng':'Please login first','zh':'請先登入帳號'}}
|
|
current_user = Authorize.get_jwt_subject()
|
|
current_user = Authorize.get_jwt_subject()
|
|
return templates.TemplateResponse("make_video_long.html", {"request": request, "response": response})
|
|
return templates.TemplateResponse("make_video_long.html", {"request": request, "response": response})
|
|
|
|
|
|
@@ -126,7 +126,7 @@ async def make_video_slide(request: Request, response: Response, Authorize: Auth
|
|
Authorize.jwt_required()
|
|
Authorize.jwt_required()
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(e)
|
|
print(e)
|
|
- return '請先登入帳號'
|
|
|
|
|
|
+ return {'msg':{'eng':'Please login first','zh':'請先登入帳號'}}
|
|
current_user = Authorize.get_jwt_subject()
|
|
current_user = Authorize.get_jwt_subject()
|
|
return templates.TemplateResponse("make_video_slide.html", {"request": request, "response": response})
|
|
return templates.TemplateResponse("make_video_slide.html", {"request": request, "response": response})
|
|
|
|
|
|
@@ -147,13 +147,24 @@ async def user_profile(token: str = Depends(oauth2_scheme)):
|
|
left_sec = user_obj['left_time']
|
|
left_sec = user_obj['left_time']
|
|
|
|
|
|
video_info_list = []
|
|
video_info_list = []
|
|
- statement = 'SELECT * FROM history_input WHERE user_id='+str(user_obj['id'])
|
|
|
|
|
|
+ statement = 'SELECT * FROM history_input WHERE user_id='+str(user_obj['id'])+' ORDER BY timestamp DESC LIMIT 50'
|
|
for row in db.query(statement):
|
|
for row in db.query(statement):
|
|
video_info_list.append({'id':row['id'],'title':row['name'],'duration':row['duration'],'url':row['link'],'time_stamp':row['timestamp'].strftime("%m/%d/%Y, %H:%M:%S")})
|
|
video_info_list.append({'id':row['id'],'title':row['name'],'duration':row['duration'],'url':row['link'],'time_stamp':row['timestamp'].strftime("%m/%d/%Y, %H:%M:%S")})
|
|
dic_return = {'user_info':{'id':user_id,'userName':user_obj['username'],'email':user_obj['email'],'video_num':video_num,'total_sec':total_sec,'left_sec':user_obj['left_time']},'video_info':video_info_list}
|
|
dic_return = {'user_info':{'id':user_id,'userName':user_obj['username'],'email':user_obj['email'],'video_num':video_num,'total_sec':total_sec,'left_sec':user_obj['left_time']},'video_info':video_info_list}
|
|
str_return = json.dumps(dic_return)
|
|
str_return = json.dumps(dic_return)
|
|
return str_return
|
|
return str_return
|
|
|
|
|
|
|
|
+@app.post('/edit_profile')
|
|
|
|
+async def edit_profile(userModel : models.UserProfile ,token: str = Depends(oauth2_scheme)):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
|
+ print(token)
|
|
|
|
+ user_id = get_user_id(token)
|
|
|
|
+ print(user_id)
|
|
|
|
+ user_obj = next(iter(db.query('SELECT * FROM users where id ="'+str(user_id)+'"')))
|
|
|
|
+ user_obj['email'] = userModel.email
|
|
|
|
+ db['users'].update(user_obj,['id'])
|
|
|
|
+ return {'msg':'ok'}
|
|
|
|
+
|
|
# login & register page
|
|
# login & register page
|
|
@app.get("/login", response_class=HTMLResponse)
|
|
@app.get("/login", response_class=HTMLResponse)
|
|
async def get_login_and_register_page(request: Request):
|
|
async def get_login_and_register_page(request: Request):
|
|
@@ -216,13 +227,13 @@ async def register_old(request: Request):
|
|
code = str(time.time()).replace('.','')
|
|
code = str(time.time()).replace('.','')
|
|
db['register_veri_code'].insert({'code':code,'user_id':id})
|
|
db['register_veri_code'].insert({'code':code,'user_id':id})
|
|
mailer.register_verify('請至點擊網址驗證 : https://www.choozmo.com:8887/verify_email?code='+code, user.email)
|
|
mailer.register_verify('請至點擊網址驗證 : https://www.choozmo.com:8887/verify_email?code='+code, user.email)
|
|
- return '註冊成功! 請回到上頁登入帳號'
|
|
|
|
|
|
+ return {'msg':{'eng':'Register success! Please login at previous page','zh':'註冊成功! 請回到上頁登入帳號'}}
|
|
else :
|
|
else :
|
|
return {'msg':'error'}
|
|
return {'msg':'error'}
|
|
#return templates.TemplateResponse("make_video.html", {"request": request, "success": True},status_code=status.HTTP_302_FOUND)
|
|
#return templates.TemplateResponse("make_video.html", {"request": request, "success": True},status_code=status.HTTP_302_FOUND)
|
|
#return templates.TemplateResponse("login.html", {'request': request,"success": True}, status_code=status.HTTP_302_FOUND)
|
|
#return templates.TemplateResponse("login.html", {'request': request,"success": True}, status_code=status.HTTP_302_FOUND)
|
|
else:
|
|
else:
|
|
- return {'msg':user.username+'重複,請更改'}
|
|
|
|
|
|
+ return {'msg':{'eng':user.username+' is duplicated user name try another','zh':user.username+'重複,請更改'}}
|
|
|
|
|
|
@app.post("/register")
|
|
@app.post("/register")
|
|
async def register(request: models.register_req):
|
|
async def register(request: models.register_req):
|
|
@@ -235,11 +246,11 @@ async def register(request: models.register_req):
|
|
code = str(time.time()).replace('.','')
|
|
code = str(time.time()).replace('.','')
|
|
db['register_veri_code'].insert({'code':code,'user_id':id})
|
|
db['register_veri_code'].insert({'code':code,'user_id':id})
|
|
mailer.register_verify('請至點擊網址驗證 : https://www.choozmo.com:8887/verify_email?code='+code, request.email)
|
|
mailer.register_verify('請至點擊網址驗證 : https://www.choozmo.com:8887/verify_email?code='+code, request.email)
|
|
- return '註冊成功! 請回到上頁登入帳號'
|
|
|
|
|
|
+ return {'msg':{'eng':'Register success! Please login at previous page','zh':'註冊成功! 請回到上頁登入帳號'}}
|
|
else :
|
|
else :
|
|
return {'msg':'error'}
|
|
return {'msg':'error'}
|
|
else:
|
|
else:
|
|
- return {'msg':request.username+':使用者名稱重複,請更改'}
|
|
|
|
|
|
+ return {'msg':{'eng':user.username+' is duplicated user name try another','zh':user.username+'重複,請更改'}}
|
|
|
|
|
|
|
|
|
|
@app.get('/logout')
|
|
@app.get('/logout')
|
|
@@ -480,6 +491,57 @@ async def make_anchor_video_eng(req:models.request_eng,token: str = Depends(oaut
|
|
x.start()
|
|
x.start()
|
|
return {"msg":"ok"}
|
|
return {"msg":"ok"}
|
|
|
|
|
|
|
|
+@app.post("/save_draft")
|
|
|
|
+async def save_draft(req:models.video_draft,token: str = Depends(oauth2_scheme)):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
|
+ user_id = get_user_id(token)
|
|
|
|
+
|
|
|
|
+ txt_content_seperate_by_dot = ''
|
|
|
|
+ for txt in req.text_content:
|
|
|
|
+ txt_content_seperate_by_dot += txt+","
|
|
|
|
+ txt_content_seperate_by_dot = txt_content_seperate_by_dot[:-1]
|
|
|
|
+ img_urls_seperate_by_dot = ''
|
|
|
|
+ for iurl in req.image_urls:
|
|
|
|
+ img_urls_seperate_by_dot += iurl+","
|
|
|
|
+ img_urls_seperate_by_dot = img_urls_seperate_by_dot[:-1]
|
|
|
|
+ time_stamp = datetime.fromtimestamp(time.time())
|
|
|
|
+ time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
+
|
|
|
|
+ if req.id==-1:
|
|
|
|
+ pk = db['draft'].insert({'title':req.title,'text_content':txt_content_seperate_by_dot,'image_urls':img_urls_seperate_by_dot
|
|
|
|
+ ,'user_id':user_id,'avatar':req.avatar,'multiLang':req.multiLang,'time_stamp':time_stamp})
|
|
|
|
+ else:
|
|
|
|
+ db['draft'].update({'id':req.id,'title':req.title,'text_content':txt_content_seperate_by_dot,'image_urls':img_urls_seperate_by_dot
|
|
|
|
+ ,'user_id':user_id,'avatar':req.avatar,'multiLang':req.multiLang,'time_stamp':time_stamp},['id'])
|
|
|
|
+
|
|
|
|
+ return {'msg':'ok'}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@app.post('/draft_list')
|
|
|
|
+async def draft_list(token: str = Depends(oauth2_scheme)):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
|
+ user_id = get_user_id(token)
|
|
|
|
+ statement = 'SELECT * FROM draft WHERE user_id='+str(user_id)+' ORDER BY time_stamp DESC LIMIT 50'
|
|
|
|
+ logs = []
|
|
|
|
+ for row in db.query(statement):
|
|
|
|
+ logs.append({'id':row['id'],'title':row['title'],'avatar':row['avatar'],'mulitLang':row['multiLang']
|
|
|
|
+ ,'text_content':row['text_content'].split(','),'image_urls':row['image_urls'].split(',')})
|
|
|
|
+ return logs
|
|
|
|
+
|
|
|
|
+@app.post('/del_draft')
|
|
|
|
+async def del_draft(id_obj:models.id_obj,token: str = Depends(oauth2_scheme)):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
|
+ user_id = get_user_id(token)
|
|
|
|
+ statement = 'SELECT * FROM draft WHERE user_id="'+str(user_id)+'" and id ="'+id_obj.id+'"'
|
|
|
|
+ if first(db.query(statement)) is not None:
|
|
|
|
+ db['draft'].delete(id=id)
|
|
|
|
+ else:
|
|
|
|
+ return {'msg':'wrong id'}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return {'msg':'ok'}
|
|
|
|
+
|
|
|
|
+
|
|
@app.get("/history_input_old")
|
|
@app.get("/history_input_old")
|
|
async def history_input_old(request: Request, Authorize: AuthJWT = Depends()):
|
|
async def history_input_old(request: Request, Authorize: AuthJWT = Depends()):
|
|
Authorize.jwt_required()
|
|
Authorize.jwt_required()
|