Initial commit
This commit is contained in:
0
backend/app/api/v1/__init__.py
Normal file
0
backend/app/api/v1/__init__.py
Normal file
BIN
backend/app/api/v1/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
backend/app/api/v1/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
backend/app/api/v1/endpoints/__pycache__/model.cpython-313.pyc
Normal file
BIN
backend/app/api/v1/endpoints/__pycache__/model.cpython-313.pyc
Normal file
Binary file not shown.
35
backend/app/api/v1/endpoints/model.py
Normal file
35
backend/app/api/v1/endpoints/model.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
from typing import List
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
MODELS_DIRECTORY = "models"
|
||||
|
||||
@router.get("/models", response_model=List[str])
|
||||
async def get_model_list():
|
||||
"""
|
||||
사용 가능한 모든 OBJ 모델의 이름 목록을 반환합니다.
|
||||
"""
|
||||
try:
|
||||
files = os.listdir(MODELS_DIRECTORY)
|
||||
obj_models = [f.split('.obj')[0] for f in files if f.endswith(".obj")]
|
||||
return obj_models
|
||||
except FileNotFoundError:
|
||||
raise HTTPException(status_code=404, detail="Models directory not found")
|
||||
|
||||
@router.get("/models/{model_name}")
|
||||
async def get_model(model_name: str):
|
||||
"""
|
||||
지정된 이름의 OBJ 모델 파일을 반환합니다.
|
||||
"""
|
||||
if not model_name.endswith(".obj"):
|
||||
model_name += ".obj"
|
||||
|
||||
file_path = os.path.join(MODELS_DIRECTORY, model_name)
|
||||
|
||||
if not os.path.exists(file_path):
|
||||
raise HTTPException(status_code=404, detail="Model not found")
|
||||
|
||||
return FileResponse(file_path, media_type='application/octet-stream', filename=model_name)
|
||||
Reference in New Issue
Block a user