|
|
|
|
@ -3,7 +3,7 @@ from typing import Optional
|
|
|
|
|
|
|
|
|
|
import httpx
|
|
|
|
|
from fastapi import HTTPException, status
|
|
|
|
|
from sqlalchemy import Delete, Select, func
|
|
|
|
|
from sqlalchemy import Delete, desc, Select, select, func
|
|
|
|
|
from sqlalchemy.orm import selectinload
|
|
|
|
|
|
|
|
|
|
from src.aeros_equipment.service import save_default_equipment
|
|
|
|
|
@ -17,7 +17,7 @@ from .model import AerosProject
|
|
|
|
|
from .schema import AerosProjectInput
|
|
|
|
|
|
|
|
|
|
ALLOWED_EXTENSIONS = {".aro"}
|
|
|
|
|
MAX_FILE_SIZE = 5 * 1024 * 1024 # 5MB
|
|
|
|
|
MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB
|
|
|
|
|
client = httpx.AsyncClient(timeout=300.0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -43,7 +43,7 @@ async def import_aro_project(*, db_session: DbSession, aeros_project_in: AerosPr
|
|
|
|
|
if len(content) > MAX_FILE_SIZE:
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
status_code=400,
|
|
|
|
|
detail="File too large. Max size: 5MB"
|
|
|
|
|
detail="File too large. Max size: 100MB"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -53,20 +53,21 @@ async def import_aro_project(*, db_session: DbSession, aeros_project_in: AerosPr
|
|
|
|
|
# Project name
|
|
|
|
|
project_name = filename_without_ext
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## save File to windows app
|
|
|
|
|
# Output is string of file path, examole
|
|
|
|
|
# # Example response "C/dsad/dsad.aro"
|
|
|
|
|
try:
|
|
|
|
|
# Reset file position since we already read it for size check
|
|
|
|
|
await file.seek(0)
|
|
|
|
|
# await file.seek(0)
|
|
|
|
|
|
|
|
|
|
# Prepare file for upload
|
|
|
|
|
files = {
|
|
|
|
|
"file": (file.filename, await file.read(), file.content_type or "application/octet-stream")
|
|
|
|
|
"file": (file.filename, content, file.content_type or "application/octet-stream")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = await client.post(
|
|
|
|
|
f"{windows_aeros_base_url}/api/aeros/upload-file",
|
|
|
|
|
f"http://192.168.1.87:8800/api/aeros/upload-file",
|
|
|
|
|
files=files
|
|
|
|
|
)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
@ -94,7 +95,19 @@ async def import_aro_project(*, db_session: DbSession, aeros_project_in: AerosPr
|
|
|
|
|
# aro_path = r"C:/Users/user/Documents/Aeros/sample_project.aro"
|
|
|
|
|
|
|
|
|
|
aeros_project = AerosProject(project_name=project_name, aro_file_path=aro_path)
|
|
|
|
|
db_session.add(aeros_project)
|
|
|
|
|
|
|
|
|
|
# find aeros record first, if not found, then create a new one
|
|
|
|
|
stmt = select(AerosProject).order_by(desc(AerosProject.created_at)).limit(1)
|
|
|
|
|
result = await db_session.execute(stmt)
|
|
|
|
|
latest_project = result.scalar_one_or_none()
|
|
|
|
|
|
|
|
|
|
# If aeros record found, then update it
|
|
|
|
|
if latest_project:
|
|
|
|
|
latest_project.project_name = project_name
|
|
|
|
|
latest_project.aro_file_path = aro_path
|
|
|
|
|
else: # else create new aeros record
|
|
|
|
|
db_session.add(aeros_project)
|
|
|
|
|
|
|
|
|
|
await db_session.commit()
|
|
|
|
|
|
|
|
|
|
# Update path to AEROS APP
|
|
|
|
|
|