feat: implement image uploading to landing page

This commit is contained in:
swve 2025-03-02 22:23:14 +01:00
parent d7b6e8282b
commit 3ce7dfdcd2
7 changed files with 244 additions and 37 deletions

View file

@ -41,6 +41,7 @@ from src.services.orgs.orgs import (
update_org_signup_mechanism,
update_org_thumbnail,
update_org_landing,
upload_org_landing_content_service,
)
@ -428,3 +429,23 @@ async def api_update_org_landing(
Update organization landing object
"""
return await update_org_landing(request, landing_object, org_id, current_user, db_session)
@router.post("/{org_id}/landing/content")
async def api_upload_org_landing_content(
request: Request,
org_id: int,
content_file: UploadFile,
current_user: PublicUser = Depends(get_current_user),
db_session: Session = Depends(get_db_session),
):
"""
Upload content for organization landing page
"""
return await upload_org_landing_content_service(
request=request,
content_file=content_file,
org_id=org_id,
current_user=current_user,
db_session=db_session,
)

View file

@ -36,7 +36,7 @@ from src.db.organizations import (
)
from fastapi import HTTPException, UploadFile, status, Request
from src.services.orgs.uploads import upload_org_logo, upload_org_preview, upload_org_thumbnail
from src.services.orgs.uploads import upload_org_logo, upload_org_preview, upload_org_thumbnail, upload_org_landing_content
async def get_organization(
@ -765,6 +765,35 @@ async def update_org_landing(
return {"detail": "Landing object updated"}
async def upload_org_landing_content_service(
request: Request,
content_file: UploadFile,
org_id: int,
current_user: PublicUser | AnonymousUser,
db_session: Session,
) -> dict:
statement = select(Organization).where(Organization.id == org_id)
result = db_session.exec(statement)
org = result.first()
if not org:
raise HTTPException(
status_code=404,
detail="Organization not found",
)
# RBAC check
await rbac_check(request, org.org_uuid, current_user, "update", db_session)
# Upload content
name_in_disk = await upload_org_landing_content(content_file, org.org_uuid)
return {
"detail": "Landing content uploaded successfully",
"filename": name_in_disk
}
## 🔒 RBAC Utils ##

View file

@ -1,4 +1,6 @@
from uuid import uuid4
from fastapi import UploadFile
from fastapi import HTTPException
from src.services.utils.upload_content import upload_content
@ -45,4 +47,23 @@ async def upload_org_preview(file, org_uuid: str) -> str:
name_in_disk,
)
return name_in_disk
async def upload_org_landing_content(file: UploadFile, org_uuid: str) -> str:
if not file or not file.filename:
raise HTTPException(status_code=400, detail="No file provided or invalid filename")
contents = file.file.read()
name_in_disk = f"{uuid4()}.{file.filename.split('.')[-1]}"
await upload_content(
"landing",
"orgs",
org_uuid,
contents,
name_in_disk,
["jpg", "jpeg", "png", "gif", "webp", "mp4", "webm", "pdf"] # Common web content formats
)
return name_in_disk