Skip to content

Commit

Permalink
Merge pull request #531 from wri/add_tiles_info_to_master
Browse files Browse the repository at this point in the history
Add tiles_info endpoint
  • Loading branch information
dmannarino authored May 28, 2024
2 parents 967f5f7 + 8cf1213 commit 09fc8ab
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 09fc8ab

Please sign in to comment.