Spaces:
Runtime error
Runtime error
Greg Claude Sonnet 4.6 commited on
Commit ·
ccb2eb5
1
Parent(s): d116d3f
feat(ta-01): GET /photos endpoint for local storage backend
Browse filesCo-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
backend/app/api/v1/endpoints/photos.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from fastapi import APIRouter, Depends, HTTPException
|
| 4 |
+
from fastapi.responses import FileResponse
|
| 5 |
+
from app.dependencies.auth import get_current_user
|
| 6 |
+
from app.models.user import User
|
| 7 |
+
|
| 8 |
+
router = APIRouter(prefix="/photos", tags=["photos"])
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@router.get("/{account_id}/{user_id}/{filename}")
|
| 12 |
+
def serve_photo(
|
| 13 |
+
account_id: int,
|
| 14 |
+
user_id: int,
|
| 15 |
+
filename: str,
|
| 16 |
+
current_user: User = Depends(get_current_user),
|
| 17 |
+
):
|
| 18 |
+
if os.getenv("PHOTO_STORAGE_BACKEND", "local").lower() != "local":
|
| 19 |
+
raise HTTPException(status_code=404, detail="not served locally")
|
| 20 |
+
if current_user.account_id != account_id:
|
| 21 |
+
raise HTTPException(status_code=404, detail="not found")
|
| 22 |
+
root = Path(os.getenv("LOCAL_PHOTO_ROOT", "/data/photos"))
|
| 23 |
+
target = root / str(account_id) / str(user_id) / filename
|
| 24 |
+
if not target.exists():
|
| 25 |
+
raise HTTPException(status_code=404, detail="not found")
|
| 26 |
+
return FileResponse(target, media_type="image/webp")
|
backend/app/api/v1/router.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from fastapi import APIRouter
|
| 2 |
|
| 3 |
-
from app.api.v1.endpoints import auth, users, subjects, sections, teacher_sections, enrollments, attendances, dashboard, facial, settings, teacher, section_subjects, teacher_subjects, permissions, developer, card_templates, representative, audit_logs, reports, holidays
|
| 4 |
|
| 5 |
router = APIRouter(prefix="/api/v1")
|
| 6 |
router.include_router(auth.router)
|
|
@@ -23,3 +23,4 @@ router.include_router(representative.router)
|
|
| 23 |
router.include_router(audit_logs.router)
|
| 24 |
router.include_router(reports.router)
|
| 25 |
router.include_router(holidays.router)
|
|
|
|
|
|
| 1 |
from fastapi import APIRouter
|
| 2 |
|
| 3 |
+
from app.api.v1.endpoints import auth, users, subjects, sections, teacher_sections, enrollments, attendances, dashboard, facial, settings, teacher, section_subjects, teacher_subjects, permissions, developer, card_templates, representative, audit_logs, reports, holidays, photos
|
| 4 |
|
| 5 |
router = APIRouter(prefix="/api/v1")
|
| 6 |
router.include_router(auth.router)
|
|
|
|
| 23 |
router.include_router(audit_logs.router)
|
| 24 |
router.include_router(reports.router)
|
| 25 |
router.include_router(holidays.router)
|
| 26 |
+
router.include_router(photos.router)
|