Skip to content

Commit

Permalink
Add tiles_info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dmannarino committed May 22, 2024
1 parent 417f885 commit c03eb88
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions app/routes/assets/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

# from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Path, status
from fastapi.responses import ORJSONResponse
from starlette.responses import JSONResponse
from starlette.responses import JSONResponse, RedirectResponse

from app.models.pydantic.responses import Response
from app.settings.globals import API_URL
from ..datasets.downloads import _get_presigned_url

from ...authentication.token import is_admin
from ...crud import assets
from ...crud import metadata as metadata_crud
from ...crud import tasks
Expand Down Expand Up @@ -67,7 +67,7 @@
delete_static_vector_tile_cache_assets,
)
from ...utils.paginate import paginate_collection
from ...utils.path import infer_srid_from_grid
from ...utils.path import infer_srid_from_grid, split_s3_path
from ..assets import asset_response
from ..tasks import paginated_tasks_response, tasks_response

Expand Down Expand Up @@ -310,6 +310,28 @@ async def get_extent(asset_id: UUID = Path(...)):
return ExtentResponse(data=extent)


@router.get(
"/{asset_id}/tiles_info",
response_class=RedirectResponse,
tags=["Assets"],
status_code=307,
)
async def get_tiles_info(asset_id: UUID = Path(...)):
asset: ORMAsset = await assets.get_asset(asset_id)

if asset.asset_type != AssetType.raster_tile_set:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Tiles information only available for raster tile sets"
)

bucket, asset_key = split_s3_path(asset.asset_uri)
tiles_geojson_key = asset_key.replace("{tile_id}.tif", "tiles.geojson")
presigned_url = await _get_presigned_url(bucket, tiles_geojson_key)

return RedirectResponse(url=presigned_url)


@router.get(
"/{asset_id}/stats",
response_class=ORJSONResponse,
Expand Down

0 comments on commit c03eb88

Please sign in to comment.