Skip to content

Commit

Permalink
feat: remove rio tiler package & update authord_id in project details…
Browse files Browse the repository at this point in the history
… endpoint
  • Loading branch information
Pradip-p committed Nov 18, 2024
1 parent 2da56b1 commit be69566
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 447 deletions.
34 changes: 1 addition & 33 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@
from app.projects import project_schemas, project_deps, project_logic, image_processing
from app.db import database
from app.models.enums import HTTPStatus, State
from app.s3 import get_cog_path, s3_client
from app.s3 import s3_client
from app.config import settings
from app.users.user_deps import login_required
from app.users.user_schemas import AuthUser
from app.tasks import task_schemas
from app.utils import geojson_to_kml, timestamp
from app.users import user_schemas
from rio_tiler.errors import TileOutsideBounds
from minio.deleteobjects import DeleteObject
import asyncio


router = APIRouter(
Expand Down Expand Up @@ -584,33 +582,3 @@ async def odm_webhook(
log.info(f"Task ID: {task_id}, Status: Webhook received")

return {"message": "Webhook received", "task_id": task_id}


@router.get(
"/orthophoto/{z}/{x}/{y}.png",
tags=["Image Processing"],
)
async def get_orthophoto_tile(
project_id: str,
task_id: str,
z: int,
x: int,
y: int,
):
"""
Endpoint to serve COG tiles as PNG images with safer and more efficient handling.
"""
cog_path = get_cog_path(settings.S3_BUCKET_NAME, project_id, task_id)

try:
# Use asyncio.to_thread to move blocking raster file I/O to a separate thread
tile = await asyncio.to_thread(
project_logic.read_tile_from_cog, cog_path, x, y, z
)
return Response(content=tile, media_type="image/png")

except TileOutsideBounds:
# Return a 204 No Content if tile is outside the bounds
return Response(status_code=204, content="")
except Exception as e:
raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}")
2 changes: 2 additions & 0 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class DbProject(BaseModel):
is_terrain_follow: bool = False
image_url: Optional[str] = None
created_at: datetime
author_id: str

async def one(db: Connection, project_id: uuid.UUID):
"""Get a single project & all associated tasks by ID."""
Expand Down Expand Up @@ -536,6 +537,7 @@ class ProjectInfo(BaseModel):
completed_task_count: Optional[int] = 0
status: Optional[str] = "not-started"
created_at: datetime
author_id: str

@model_validator(mode="after")
def set_image_url(cls, values):
Expand Down
Loading

0 comments on commit be69566

Please sign in to comment.