1
- from fastapi import FastAPI , HTTPException , Header , UploadFile , File , Request
1
+ from fastapi import FastAPI , HTTPException , Header , Request
2
2
from pydantic import BaseModel
3
3
from typing import Optional , List , Dict
4
4
import uuid
5
5
import json
6
+ import random
6
7
7
8
app = FastAPI ()
8
9
@@ -22,6 +23,11 @@ class ArtifactPrepareResponse(BaseModel):
22
23
class ExternalWorkerResponse (BaseModel ):
23
24
state : str
24
25
26
+ class AirdropArtifactResponse (BaseModel ):
27
+ artifact_id : str
28
+ upload_url : str
29
+ form_data : List [FormDataField ]
30
+
25
31
@app .post ("/upload/{artifact_id}" )
26
32
async def upload_artifact (
27
33
artifact_id : str ,
@@ -102,6 +108,35 @@ async def get_snap_ins(request: Request):
102
108
print ("Received /internal/snap-ins.get GET request" )
103
109
return {"status" : "success" }
104
110
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
+
105
140
if __name__ == "__main__" :
106
141
import uvicorn
107
142
uvicorn .run (app , host = "localhost" , port = 8003 )
0 commit comments