HTTPException is not returned, raised instead
This commit is contained in:
@@ -24,10 +24,10 @@ from starlette.status import HTTP_204_NO_CONTENT, HTTP_400_BAD_REQUEST, HTTP_401
|
||||
async def video_upload(file: UploadFile, album: str, caption: Union[str, None] = None, current_user: User = Security(get_current_active_user, scopes=["videos.write"])):
|
||||
|
||||
if col_albums.find_one( {"user": current_user.user, "name": album} ) is None:
|
||||
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail=f"Provided album '{album}' does not exist.")
|
||||
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=f"Provided album '{album}' does not exist.")
|
||||
|
||||
# if not file.content_type.startswith("video"):
|
||||
# return HTTPException(status_code=HTTP_406_NOT_ACCEPTABLE, detail="Provided file is not a video, not accepting.")
|
||||
# raise HTTPException(status_code=HTTP_406_NOT_ACCEPTABLE, detail="Provided file is not a video, not accepting.")
|
||||
|
||||
makedirs(path.join("data", "users", current_user.user, "albums", album), exist_ok=True)
|
||||
|
||||
@@ -88,7 +88,7 @@ async def video_get(id: str, current_user: User = Security(get_current_active_us
|
||||
if video is None:
|
||||
raise InvalidId(id)
|
||||
except InvalidId:
|
||||
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find a video with such id.")
|
||||
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find a video with such id.")
|
||||
|
||||
video_path = path.join("data", "users", current_user.user, "albums", video["album"], video["filename"])
|
||||
|
||||
@@ -106,10 +106,10 @@ async def video_move(id: str, album: str, current_user: User = Security(get_curr
|
||||
if video is None:
|
||||
raise InvalidId(id)
|
||||
except InvalidId:
|
||||
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find an video with such id.")
|
||||
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find an video with such id.")
|
||||
|
||||
if col_albums.find_one( {"user": current_user.user, "name": album} ) is None:
|
||||
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail=f"Provided album '{album}' does not exist.")
|
||||
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=f"Provided album '{album}' does not exist.")
|
||||
|
||||
if path.exists(path.join("data", "users", current_user.user, "albums", album, video["filename"])):
|
||||
base_name = video["filename"].split(".")[:-1]
|
||||
@@ -140,7 +140,7 @@ async def video_patch(id: str, caption: str, current_user: User = Security(get_c
|
||||
if video is None:
|
||||
raise InvalidId(id)
|
||||
except InvalidId:
|
||||
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find an video with such id.")
|
||||
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find an video with such id.")
|
||||
|
||||
col_videos.find_one_and_update( {"_id": ObjectId(id)}, {"$set": {"caption": caption, "dates.modified": datetime.now(tz=timezone.utc)}} )
|
||||
|
||||
@@ -159,7 +159,7 @@ async def video_delete(id: str, current_user: User = Security(get_current_active
|
||||
if video is None:
|
||||
raise InvalidId(id)
|
||||
except InvalidId:
|
||||
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find a video with such id.")
|
||||
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find a video with such id.")
|
||||
|
||||
album = col_albums.find_one( {"name": video["album"]} )
|
||||
|
||||
@@ -171,10 +171,10 @@ async def video_delete(id: str, current_user: User = Security(get_current_active
|
||||
async def video_find(album: str, q: Union[str, None] = None, caption: Union[str, None] = None, page: int = 1, page_size: int = 100, current_user: User = Security(get_current_active_user, scopes=["videos.list"])):
|
||||
|
||||
if col_albums.find_one( {"user": current_user.user, "name": album} ) is None:
|
||||
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail=f"Provided album '{album}' does not exist.")
|
||||
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=f"Provided album '{album}' does not exist.")
|
||||
|
||||
if page <= 0 or page_size <= 0:
|
||||
return HTTPException(status_code=HTTP_400_BAD_REQUEST, detail="Parameters 'page' and 'page_size' must be greater or equal to 1.")
|
||||
raise HTTPException(status_code=HTTP_400_BAD_REQUEST, detail="Parameters 'page' and 'page_size' must be greater or equal to 1.")
|
||||
|
||||
output = {"results": []}
|
||||
skip = (page-1)*page_size
|
||||
@@ -212,6 +212,6 @@ async def video_find_token(token: str):
|
||||
found_record = col_tokens.find_one( {"token": token} )
|
||||
|
||||
if found_record is None:
|
||||
return HTTPException(status_code=HTTP_401_UNAUTHORIZED, detail="Invalid search token.")
|
||||
raise HTTPException(status_code=HTTP_401_UNAUTHORIZED, detail="Invalid search token.")
|
||||
|
||||
return await video_find(q=found_record["query"], album=found_record["album"], page=found_record["page"], page_size=found_record["page_size"], current_user=pickle.loads(found_record["user"]))
|
Reference in New Issue
Block a user