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
55import json
6+ import random
67
78app = FastAPI ()
89
@@ -22,6 +23,11 @@ class ArtifactPrepareResponse(BaseModel):
2223class ExternalWorkerResponse (BaseModel ):
2324 state : str
2425
26+ class AirdropArtifactResponse (BaseModel ):
27+ artifact_id : str
28+ upload_url : str
29+ form_data : List [FormDataField ]
30+
2531@app .post ("/upload/{artifact_id}" )
2632async def upload_artifact (
2733 artifact_id : str ,
@@ -102,6 +108,35 @@ async def get_snap_ins(request: Request):
102108 print ("Received /internal/snap-ins.get GET request" )
103109 return {"status" : "success" }
104110
111+ @app .get ("/internal/airdrop.artifacts.upload-url" , response_model = AirdropArtifactResponse )
112+ async def airdrop_artifacts_upload_url (
113+ file_type : str ,
114+ file_name : str ,
115+ request_id : Optional [str ] = None ,
116+ authorization : Optional [str ] = Header (None )
117+ ):
118+ # Generate a unique artifact ID in the required format
119+ partition = "dvrv-us-1"
120+ devOrgID = "1"
121+ random_int = random .randint (1 , 1000 )
122+ artifact_id = f"don:core:{ partition } :devo/{ devOrgID } :artifact/{ random_int } "
123+
124+ # Create a mock S3-like URL for the upload
125+ upload_url = f"http://localhost:8003/upload/{ artifact_id } "
126+
127+ # Create form data fields that would typically be required for S3 upload
128+ form_data = [
129+ FormDataField (key = "key" , value = f"airdrop-artifacts/{ artifact_id } /{ file_name } " ),
130+ FormDataField (key = "Content-Type" , value = file_type ),
131+ FormDataField (key = "x-amz-meta-artifact-id" , value = artifact_id ),
132+ ]
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