-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into install-script-python-version-error-prompt-fix
- Loading branch information
Showing
137 changed files
with
4,087 additions
and
1,018 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from fastapi import Body, HTTPException, Path, Query | ||
from fastapi.routing import APIRouter | ||
from invokeai.app.services.board_record_storage import BoardRecord, BoardChanges | ||
from invokeai.app.services.image_record_storage import OffsetPaginatedResults | ||
from invokeai.app.services.models.board_record import BoardDTO | ||
from invokeai.app.services.models.image_record import ImageDTO | ||
|
||
from ..dependencies import ApiDependencies | ||
|
||
board_images_router = APIRouter(prefix="/v1/board_images", tags=["boards"]) | ||
|
||
|
||
@board_images_router.post( | ||
"/", | ||
operation_id="create_board_image", | ||
responses={ | ||
201: {"description": "The image was added to a board successfully"}, | ||
}, | ||
status_code=201, | ||
) | ||
async def create_board_image( | ||
board_id: str = Body(description="The id of the board to add to"), | ||
image_name: str = Body(description="The name of the image to add"), | ||
): | ||
"""Creates a board_image""" | ||
try: | ||
result = ApiDependencies.invoker.services.board_images.add_image_to_board(board_id=board_id, image_name=image_name) | ||
return result | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail="Failed to add to board") | ||
|
||
@board_images_router.delete( | ||
"/", | ||
operation_id="remove_board_image", | ||
responses={ | ||
201: {"description": "The image was removed from the board successfully"}, | ||
}, | ||
status_code=201, | ||
) | ||
async def remove_board_image( | ||
board_id: str = Body(description="The id of the board"), | ||
image_name: str = Body(description="The name of the image to remove"), | ||
): | ||
"""Deletes a board_image""" | ||
try: | ||
result = ApiDependencies.invoker.services.board_images.remove_image_from_board(board_id=board_id, image_name=image_name) | ||
return result | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail="Failed to update board") | ||
|
||
|
||
|
||
@board_images_router.get( | ||
"/{board_id}", | ||
operation_id="list_board_images", | ||
response_model=OffsetPaginatedResults[ImageDTO], | ||
) | ||
async def list_board_images( | ||
board_id: str = Path(description="The id of the board"), | ||
offset: int = Query(default=0, description="The page offset"), | ||
limit: int = Query(default=10, description="The number of boards per page"), | ||
) -> OffsetPaginatedResults[ImageDTO]: | ||
"""Gets a list of images for a board""" | ||
|
||
results = ApiDependencies.invoker.services.board_images.get_images_for_board( | ||
board_id, | ||
) | ||
return results | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
from typing import Optional, Union | ||
from fastapi import Body, HTTPException, Path, Query | ||
from fastapi.routing import APIRouter | ||
from invokeai.app.services.board_record_storage import BoardChanges | ||
from invokeai.app.services.image_record_storage import OffsetPaginatedResults | ||
from invokeai.app.services.models.board_record import BoardDTO | ||
|
||
from ..dependencies import ApiDependencies | ||
|
||
boards_router = APIRouter(prefix="/v1/boards", tags=["boards"]) | ||
|
||
|
||
@boards_router.post( | ||
"/", | ||
operation_id="create_board", | ||
responses={ | ||
201: {"description": "The board was created successfully"}, | ||
}, | ||
status_code=201, | ||
response_model=BoardDTO, | ||
) | ||
async def create_board( | ||
board_name: str = Query(description="The name of the board to create"), | ||
) -> BoardDTO: | ||
"""Creates a board""" | ||
try: | ||
result = ApiDependencies.invoker.services.boards.create(board_name=board_name) | ||
return result | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail="Failed to create board") | ||
|
||
|
||
@boards_router.get("/{board_id}", operation_id="get_board", response_model=BoardDTO) | ||
async def get_board( | ||
board_id: str = Path(description="The id of board to get"), | ||
) -> BoardDTO: | ||
"""Gets a board""" | ||
|
||
try: | ||
result = ApiDependencies.invoker.services.boards.get_dto(board_id=board_id) | ||
return result | ||
except Exception as e: | ||
raise HTTPException(status_code=404, detail="Board not found") | ||
|
||
|
||
@boards_router.patch( | ||
"/{board_id}", | ||
operation_id="update_board", | ||
responses={ | ||
201: { | ||
"description": "The board was updated successfully", | ||
}, | ||
}, | ||
status_code=201, | ||
response_model=BoardDTO, | ||
) | ||
async def update_board( | ||
board_id: str = Path(description="The id of board to update"), | ||
changes: BoardChanges = Body(description="The changes to apply to the board"), | ||
) -> BoardDTO: | ||
"""Updates a board""" | ||
try: | ||
result = ApiDependencies.invoker.services.boards.update( | ||
board_id=board_id, changes=changes | ||
) | ||
return result | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail="Failed to update board") | ||
|
||
|
||
@boards_router.delete("/{board_id}", operation_id="delete_board") | ||
async def delete_board( | ||
board_id: str = Path(description="The id of board to delete"), | ||
) -> None: | ||
"""Deletes a board""" | ||
|
||
try: | ||
ApiDependencies.invoker.services.boards.delete(board_id=board_id) | ||
except Exception as e: | ||
# TODO: Does this need any exception handling at all? | ||
pass | ||
|
||
|
||
@boards_router.get( | ||
"/", | ||
operation_id="list_boards", | ||
response_model=Union[OffsetPaginatedResults[BoardDTO], list[BoardDTO]], | ||
) | ||
async def list_boards( | ||
all: Optional[bool] = Query(default=None, description="Whether to list all boards"), | ||
offset: Optional[int] = Query(default=None, description="The page offset"), | ||
limit: Optional[int] = Query( | ||
default=None, description="The number of boards per page" | ||
), | ||
) -> Union[OffsetPaginatedResults[BoardDTO], list[BoardDTO]]: | ||
"""Gets a list of boards""" | ||
if all: | ||
return ApiDependencies.invoker.services.boards.get_all() | ||
elif offset is not None and limit is not None: | ||
return ApiDependencies.invoker.services.boards.get_many( | ||
offset, | ||
limit, | ||
) | ||
else: | ||
raise HTTPException( | ||
status_code=400, | ||
detail="Invalid request: Must provide either 'all' or both 'offset' and 'limit'", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.