WIP checkpoint: US-1: Asset Import Pipeline — glTF upload endpoint with metadata extraction
This commit is contained in:
@@ -3,6 +3,8 @@ from sqlalchemy.dialects.postgresql import ENUM
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
import enum
|
||||
import json
|
||||
from typing import Optional, List
|
||||
|
||||
from app.database import Base
|
||||
|
||||
@@ -38,3 +40,31 @@ class Asset(Base):
|
||||
|
||||
owner = relationship("User", back_populates="assets")
|
||||
world = relationship("World", back_populates="assets")
|
||||
|
||||
|
||||
class GLTFMetadata(BaseModel):
|
||||
"""Pydantic schema for glTF asset metadata."""
|
||||
mesh_count: Optional[int] = None
|
||||
vertex_count: Optional[int] = None
|
||||
has_animation: bool = False
|
||||
texture_refs: Optional[List[str]] = None
|
||||
tags: Optional[List[str]] = None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
def parse_metadata_json(metadata_text: Optional[str]) -> dict:
|
||||
"""Parse the metadata_json text field into a dict, handling None gracefully."""
|
||||
if not metadata_text:
|
||||
return {}
|
||||
try:
|
||||
return json.loads(metadata_text)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
return {}
|
||||
|
||||
|
||||
def serialize_metadata(metadata: dict) -> Optional[str]:
|
||||
"""Serialize metadata dict to JSON string for storage."""
|
||||
if not metadata:
|
||||
return None
|
||||
return json.dumps(metadata)
|
||||
|
||||
Reference in New Issue
Block a user