Skip to content

Commit

Permalink
feat: remove rio-tiler package & update author_id in project details…
Browse files Browse the repository at this point in the history
… endpoint (#337)

* feat: add reprojection of orthophoto to EPSG:3857 before uploading to S3

* docs: added docs string on image processing function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* feat: added try-except to handle/track the error

* feat: remove rio tiler package & update authord_id in project details endpoint

* feat: update author_id in project lists

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Pradip-p and pre-commit-ci[bot] authored Nov 18, 2024
1 parent 36e006b commit 64a9775
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 448 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)}")
4 changes: 3 additions & 1 deletion 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 @@ -337,7 +338,7 @@ async def all(
await cur.execute(
"""
SELECT
p.id, p.slug, p.name, p.description, p.per_task_instructions, p.created_at,
p.id, p.slug, p.name, p.description, p.per_task_instructions, p.created_at, p.author_id,
ST_AsGeoJSON(p.outline)::jsonb AS outline,
p.requires_approval_from_manager_for_locking,
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 64a9775

Please sign in to comment.