From fb388a3369116c9c068877002ff99377a218a002 Mon Sep 17 00:00:00 2001 From: "spaceBearAmadeus (Alex)" Date: Thu, 15 Aug 2024 22:37:27 -0400 Subject: [PATCH] update for shared prefix --- compose_api/main.py | 16 +++------------- compose_api/shared.py | 7 +++++++ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/compose_api/main.py b/compose_api/main.py index 6d0addd47..6ba1e6e73 100644 --- a/compose_api/main.py +++ b/compose_api/main.py @@ -17,7 +17,7 @@ from compatible import COMPATIBLE_VERIFICATION_SIMULATORS # from bio_check import MONGO_URI from data_model import DbClientResponse, UtcComparisonResult, PendingSmoldynJob, CompatibleSimulators, Simulator, PendingUtcJob, OutputData, PendingSimulariumJob, CompositionSpecification, PendingSbmlVerificationJob, PendingOmexVerificationJob, PendingCompositionJob -from shared import upload_blob, MongoDbConnector, DB_NAME, DB_TYPE, BUCKET_NAME, JobStatus, DatabaseCollections +from shared import upload_blob, MongoDbConnector, DB_NAME, DB_TYPE, BUCKET_NAME, JobStatus, DatabaseCollections, file_upload_prefix from io_api import write_uploaded_file, save_uploaded_file, check_upload_file_extension, download_file_from_bucket from log_config import setup_logging @@ -211,13 +211,8 @@ async def verify_omex( job_id = "verification-" + compare_id + "-" + str(uuid.uuid4()) _time = db_connector.timestamp() - - # bucket params - upload_prefix = f"uploads/{job_id}/" - bucket_prefix = f"gs://{BUCKET_NAME}/" + upload_prefix - + upload_prefix, bucket_prefix = file_upload_prefix(job_id) save_dest = mkdtemp() - fp = await save_uploaded_file(uploaded_file, save_dest) # save uploaded file to ephemeral store # Save uploaded omex file to Google Cloud Storage @@ -293,13 +288,8 @@ async def verify_sbml( job_id = "verification-" + compare_id + "-" + str(uuid.uuid4()) _time = db_connector.timestamp() - - # bucket params - upload_prefix = f"uploads/{job_id}/" - bucket_prefix = f"gs://{BUCKET_NAME}/" + upload_prefix - + upload_prefix, bucket_prefix = file_upload_prefix(job_id) save_dest = mkdtemp() - fp = await save_uploaded_file(uploaded_file, save_dest) # save uploaded file to ephemeral store # Save uploaded omex file to Google Cloud Storage diff --git a/compose_api/shared.py b/compose_api/shared.py index 49faa1d87..1182557af 100644 --- a/compose_api/shared.py +++ b/compose_api/shared.py @@ -25,6 +25,13 @@ BUCKET_NAME = os.getenv("BUCKET_NAME") +def file_upload_prefix(job_id: str): + # bucket params + upload_prefix = f"file_uploads/{job_id}/" + bucket_prefix = f"gs://{BUCKET_NAME}/" + upload_prefix + return upload_prefix, bucket_prefix + + def check_upload_file_extension(file: UploadFile, purpose: str, ext: str) -> bool: if not file.filename.endswith(ext): raise ValueError(f"Files for {purpose} must be passed in {ext} format.")