1- from fastapi import FastAPI , HTTPException , Header , UploadFile , File , Request
1+ from fastapi import FastAPI , HTTPException , Header , Request
22from pydantic import BaseModel
33from typing import Optional , List , Dict
44import uuid
@@ -22,6 +22,11 @@ class ArtifactPrepareResponse(BaseModel):
2222class ExternalWorkerResponse (BaseModel ):
2323 state : str
2424
25+ class AirdropArtifactResponse (BaseModel ):
26+ artifact_id : str
27+ upload_url : str
28+ form_data : List [FormDataField ]
29+
2530@app .post ("/upload/{artifact_id}" )
2631async def upload_artifact (
2732 artifact_id : str ,
@@ -102,6 +107,36 @@ async def get_snap_ins(request: Request):
102107 print ("Received /internal/snap-ins.get GET request" )
103108 return {"status" : "success" }
104109
110+ @app .get ("/internal/airdrop.artifacts.upload-url" , response_model = AirdropArtifactResponse )
111+ async def airdrop_artifacts_upload_url (
112+ file_type : str ,
113+ file_name : str ,
114+ request_id : Optional [str ] = None ,
115+ authorization : Optional [str ] = Header (None )
116+ ):
117+ # Generate a unique artifact ID
118+ artifact_id = str (uuid .uuid4 ())
119+
120+ # Create a mock S3-like URL for the upload
121+ upload_url = f"http://localhost:8003/upload/{ artifact_id } "
122+
123+ # Create form data fields that would typically be required for S3 upload
124+ form_data = [
125+ FormDataField (key = "key" , value = f"airdrop-artifacts/{ artifact_id } /{ file_name } " ),
126+ FormDataField (key = "Content-Type" , value = file_type ),
127+ FormDataField (key = "x-amz-meta-artifact-id" , value = artifact_id ),
128+ ]
129+
130+ # Add request_id to form data if provided
131+ if request_id :
132+ form_data .append (FormDataField (key = "x-amz-meta-request-id" , value = request_id ))
133+
134+ return AirdropArtifactResponse (
135+ artifact_id = artifact_id ,
136+ upload_url = upload_url ,
137+ form_data = form_data
138+ )
139+
105140if __name__ == "__main__" :
106141 import uvicorn
107142 uvicorn .run (app , host = "localhost" , port = 8003 )
0 commit comments