mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(nodes): generalise list_images route for all types
This commit is contained in:
parent
4f3be53d55
commit
daf1bc6b67
@ -15,7 +15,6 @@ from ..dependencies import ApiDependencies
|
|||||||
|
|
||||||
images_router = APIRouter(prefix="/v1/images", tags=["images"])
|
images_router = APIRouter(prefix="/v1/images", tags=["images"])
|
||||||
|
|
||||||
|
|
||||||
@images_router.get("/{image_type}/{image_name}", operation_id="get_image")
|
@images_router.get("/{image_type}/{image_name}", operation_id="get_image")
|
||||||
async def get_image(
|
async def get_image(
|
||||||
image_type: ImageType = Path(description="The type of image to get"),
|
image_type: ImageType = Path(description="The type of image to get"),
|
||||||
@ -69,16 +68,17 @@ async def upload_image(file: UploadFile, request: Request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@images_router.get(
|
@images_router.get(
|
||||||
"/uploads/",
|
"/",
|
||||||
operation_id="list_uploads",
|
operation_id="list_images",
|
||||||
responses={200: {"model": PaginatedResults[ImageField]}},
|
responses={200: {"model": PaginatedResults[ImageField]}},
|
||||||
)
|
)
|
||||||
async def list_uploads(
|
async def list_images(
|
||||||
page: int = Query(default=0, description="The page of uploads to get"),
|
image_type: ImageType = Query(default=ImageType.RESULT, description="The type of images to get"),
|
||||||
per_page: int = Query(default=10, description="The number of uploads per page"),
|
page: int = Query(default=0, description="The page of images to get"),
|
||||||
|
per_page: int = Query(default=10, description="The number of images per page"),
|
||||||
) -> PaginatedResults[ImageField]:
|
) -> PaginatedResults[ImageField]:
|
||||||
"""Gets a list of uploads"""
|
"""Gets a list of images"""
|
||||||
result = ApiDependencies.invoker.services.images.list(
|
result = ApiDependencies.invoker.services.images.list(
|
||||||
ImageType.UPLOAD, page, per_page
|
image_type, page, per_page
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
@ -77,18 +77,19 @@ class DiskImageStorage(ImageStorageBase):
|
|||||||
self, image_type: ImageType, page: int = 0, per_page: int = 10
|
self, image_type: ImageType, page: int = 0, per_page: int = 10
|
||||||
) -> PaginatedResults[ImageField]:
|
) -> PaginatedResults[ImageField]:
|
||||||
dir_path = os.path.join(self.__output_folder, image_type)
|
dir_path = os.path.join(self.__output_folder, image_type)
|
||||||
|
image_paths = glob(f"{dir_path}/*.png")
|
||||||
|
|
||||||
|
# just want the filenames
|
||||||
|
image_filenames = list(map(lambda i: os.path.basename(i), image_paths))
|
||||||
|
|
||||||
# we want to sort the images by timestamp, but we don't trust the filesystem
|
# we want to sort the images by timestamp, but we don't trust the filesystem
|
||||||
# we do have a timestamp in the filename: `{uuid}_{timestamp}.png`
|
# we do have a timestamp in the filename: `{uuid}_{timestamp}.png`
|
||||||
|
|
||||||
image_paths = glob(f"{dir_path}/*.png")
|
|
||||||
sorted_paths = sorted(
|
sorted_paths = sorted(
|
||||||
# extract the timestamp as int and multiply -1 to reverse sorting
|
# extract the timestamp as int and multiply -1 to reverse sorting
|
||||||
image_paths, key=lambda i: int(os.path.splitext(i)[0].split("_")[1]) * -1
|
image_filenames, key=lambda i: int(os.path.splitext(i)[0].split("_")[-1]) * -1
|
||||||
)
|
)
|
||||||
|
|
||||||
all_images = list(
|
all_images = list(
|
||||||
# build ImageFields for every image path
|
|
||||||
map(lambda i: ImageField(image_type=image_type, image_name=i), sorted_paths)
|
map(lambda i: ImageField(image_type=image_type, image_name=i), sorted_paths)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user