Spaces:
Paused
Paused
deploy attempt fix
Browse files- routers/user_models.py +46 -2
routers/user_models.py
CHANGED
|
@@ -1016,27 +1016,34 @@ async def view_model_file(
|
|
| 1016 |
Serve the 3D model file inline for frontend 3D viewers.
|
| 1017 |
This endpoint serves the file with appropriate headers for direct consumption by 3D libraries.
|
| 1018 |
"""
|
| 1019 |
-
print("view_model_file")
|
| 1020 |
try:
|
| 1021 |
# Handle placeholder IDs and validate integer format
|
| 1022 |
if generated_model_id.startswith("placeholder_"):
|
|
|
|
| 1023 |
raise HTTPException(status_code=400, detail="Invalid model ID. Model may not be ready yet or generation is still initializing.")
|
| 1024 |
|
| 1025 |
try:
|
| 1026 |
model_id_int = int(generated_model_id)
|
| 1027 |
except ValueError:
|
|
|
|
| 1028 |
raise HTTPException(status_code=400, detail="Invalid model ID format. Expected numeric ID.")
|
| 1029 |
|
|
|
|
|
|
|
| 1030 |
# First check if the model exists (removed user ownership check for public access)
|
| 1031 |
-
model_check = supabase.from_("Generated_Models").select("generated_model_id, user_id, model_name").eq("generated_model_id", model_id_int).limit(1).execute() # .eq("user_id", current_user.id) - commented out for public access
|
| 1032 |
|
| 1033 |
if not model_check.data:
|
|
|
|
| 1034 |
raise HTTPException(status_code=404, detail="Model not found.")
|
| 1035 |
|
|
|
|
|
|
|
| 1036 |
# Get the model file (removed ownership verification for public access)
|
| 1037 |
file_result = supabase.from_("Model_Files").select("*").eq("generated_model_id", model_id_int).limit(1).execute() # .eq("user_id", current_user.id) - commented out for public access
|
| 1038 |
|
| 1039 |
if not file_result.data:
|
|
|
|
| 1040 |
raise HTTPException(status_code=404, detail="No model file found for this generated model.")
|
| 1041 |
|
| 1042 |
file_data = file_result.data[0]
|
|
@@ -1156,6 +1163,43 @@ async def get_model_thumbnail(generated_model_id: str):
|
|
| 1156 |
logging.error(f"Failed to serve thumbnail for {generated_model_id}: {str(e)}")
|
| 1157 |
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
| 1158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1159 |
@router.delete("/{generated_model_id}", dependencies=[Depends(get_current_active_user)])
|
| 1160 |
async def delete_model(
|
| 1161 |
generated_model_id: str,
|
|
|
|
| 1016 |
Serve the 3D model file inline for frontend 3D viewers.
|
| 1017 |
This endpoint serves the file with appropriate headers for direct consumption by 3D libraries.
|
| 1018 |
"""
|
|
|
|
| 1019 |
try:
|
| 1020 |
# Handle placeholder IDs and validate integer format
|
| 1021 |
if generated_model_id.startswith("placeholder_"):
|
| 1022 |
+
logging.warning(f"Placeholder ID received: {generated_model_id}")
|
| 1023 |
raise HTTPException(status_code=400, detail="Invalid model ID. Model may not be ready yet or generation is still initializing.")
|
| 1024 |
|
| 1025 |
try:
|
| 1026 |
model_id_int = int(generated_model_id)
|
| 1027 |
except ValueError:
|
| 1028 |
+
logging.error(f"Invalid model ID format: {generated_model_id}")
|
| 1029 |
raise HTTPException(status_code=400, detail="Invalid model ID format. Expected numeric ID.")
|
| 1030 |
|
| 1031 |
+
logging.info(f"Looking up model {model_id_int} for view endpoint")
|
| 1032 |
+
|
| 1033 |
# First check if the model exists (removed user ownership check for public access)
|
| 1034 |
+
model_check = supabase.from_("Generated_Models").select("generated_model_id, user_id, model_name, status").eq("generated_model_id", model_id_int).limit(1).execute() # .eq("user_id", current_user.id) - commented out for public access
|
| 1035 |
|
| 1036 |
if not model_check.data:
|
| 1037 |
+
logging.error(f"Model {model_id_int} not found in Generated_Models table")
|
| 1038 |
raise HTTPException(status_code=404, detail="Model not found.")
|
| 1039 |
|
| 1040 |
+
logging.info(f"Found model {model_id_int}: {model_check.data[0]}")
|
| 1041 |
+
|
| 1042 |
# Get the model file (removed ownership verification for public access)
|
| 1043 |
file_result = supabase.from_("Model_Files").select("*").eq("generated_model_id", model_id_int).limit(1).execute() # .eq("user_id", current_user.id) - commented out for public access
|
| 1044 |
|
| 1045 |
if not file_result.data:
|
| 1046 |
+
logging.error(f"No model file found for model {model_id_int} in Model_Files table")
|
| 1047 |
raise HTTPException(status_code=404, detail="No model file found for this generated model.")
|
| 1048 |
|
| 1049 |
file_data = file_result.data[0]
|
|
|
|
| 1163 |
logging.error(f"Failed to serve thumbnail for {generated_model_id}: {str(e)}")
|
| 1164 |
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
| 1165 |
|
| 1166 |
+
@router.get("/{generated_model_id}/debug")
|
| 1167 |
+
async def debug_model(generated_model_id: str):
|
| 1168 |
+
"""
|
| 1169 |
+
Debug endpoint to check model and file existence in production.
|
| 1170 |
+
Returns detailed information about what's in the database.
|
| 1171 |
+
"""
|
| 1172 |
+
try:
|
| 1173 |
+
# Handle placeholder IDs and validate integer format
|
| 1174 |
+
if generated_model_id.startswith("placeholder_"):
|
| 1175 |
+
return {"error": "Placeholder ID", "generated_model_id": generated_model_id}
|
| 1176 |
+
|
| 1177 |
+
try:
|
| 1178 |
+
model_id_int = int(generated_model_id)
|
| 1179 |
+
except ValueError:
|
| 1180 |
+
return {"error": "Invalid ID format", "generated_model_id": generated_model_id}
|
| 1181 |
+
|
| 1182 |
+
# Check if model exists
|
| 1183 |
+
model_check = supabase.from_("Generated_Models").select("*").eq("generated_model_id", model_id_int).execute()
|
| 1184 |
+
|
| 1185 |
+
# Check for files
|
| 1186 |
+
files_check = supabase.from_("Model_Files").select("*").eq("generated_model_id", model_id_int).execute()
|
| 1187 |
+
|
| 1188 |
+
return {
|
| 1189 |
+
"generated_model_id": model_id_int,
|
| 1190 |
+
"model_exists": bool(model_check.data),
|
| 1191 |
+
"model_data": model_check.data[0] if model_check.data else None,
|
| 1192 |
+
"files_exist": bool(files_check.data),
|
| 1193 |
+
"files_count": len(files_check.data) if files_check.data else 0,
|
| 1194 |
+
"files_data": files_check.data if files_check.data else []
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
except Exception as e:
|
| 1198 |
+
return {
|
| 1199 |
+
"error": f"Debug error: {str(e)}",
|
| 1200 |
+
"generated_model_id": generated_model_id
|
| 1201 |
+
}
|
| 1202 |
+
|
| 1203 |
@router.delete("/{generated_model_id}", dependencies=[Depends(get_current_active_user)])
|
| 1204 |
async def delete_model(
|
| 1205 |
generated_model_id: str,
|