Add file upload

This commit is contained in:
2024-05-10 14:20:46 +04:00
parent 698cca0aeb
commit a45c2dfee2
11 changed files with 102 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, UploadFile
from database import *
from file_handler import *
router = APIRouter(prefix="/games", tags=["Games"])
@@ -14,7 +15,13 @@ async def get_game(game_id: int, db: AsyncSession = Depends(get_session)):
return await crud.get_game(db, game_id)
@router.post("/", response_model=Game)
async def add_game(game: GameCreate, user_id: int, db:AsyncSession = Depends(get_session)):
try: return await crud.add_game(db, game, user_id)
except Exception as ex: raise HTTPException(500)
async def add_game(game: GameCreate,
user_id: int,
db:AsyncSession = Depends(get_session)):
try:
torrent_filename = save_torrent_file(torrent, game.title)
cover_filename = save_image(cover, game.title, "cover")
return await crud.add_game(db, game, user_id)
except Exception as ex:
raise HTTPException(500)