fix: sửa lỗi Ai prompt multi

This commit is contained in:
2026-07-22 18:37:52 +07:00
parent ec178b42f3
commit 6f0fac9f2d
3 changed files with 62 additions and 4 deletions
+9 -4
View File
@@ -1,11 +1,15 @@
import os import os
import uuid import uuid
import asyncio import asyncio
from fastapi import APIRouter, UploadFile, File, HTTPException, Query import json
from fastapi import APIRouter, UploadFile, File, HTTPException, Query, Depends
from fastapi.responses import FileResponse from fastapi.responses import FileResponse
from pydantic import BaseModel from pydantic import BaseModel
from typing import Optional from typing import Optional, List
from app.config import settings from app.config import settings
from app.api.v1.auth import get_current_user
from app.api.v1.projects import get_optional_user
from app.models.user import get_db_connection
router = APIRouter() router = APIRouter()
@@ -52,11 +56,12 @@ class PythonToolRequest(BaseModel):
wave_type: Optional[str] = "sine" wave_type: Optional[str] = "sine"
@router.post("/upload") @router.post("/upload")
async def upload_audio(file: UploadFile = File(...)): async def upload_audio(file: UploadFile = File(...), current_user: Optional[dict] = Depends(get_optional_user)):
user_id = current_user["user_id"] if current_user else "anonymous"
ext = os.path.splitext(file.filename)[1] ext = os.path.splitext(file.filename)[1]
if not ext: if not ext:
ext = ".wav" ext = ".wav"
file_id = f"{uuid.uuid4()}{ext}" file_id = f"user_{user_id}_{uuid.uuid4()}{ext}"
file_path = os.path.join(settings.UPLOADS_DIR, file_id) file_path = os.path.join(settings.UPLOADS_DIR, file_id)
with open(file_path, "wb") as f: with open(file_path, "wb") as f:
+53
View File
@@ -126,3 +126,56 @@ async def list_cloud_projects(current_user: dict = Depends(get_current_user)):
"updated_at": r["updated_at"] "updated_at": r["updated_at"]
} for r in rows } for r in rows
] ]
@router.get("/cloud/{project_id}")
async def get_cloud_project(project_id: str, current_user: dict = Depends(get_current_user)):
user_id = current_user["user_id"]
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("SELECT name, data_json FROM projects WHERE id = ? AND user_id = ? AND is_temp = 0", (project_id, user_id))
row = cursor.fetchone()
conn.close()
if not row:
raise HTTPException(status_code=404, detail="Không tìm thấy dự án")
return {
"id": project_id,
"name": row["name"],
"data_json": row["data_json"]
}
@router.delete("/cloud/{project_id}")
async def delete_cloud_project(project_id: str, current_user: dict = Depends(get_current_user)):
user_id = current_user["user_id"]
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("DELETE FROM projects WHERE id = ? AND user_id = ? AND is_temp = 0", (project_id, user_id))
conn.commit()
conn.close()
return {"success": True, "message": "Đã xóa dự án thành công"}
@router.put("/cloud/{project_id}")
async def update_cloud_project(project_id: str, req: SaveProjectRequest, current_user: dict = Depends(get_current_user)):
user_id = current_user["user_id"]
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("SELECT id FROM projects WHERE id = ? AND user_id = ? AND is_temp = 0", (project_id, user_id))
exists = cursor.fetchone()
if not exists:
conn.close()
raise HTTPException(status_code=404, detail="Không tìm thấy dự án để cập nhật")
new_size_bytes = len(req.data_json.encode("utf-8"))
now = time.time()
cursor.execute("""
UPDATE projects
SET name = ?, data_json = ?, size_bytes = ?, updated_at = ?
WHERE id = ? AND user_id = ?
""", (req.name, req.data_json, new_size_bytes, now, project_id, user_id))
conn.commit()
conn.close()
return {"success": True, "message": "Đã cập nhật dự án thành công"}
Binary file not shown.