Album covers added

This commit is contained in:
Profitroll
2022-12-20 23:59:47 +01:00
parent 7035f78bac
commit 0f1c6edf0f
2 changed files with 23 additions and 7 deletions

View File

@@ -114,6 +114,11 @@ async def photo_delete(id: str, current_user: User = Security(get_current_active
except InvalidId:
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Could not find an image with such id.")
album = col_albums.find_one( {"name": image["album"]} )
if album is not None and album["cover"] == image["_id"].__str__():
col_albums.update_one( {"name": image["album"]}, {"$set": {"cover": None}} )
remove(path.join("data", "users", current_user.user, "albums", image["album"], image["filename"]))
return Response(status_code=HTTP_204_NO_CONTENT)