From 4392809e81874c29e7dbe29e13238ffa41796c46 Mon Sep 17 00:00:00 2001 From: Cizz22 Date: Fri, 20 Feb 2026 12:24:26 +0700 Subject: [PATCH] refactor: Centralize Aeros file upload logic into a new utility function, update `licaeros` dependency to 0.1.2, and add `__init__.py`. --- __init__.py | 0 poetry.lock | 15 ++++++--------- pyproject.toml | 2 +- src/aeros_project/service.py | 27 +++++++++++++++++---------- src/aeros_utils.py | 8 ++++++++ 5 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/poetry.lock b/poetry.lock index 12108d7..6f00199 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1312,20 +1312,17 @@ i18n = ["Babel (>=2.7)"] [[package]] name = "licaeros" -version = "0.1.0" -description = "" +version = "0.1.2" +description = "License App for Aeros" optional = false python-versions = "*" groups = ["main"] files = [ - {file = "licaeros-0.1.0-cp310-cp310-linux_x86_64.whl", hash = "sha256:7ab820555c10edae6d8f391e71f0188463283ddbf60840a3baadb926bb78a6a9"}, - {file = "licaeros-0.1.0-cp311-cp311-linux_x86_64.whl", hash = "sha256:70b6b753c96e6fa4912e0e9eddf8088ddc3c4b6947ca16dc4b19047d2ee4aedf"}, - {file = "licaeros-0.1.0-cp312-cp312-linux_x86_64.whl", hash = "sha256:d89fe52a78637f2a72abf64f6a74445aad3899303cce7409f2d12fd277a0db00"}, + {file = "licaeros-0.1.2-cp310-cp310-linux_x86_64.whl", hash = "sha256:4b9bfe2e7ba8ab9edb5db18dcb415476e7ab302e09d72b74b5bfd1ac8938b10c"}, + {file = "licaeros-0.1.2-cp311-cp311-linux_x86_64.whl", hash = "sha256:4f3a2251aebe7351e61d6f80d6c7474387f9561fdcfff02103b78bb2168c9791"}, + {file = "licaeros-0.1.2-cp312-cp312-linux_x86_64.whl", hash = "sha256:933c24029aec984ccc39baf630fbee10e07c1e28192c499685bec0a11d31321d"}, ] -[package.dependencies] -requests = "*" - [package.source] type = "legacy" url = "https://git.reliabilityindonesia.com/api/packages/DigitalTwin/pypi/simple" @@ -3596,4 +3593,4 @@ propcache = ">=0.2.1" [metadata] lock-version = "2.1" python-versions = "^3.11" -content-hash = "f75002a661bdae021c2906c1b44ba85cfe1835d37378a717ee9561e376603771" +content-hash = "c97aecfef075bcbd7a40d9c98ae79c30d6253bc2c9f14ef187b1a098ace42088" diff --git a/pyproject.toml b/pyproject.toml index d36b34f..0b32950 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ aiohttp = "^3.12.14" ijson = "^3.4.0" redis = "^7.1.0" clamd = "^1.0.2" -licaeros = "^0.1.0" +licaeros = "^0.1.2" [[tool.poetry.source]] diff --git a/src/aeros_project/service.py b/src/aeros_project/service.py index ffbb42c..b2eaf52 100644 --- a/src/aeros_project/service.py +++ b/src/aeros_project/service.py @@ -99,8 +99,6 @@ async def import_aro_project(*, db_session: DbSession, aeros_project_in: AerosPr ) - return clean_filename - # Project name hardcode # project_name = "trialapi" @@ -116,17 +114,26 @@ async def import_aro_project(*, db_session: DbSession, aeros_project_in: AerosPr # await file.seek(0) # Prepare file for upload - files = { - "file": (clean_filename, content, file.content_type or "application/octet-stream") - } - - print("fetch") - response = await client.post( - f"{WINDOWS_AEROS_BASE_URL}/upload-file", - files=files + # files = { + # "file": (clean_filename, content, file.content_type or "application/octet-stream") + # } + + response = await aeros_file_upload( + "/api/upload", + file, + "file", + clean_filename ) + response.raise_for_status() + # print("fetch") + # response = await client.post( + # f"{WINDOWS_AEROS_BASE_URL}/upload-file", + # files=files + # ) + # response.raise_for_status() + # Get the file path from the response upload_result = response.json() aro_path = upload_result.get("full_path") diff --git a/src/aeros_utils.py b/src/aeros_utils.py index 01800c0..f361407 100644 --- a/src/aeros_utils.py +++ b/src/aeros_utils.py @@ -30,3 +30,11 @@ async def aeros_post(path: str, json: dict = None, **kwargs): lambda: session.post(path, json) ) return response + + +async def aeros_file_upload(path, file, field_name, filename): + session = get_aeros_session() + response = await anyio.to_thread.run_sync( + lambda: session.post_multipart(path, file, field_name, filename) + ) + return response \ No newline at end of file