|
@@ -4,7 +4,7 @@ from fastapi import APIRouter, Body, Depends, HTTPException, Form, status, Respo
|
|
from fastapi.encoders import jsonable_encoder
|
|
from fastapi.encoders import jsonable_encoder
|
|
from pydantic.networks import EmailStr, HttpUrl
|
|
from pydantic.networks import EmailStr, HttpUrl
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy.orm import Session
|
|
-from fastapi.responses import FileResponse, PlainTextResponse
|
|
|
|
|
|
+from fastapi.responses import FileResponse, PlainTextResponse, JSONResponse
|
|
import app.crud as crud
|
|
import app.crud as crud
|
|
import app.models as models
|
|
import app.models as models
|
|
import app.schemas as schemas
|
|
import app.schemas as schemas
|
|
@@ -37,6 +37,8 @@ from app.core.config import settings
|
|
from app.aianchor.utils2 import check_zip, VideoMakerError
|
|
from app.aianchor.utils2 import check_zip, VideoMakerError
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
import emails
|
|
import emails
|
|
|
|
+from fastapi import UploadFile, File, Form
|
|
|
|
+from app.core.video_utils import update_zip
|
|
|
|
|
|
BACKEND_ZIP_STORAGE = Path("/app").joinpath(settings.BACKEND_ZIP_STORAGE)
|
|
BACKEND_ZIP_STORAGE = Path("/app").joinpath(settings.BACKEND_ZIP_STORAGE)
|
|
LOCAL_ZIP_STORAGE = Path("/").joinpath(settings.LOCAL_ZIP_STORAGE)
|
|
LOCAL_ZIP_STORAGE = Path("/").joinpath(settings.LOCAL_ZIP_STORAGE)
|
|
@@ -107,7 +109,8 @@ async def generate_zip(
|
|
*,
|
|
*,
|
|
background_tasks: BackgroundTasks,
|
|
background_tasks: BackgroundTasks,
|
|
current_user: models.User = Depends(deps.get_current_active_user),
|
|
current_user: models.User = Depends(deps.get_current_active_user),
|
|
- model:Literal['sd3', 'flux']="sd3",
|
|
|
|
|
|
+
|
|
|
|
+ upload_file: UploadFile=File(),
|
|
texts:List[str]):
|
|
texts:List[str]):
|
|
|
|
|
|
if not model:
|
|
if not model:
|
|
@@ -334,3 +337,35 @@ def send_simple_email(email_to: str, video_path: str):
|
|
print(r)
|
|
print(r)
|
|
assert r.status_code == 250
|
|
assert r.status_code == 250
|
|
|
|
|
|
|
|
+@router.post('/zip-translate')
|
|
|
|
+def zip_translate(
|
|
|
|
+ *,
|
|
|
|
+ background_tasks: BackgroundTasks,
|
|
|
|
+ upload_file: UploadFile=File(),
|
|
|
|
+ lang:Literal["en", 'zh', 'zh-TW', 'ja', 'vi']):
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ with open(upload_file.filename, 'wb') as f:
|
|
|
|
+ while contents := upload_file.file.read(1024 * 1024):
|
|
|
|
+ f.write(contents)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e, type(e))
|
|
|
|
+ error_msg = {"error_message": str(e)}
|
|
|
|
+ return JSONResponse(error_msg)
|
|
|
|
+ finally:
|
|
|
|
+ upload_file.file.close()
|
|
|
|
+ try:
|
|
|
|
+ if check_zip(upload_file.filename):
|
|
|
|
+ print("passed check_zip")
|
|
|
|
+ except VideoMakerError as e:
|
|
|
|
+ print(e)
|
|
|
|
+ error_msg = {"accepted": False, "error_message":f'{e}'}
|
|
|
|
+ return JSONResponse(error_msg)
|
|
|
|
+ path = Path(upload_file.filename)
|
|
|
|
+ update_zip(str(path), 'zh-TW', str(path.parent/(path.stem+"_"+lang+path.suffix)))
|
|
|
|
+
|
|
|
|
+ def remove_zip():
|
|
|
|
+ if os.path.exists(str(path.parent/(path.stem+"_"+lang+path.suffix))):
|
|
|
|
+ os.remove(str(path.parent/(path.stem+"_"+lang+path.suffix)))
|
|
|
|
+ background_tasks.add_task(remove_zip)
|
|
|
|
+ return FileResponse(str(path.parent/(path.stem+"_"+lang+path.suffix)), media_type="application/zip")
|