|
@@ -21,9 +21,11 @@ from util.videoswap import video_swap
|
|
|
import requests
|
|
|
import uuid
|
|
|
import os
|
|
|
+import uvicorn
|
|
|
from util.cos_util import cos_upload
|
|
|
from database.database import insert,update,query,Task
|
|
|
from datetime import datetime
|
|
|
+from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
threadPool = ThreadPoolExecutor(max_workers=4)
|
|
|
def lcm(a, b): return abs(a * b) / fractions.gcd(a, b) if a and b else 0
|
|
@@ -131,18 +133,32 @@ class QueryItem(BaseModel):
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
+origins = [
|
|
|
+ "http://192.168.1.34",
|
|
|
+ "http://192.168.1.34:8000",
|
|
|
+ "http://192.168.1.105",
|
|
|
+ "http://192.168.1.105:3000",
|
|
|
+]
|
|
|
+
|
|
|
+app.add_middleware(
|
|
|
+ CORSMiddleware,
|
|
|
+ allow_origins=origins,
|
|
|
+ allow_credentials=True,
|
|
|
+ allow_methods=["*"],
|
|
|
+ allow_headers=["*"],
|
|
|
+)
|
|
|
+
|
|
|
@app.get('/')
|
|
|
def index():
|
|
|
return {'message': '你已经正确创建 FastApi 服务!'}
|
|
|
|
|
|
-@app.post('/task/query')
|
|
|
+@app.post('/jeecg-boot/task/query')
|
|
|
def task_query(queryItem:QueryItem):
|
|
|
- print(queryItem.id)
|
|
|
task = query(queryItem.id,queryItem.videoMd5,queryItem.imageMd5,queryItem.createBy)
|
|
|
return {'code':0,'data':task}
|
|
|
|
|
|
|
|
|
-@app.post('/task/single')
|
|
|
+@app.post('/jeecg-boot/task/single')
|
|
|
def single(item:Item):
|
|
|
#插入数据库
|
|
|
uid = str(uuid.uuid4())
|
|
@@ -205,6 +221,7 @@ def videoSwap(opt):
|
|
|
task = query(opt.taskId,None,None,None)[0]
|
|
|
task.status = 'download_error'
|
|
|
update(task)
|
|
|
+ del_file(opt.base_path)
|
|
|
|
|
|
task = query(opt.taskId,None,None,None)[0]
|
|
|
task.status = 'processing'
|
|
@@ -252,6 +269,11 @@ def videoSwap(opt):
|
|
|
task = query(opt.taskId,None,None,None)[0]
|
|
|
task.status = 'process_error'
|
|
|
update(task)
|
|
|
+ del_file(opt.base_path)
|
|
|
url = cos_upload(opt.output_path,datetime.now().strftime('%Y%m%d')+'/'+opt.output_file_name)
|
|
|
del_file(opt.base_path)
|
|
|
- return {'taskId':opt.taskId,'outputUrl':url}
|
|
|
+ return {'taskId':opt.taskId,'outputUrl':url}
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ uvicorn.run(app='main:app', host="0.0.0.0", port=8000, reload=True, debug=True)
|