Spaces:
Sleeping
Sleeping
Seth
commited on
Commit
·
ebd72bb
1
Parent(s):
aabbd76
update
Browse files- backend/app/main.py +22 -4
- backend/app/models.py +2 -2
backend/app/main.py
CHANGED
|
@@ -247,11 +247,29 @@ FRONTEND_DIST = Path("/app/frontend/dist")
|
|
| 247 |
INDEX_FILE = FRONTEND_DIST / "index.html"
|
| 248 |
|
| 249 |
if FRONTEND_DIST.exists():
|
| 250 |
-
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
# SPA fallback: any non-/api route should return React index.html
|
|
|
|
| 253 |
@app.get("/{full_path:path}")
|
| 254 |
-
def spa_fallback(full_path: str):
|
|
|
|
| 255 |
if full_path.startswith("api/"):
|
| 256 |
return {"detail": "Not Found"}
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
INDEX_FILE = FRONTEND_DIST / "index.html"
|
| 248 |
|
| 249 |
if FRONTEND_DIST.exists():
|
| 250 |
+
# Serve static assets (JS, CSS, images, etc.) from /assets
|
| 251 |
+
assets_dir = FRONTEND_DIST / "assets"
|
| 252 |
+
if assets_dir.exists():
|
| 253 |
+
app.mount("/assets", StaticFiles(directory=str(assets_dir)), name="assets")
|
| 254 |
+
|
| 255 |
+
# Serve index.html for root
|
| 256 |
+
@app.get("/")
|
| 257 |
+
async def serve_index():
|
| 258 |
+
if INDEX_FILE.exists():
|
| 259 |
+
return FileResponse(str(INDEX_FILE))
|
| 260 |
+
return {"detail": "Frontend not found"}
|
| 261 |
+
|
| 262 |
# SPA fallback: any non-/api route should return React index.html
|
| 263 |
+
# This must be last to catch all routes not handled above
|
| 264 |
@app.get("/{full_path:path}")
|
| 265 |
+
async def spa_fallback(full_path: str):
|
| 266 |
+
# Don't handle API routes here
|
| 267 |
if full_path.startswith("api/"):
|
| 268 |
return {"detail": "Not Found"}
|
| 269 |
+
# Don't handle assets (already mounted)
|
| 270 |
+
if full_path.startswith("assets/"):
|
| 271 |
+
return {"detail": "Not Found"}
|
| 272 |
+
# Serve index.html for all other routes (SPA routing)
|
| 273 |
+
if INDEX_FILE.exists():
|
| 274 |
+
return FileResponse(str(INDEX_FILE))
|
| 275 |
+
return {"detail": "Frontend not found"}
|
backend/app/models.py
CHANGED
|
@@ -42,7 +42,7 @@ class Asset(Base):
|
|
| 42 |
product_category = Column(String) # 'ocr', 'p2p', 'o2c'
|
| 43 |
sub_category = Column(String, nullable=True)
|
| 44 |
size = Column(Integer) # in bytes
|
| 45 |
-
|
| 46 |
created_at = Column(DateTime, default=datetime.utcnow)
|
| 47 |
|
| 48 |
user = relationship("User", back_populates="assets")
|
|
@@ -61,7 +61,7 @@ class Post(Base):
|
|
| 61 |
linkedin_post_id = Column(String, nullable=True)
|
| 62 |
canva_design_id = Column(String, nullable=True)
|
| 63 |
assets = Column(JSON) # List of asset IDs
|
| 64 |
-
|
| 65 |
created_at = Column(DateTime, default=datetime.utcnow)
|
| 66 |
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
| 67 |
|
|
|
|
| 42 |
product_category = Column(String) # 'ocr', 'p2p', 'o2c'
|
| 43 |
sub_category = Column(String, nullable=True)
|
| 44 |
size = Column(Integer) # in bytes
|
| 45 |
+
extra_metadata = Column(JSON, nullable=True) # Renamed from 'metadata' to avoid SQLAlchemy conflict
|
| 46 |
created_at = Column(DateTime, default=datetime.utcnow)
|
| 47 |
|
| 48 |
user = relationship("User", back_populates="assets")
|
|
|
|
| 61 |
linkedin_post_id = Column(String, nullable=True)
|
| 62 |
canva_design_id = Column(String, nullable=True)
|
| 63 |
assets = Column(JSON) # List of asset IDs
|
| 64 |
+
extra_metadata = Column(JSON, nullable=True) # Renamed from 'metadata' to avoid SQLAlchemy conflict
|
| 65 |
created_at = Column(DateTime, default=datetime.utcnow)
|
| 66 |
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
| 67 |
|