1818from minio import Minio
1919from sqlalchemy import text
2020from starlette .datastructures import UploadFile as StarletteUploadFile
21+
2122from macrostrat .core import app as app_
2223
2324router = APIRouter (
2829
2930settings = app_ .settings
3031
32+
3133def guess_mime_type (filename : str ) -> str :
3234 mime , _ = mimetypes .guess_type (filename )
3335 return mime or "application/octet-stream"
@@ -50,6 +52,7 @@ def sha256_of_uploadfile(
5052 upload .file .seek (0 )
5153 return h .hexdigest ()
5254
55+
5356def get_s3_client ():
5457 # TODO need to add or configure these envs within api v3 kubernetes config
5558 return Minio (
@@ -59,6 +62,7 @@ def get_s3_client():
5962 secure = True ,
6063 )
6164
65+
6266def get_storage_host_bucket () -> tuple [str , str ]:
6367 """
6468 Keep host/bucket consistent everywhere.
@@ -192,7 +196,6 @@ async def list_objects(
192196 return {"items" : items , "next_before_id" : next_before_id }
193197
194198
195-
196199@router .get ("/{id}" )
197200async def get_object (id : int ):
198201 engine = get_engine ()
@@ -407,6 +410,7 @@ async def delete_object(
407410 await session .commit ()
408411 return {"status" : "deleted" , "hard" : False , "object" : _row_to_dict (row2 )}
409412
413+
410414@router .post ("/{id}/track" )
411415async def track_object (id : int ):
412416 """
@@ -422,10 +426,10 @@ async def forget_object(id: int):
422426 """
423427 raise HTTPException (status_code = 501 , detail = "Forget not implemented yet" )
424428
429+
425430@router .get ("/{id}/url" )
426431async def get_object_url (id : int ):
427432 """
428433 TODO: Return or redirect to signed S3 URL.
429434 """
430435 raise HTTPException (status_code = 501 , detail = "URL helper not implemented yet" )
431-
0 commit comments