|
@@ -15,12 +15,14 @@ from app.core.config import settings
|
|
|
from app.aianchor.utils2 import check_zip, VideoMakerError
|
|
|
from pathlib import Path
|
|
|
from app.db.session import SessionLocal
|
|
|
-
|
|
|
+import requests
|
|
|
import asyncio
|
|
|
|
|
|
BACKEND_ZIP_STORAGE = Path("/app").joinpath(settings.BACKEND_ZIP_STORAGE)
|
|
|
LOCAL_ZIP_STORAGE = Path("/").joinpath(settings.LOCAL_ZIP_STORAGE)
|
|
|
|
|
|
+LINE_URL = 'https://notify-api.line.me/api/notify'
|
|
|
+LINE_TOKEN = '剛剛複製的權杖'
|
|
|
|
|
|
router = APIRouter()
|
|
|
video_clients = {}
|
|
@@ -131,6 +133,18 @@ def upload_plot(
|
|
|
video_data['style'] = style
|
|
|
video_data['lang'] = lang
|
|
|
background_tasks.add_task(wait_finish, video_data)
|
|
|
+
|
|
|
+ headers = {
|
|
|
+ 'Authorization': 'Bearer ' + LINE_TOKEN # 設定權杖
|
|
|
+ }
|
|
|
+ data = {
|
|
|
+ 'message':f'cloud.choozmo.com \
|
|
|
+ Video \
|
|
|
+ user: {current_user.id}\n \
|
|
|
+ video: {video_data['id']}\n \
|
|
|
+ state: queuing' # 設定要發送的訊息
|
|
|
+ }
|
|
|
+ data = requests.post(LINE_URL, headers=headers, data=data)
|
|
|
return JSONResponse(return_msg, background=background_tasks)
|
|
|
|
|
|
async def wait_finish(video_data:dict):
|
|
@@ -152,7 +166,18 @@ async def wait_finish(video_data:dict):
|
|
|
db.close()
|
|
|
msg_data = f"{video_data['stored_filename']}:STARTED"
|
|
|
await publish(msg_data)
|
|
|
-
|
|
|
+ headers = {
|
|
|
+ 'Authorization': 'Bearer ' + LINE_TOKEN # 設定權杖
|
|
|
+ }
|
|
|
+ data = {
|
|
|
+ 'message':f'cloud.choozmo.com \
|
|
|
+ Video \
|
|
|
+ user: {video_data['owner_id']}\n \
|
|
|
+ membership: {video_data['membership_status']}\n \
|
|
|
+ video: {video_data['id']}\n \
|
|
|
+ state: start' # 設定要發送的訊息
|
|
|
+ }
|
|
|
+ data = requests.post(LINE_URL, headers=headers, data=data)
|
|
|
while True:
|
|
|
await asyncio.sleep(1)
|
|
|
if task.state != "STARTED":
|
|
@@ -169,6 +194,18 @@ async def wait_finish(video_data:dict):
|
|
|
db.commit()
|
|
|
db.close()
|
|
|
msg_data = f"{video_data['stored_filename']}:SUCCESS:{int(time)}"
|
|
|
+ headers = {
|
|
|
+ 'Authorization': 'Bearer ' + LINE_TOKEN # 設定權杖
|
|
|
+ }
|
|
|
+ data = {
|
|
|
+ 'message':f'cloud.choozmo.com \
|
|
|
+ Video \
|
|
|
+ user: {video_data['owner_id']}\n \
|
|
|
+ membership: {video_data['membership_status']}\n \
|
|
|
+ video: {video_data['id']}\n \
|
|
|
+ state: success' # 設定要發送的訊息
|
|
|
+ }
|
|
|
+ data = requests.post(LINE_URL, headers=headers, data=data)
|
|
|
|
|
|
elif task.state == "FAILURE":
|
|
|
db = SessionLocal()
|
|
@@ -178,6 +215,19 @@ async def wait_finish(video_data:dict):
|
|
|
db.close()
|
|
|
msg_data = f"{video_data['stored_filename']}:FAILURE"
|
|
|
|
|
|
+ headers = {
|
|
|
+ 'Authorization': 'Bearer ' + LINE_TOKEN # 設定權杖
|
|
|
+ }
|
|
|
+ data = {
|
|
|
+ 'message':f'cloud.choozmo.com \
|
|
|
+ Video \
|
|
|
+ user: {video_data['owner_id']}\n \
|
|
|
+ membership: {video_data['membership_status']}\n \
|
|
|
+ video: {video_data['id']}\n \
|
|
|
+ state: failure' # 設定要發送的訊息
|
|
|
+ }
|
|
|
+ data = requests.post(LINE_URL, headers=headers, data=data)
|
|
|
+
|
|
|
await publish(msg_data)
|
|
|
|
|
|
async def publish(data):
|
|
@@ -210,5 +260,51 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
|
except:
|
|
|
# 接続が切れた場合、当該クライアントを削除する
|
|
|
del video_clients[key]
|
|
|
+
|
|
|
+# # mia write
|
|
|
+# from pydantic import BaseModel
|
|
|
+
|
|
|
+# class phone_json(BaseModel):
|
|
|
+# title : str
|
|
|
+# text : str
|
|
|
+
|
|
|
+# IMAGEDIR = "/tmp/"
|
|
|
+# IMAGEDIR_all = "/var/lib/docker/overlay2/1e9b63ea29cc42551035ae2c5ce1cdf0c44a3f254879175a8a37db08ac7154de/diff/tmp/"
|
|
|
|
|
|
|
|
|
+# @router.post("/phone_input_json")
|
|
|
+# async def phone_input_json(
|
|
|
+# input_model:List[UploadFile],
|
|
|
+# text: str
|
|
|
+# ):
|
|
|
+# try:
|
|
|
+# result = []
|
|
|
+
|
|
|
+# text_json = eval(text)
|
|
|
+
|
|
|
+# for item,text_tmp in zip(input_model,text_json):
|
|
|
+
|
|
|
+# # img_url = ''
|
|
|
+# # if item != '':
|
|
|
+# # try:
|
|
|
+# # contents = await item.read()
|
|
|
+
|
|
|
+# #save the file
|
|
|
+# # with open(f"{IMAGEDIR}{item.filename}", "wb") as f:
|
|
|
+# # f.write(contents)
|
|
|
+
|
|
|
+# # img_url = f"{IMAGEDIR_all}{item.filename}"
|
|
|
+# # except Exception as e:
|
|
|
+# # img_url= str(e)
|
|
|
+
|
|
|
+# result.append(
|
|
|
+# {
|
|
|
+# "img" : item,
|
|
|
+# "title" :text_tmp["title"],
|
|
|
+# "text" : str(text_tmp["text"])
|
|
|
+# }
|
|
|
+# )
|
|
|
+
|
|
|
+# return result
|
|
|
+# except Exception as e:
|
|
|
+# return {"msg": str(e), "code": 500}
|