|
|
@@ -3,6 +3,10 @@ from sqlalchemy.dialects.postgresql import ENUM
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from sqlalchemy.sql import func
|
|
|
|
from sqlalchemy.sql import func
|
|
|
|
import enum
|
|
|
|
import enum
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
from typing import Optional, List
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel as PydanticBaseModel
|
|
|
|
|
|
|
|
|
|
|
|
from app.database import Base
|
|
|
|
from app.database import Base
|
|
|
|
|
|
|
|
|
|
|
@@ -38,3 +42,31 @@ class Asset(Base):
|
|
|
|
|
|
|
|
|
|
|
|
owner = relationship("User", back_populates="assets")
|
|
|
|
owner = relationship("User", back_populates="assets")
|
|
|
|
world = relationship("World", back_populates="assets")
|
|
|
|
world = relationship("World", back_populates="assets")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GLTFMetadata(PydanticBaseModel):
|
|
|
|
|
|
|
|
"""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)
|
|
|
|