1- from fastapi import Body , HTTPException , Path , Query
1+ from fastapi import Body , HTTPException
22from fastapi .routing import APIRouter
3- from invokeai .app .services .board_record_storage import BoardRecord , BoardChanges
4- from invokeai .app .services .image_record_storage import OffsetPaginatedResults
5- from invokeai .app .services .models .board_record import BoardDTO
6- from invokeai .app .services .models .image_record import ImageDTO
3+ from pydantic import BaseModel , Field
74
85from ..dependencies import ApiDependencies
96
107board_images_router = APIRouter (prefix = "/v1/board_images" , tags = ["boards" ])
118
129
10+ class AddImagesToBoardResult (BaseModel ):
11+ board_id : str = Field (description = "The id of the board the images were added to" )
12+ added_image_names : list [str ] = Field (description = "The image names that were added to the board" )
13+
14+
15+ class RemoveImagesFromBoardResult (BaseModel ):
16+ removed_image_names : list [str ] = Field (description = "The image names that were removed from their board" )
17+
18+
1319@board_images_router .post (
1420 "/" ,
15- operation_id = "create_board_image " ,
21+ operation_id = "add_image_to_board " ,
1622 responses = {
1723 201 : {"description" : "The image was added to a board successfully" },
1824 },
1925 status_code = 201 ,
2026)
21- async def create_board_image (
27+ async def add_image_to_board (
2228 board_id : str = Body (description = "The id of the board to add to" ),
2329 image_name : str = Body (description = "The name of the image to add" ),
2430):
@@ -29,26 +35,78 @@ async def create_board_image(
2935 )
3036 return result
3137 except Exception as e :
32- raise HTTPException (status_code = 500 , detail = "Failed to add to board" )
38+ raise HTTPException (status_code = 500 , detail = "Failed to add image to board" )
3339
3440
3541@board_images_router .delete (
3642 "/" ,
37- operation_id = "remove_board_image " ,
43+ operation_id = "remove_image_from_board " ,
3844 responses = {
3945 201 : {"description" : "The image was removed from the board successfully" },
4046 },
4147 status_code = 201 ,
4248)
43- async def remove_board_image (
44- board_id : str = Body (description = "The id of the board" ),
45- image_name : str = Body (description = "The name of the image to remove" ),
49+ async def remove_image_from_board (
50+ image_name : str = Body (description = "The name of the image to remove" , embed = True ),
4651):
47- """Deletes a board_image """
52+ """Removes an image from its board, if it had one """
4853 try :
49- result = ApiDependencies .invoker .services .board_images .remove_image_from_board (
50- board_id = board_id , image_name = image_name
51- )
54+ result = ApiDependencies .invoker .services .board_images .remove_image_from_board (image_name = image_name )
5255 return result
5356 except Exception as e :
54- raise HTTPException (status_code = 500 , detail = "Failed to update board" )
57+ raise HTTPException (status_code = 500 , detail = "Failed to remove image from board" )
58+
59+
60+ @board_images_router .post (
61+ "/batch" ,
62+ operation_id = "add_images_to_board" ,
63+ responses = {
64+ 201 : {"description" : "Images were added to board successfully" },
65+ },
66+ status_code = 201 ,
67+ response_model = AddImagesToBoardResult ,
68+ )
69+ async def add_images_to_board (
70+ board_id : str = Body (description = "The id of the board to add to" ),
71+ image_names : list [str ] = Body (description = "The names of the images to add" , embed = True ),
72+ ) -> AddImagesToBoardResult :
73+ """Adds a list of images to a board"""
74+ try :
75+ added_image_names : list [str ] = []
76+ for image_name in image_names :
77+ try :
78+ ApiDependencies .invoker .services .board_images .add_image_to_board (
79+ board_id = board_id , image_name = image_name
80+ )
81+ added_image_names .append (image_name )
82+ except :
83+ pass
84+ return AddImagesToBoardResult (board_id = board_id , added_image_names = added_image_names )
85+ except Exception as e :
86+ raise HTTPException (status_code = 500 , detail = "Failed to add images to board" )
87+
88+
89+ @board_images_router .post (
90+ "/batch/delete" ,
91+ operation_id = "remove_images_from_board" ,
92+ responses = {
93+ 201 : {"description" : "Images were removed from board successfully" },
94+ },
95+ status_code = 201 ,
96+ response_model = RemoveImagesFromBoardResult ,
97+ )
98+ async def remove_images_from_board (
99+ image_names : list [str ] = Body (description = "The names of the images to remove" , embed = True ),
100+ ) -> RemoveImagesFromBoardResult :
101+ """Removes a list of images from their board, if they had one"""
102+ try :
103+ removed_image_names : list [str ] = []
104+ for image_name in image_names :
105+ try :
106+ ApiDependencies .invoker .services .board_images .remove_image_from_board (image_name = image_name )
107+ removed_image_names .append (image_name )
108+ except :
109+ pass
110+ return RemoveImagesFromBoardResult (removed_image_names = removed_image_names )
111+ except Exception as e :
112+ raise HTTPException (status_code = 500 , detail = "Failed to remove images from board" )
0 commit comments