|
|
|
@ -1,9 +1,14 @@
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
from typing import List, Optional
|
|
|
|
from typing import List, Optional
|
|
|
|
|
|
|
|
|
|
|
|
from fastapi import APIRouter, HTTPException, status, File, UploadFile, Form
|
|
|
|
from fastapi import APIRouter, HTTPException, Response, status, File, UploadFile, Form
|
|
|
|
|
|
|
|
from fastapi.responses import StreamingResponse
|
|
|
|
|
|
|
|
import httpx
|
|
|
|
|
|
|
|
from sqlalchemy import select
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from src.aeros_project.model import AerosProject
|
|
|
|
from src.auth.service import CurrentUser
|
|
|
|
from src.auth.service import CurrentUser
|
|
|
|
|
|
|
|
from src.config import WINDOWS_AEROS_BASE_URL
|
|
|
|
from src.database.core import DbSession
|
|
|
|
from src.database.core import DbSession
|
|
|
|
from src.database.service import CommonParameters
|
|
|
|
from src.database.service import CommonParameters
|
|
|
|
from src.models import StandardResponse
|
|
|
|
from src.models import StandardResponse
|
|
|
|
@ -35,6 +40,50 @@ async def import_aro(
|
|
|
|
|
|
|
|
|
|
|
|
return {"data": None, "status": "success", "message": "Success"}
|
|
|
|
return {"data": None, "status": "success", "message": "Success"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/download")
|
|
|
|
|
|
|
|
async def forward_download(db_session: DbSession):
|
|
|
|
|
|
|
|
query = select(AerosProject)
|
|
|
|
|
|
|
|
data = await db_session.execute(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
project = data.scalar_one_or_none()
|
|
|
|
|
|
|
|
filename = f"{project.project_name}.aro"
|
|
|
|
|
|
|
|
url = f"{WINDOWS_AEROS_BASE_URL}/download/f{filename}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async with httpx.AsyncClient() as client:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
# Download entire file (no streaming)
|
|
|
|
|
|
|
|
response = await client.get(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if response.status_code != 200:
|
|
|
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
|
|
|
status_code=response.status_code,
|
|
|
|
|
|
|
|
detail="Failed to download from upstream service"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file_bytes = response.content # full file in memory
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Extract headers
|
|
|
|
|
|
|
|
content_disposition = response.headers.get(
|
|
|
|
|
|
|
|
"content-disposition",
|
|
|
|
|
|
|
|
f'attachment; filename="{filename}"'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
media_type = response.headers.get(
|
|
|
|
|
|
|
|
"content-type",
|
|
|
|
|
|
|
|
"application/octet-stream"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Return as ordinary file response
|
|
|
|
|
|
|
|
return Response(
|
|
|
|
|
|
|
|
content=file_bytes,
|
|
|
|
|
|
|
|
media_type=media_type,
|
|
|
|
|
|
|
|
headers={"Content-Disposition": content_disposition}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/metadata", response_model=StandardResponse[AerosMetadata])
|
|
|
|
@router.get("/metadata", response_model=StandardResponse[AerosMetadata])
|
|
|
|
async def getAerosMetadata(db_session: DbSession):
|
|
|
|
async def getAerosMetadata(db_session: DbSession):
|
|
|
|
result = await fetch_aro_record(db_session=db_session)
|
|
|
|
result = await fetch_aro_record(db_session=db_session)
|
|
|
|
|