feat(nodes): image records router

This commit is contained in:
psychedelicious 2023-05-21 15:47:29 +10:00 committed by Kent Keirsey
parent 9c89d3452c
commit 33d199c007
4 changed files with 24 additions and 9 deletions

View File

@ -11,7 +11,7 @@ from invokeai.app.services.item_storage import PaginatedResults
from ..dependencies import ApiDependencies from ..dependencies import ApiDependencies
image_records_router = APIRouter(prefix="/v1/records/images", tags=["records"]) image_records_router = APIRouter(prefix="/v1/images", tags=["images", "records"])
@image_records_router.get("/{image_type}/{image_name}", operation_id="get_image_record") @image_records_router.get("/{image_type}/{image_name}", operation_id="get_image_record")
@ -57,7 +57,7 @@ async def list_image_records(
@image_records_router.delete("/{image_type}/{image_name}", operation_id="delete_image") @image_records_router.delete("/{image_type}/{image_name}", operation_id="delete_image")
async def delete_image_record( async def delete_image_record(
image_type: ImageType = Query(description="The type of image records to get"), image_type: ImageType = Query(description="The type of image to delete"),
image_name: str = Path(description="The name of the image to delete"), image_name: str = Path(description="The name of the image to delete"),
) -> None: ) -> None:
"""Deletes an image record""" """Deletes an image record"""

View File

@ -19,7 +19,7 @@ from invokeai.app.services.item_storage import PaginatedResults
from ..dependencies import ApiDependencies from ..dependencies import ApiDependencies
images_router = APIRouter(prefix="/v1/images", tags=["images"]) images_router = APIRouter(prefix="/v1/files/images", tags=["images", "files"])
# @images_router.get("/{image_type}/{image_name}", operation_id="get_image") # @images_router.get("/{image_type}/{image_name}", operation_id="get_image")
@ -38,15 +38,16 @@ images_router = APIRouter(prefix="/v1/images", tags=["images"])
# else: # else:
# raise HTTPException(status_code=404) # raise HTTPException(status_code=404)
@images_router.get("/{image_type}/{image_id}", 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 the image to get"), image_type: ImageType = Path(description="The type of the image to get"),
image_id: str = Path(description="The id of the image to get"), image_name: str = Path(description="The id of the image to get"),
) -> FileResponse: ) -> FileResponse:
"""Gets an image""" """Gets an image"""
path = ApiDependencies.invoker.services.images.get_path( path = ApiDependencies.invoker.services.images.get_path(
image_type=image_type, image_id=image_id image_type=image_type, image_name=image_name
) )
if ApiDependencies.invoker.services.images.validate_path(path): if ApiDependencies.invoker.services.images.validate_path(path):
@ -77,7 +78,7 @@ async def get_thumbnail(
"""Gets a thumbnail""" """Gets a thumbnail"""
path = ApiDependencies.invoker.services.images.get_path( path = ApiDependencies.invoker.services.images.get_path(
image_type=image_type, image_id=thumbnail_id, is_thumbnail=True image_type=image_type, image_name=thumbnail_id, is_thumbnail=True
) )
if ApiDependencies.invoker.services.images.validate_path(path): if ApiDependencies.invoker.services.images.validate_path(path):

View File

@ -15,7 +15,7 @@ from fastapi_events.middleware import EventHandlerASGIMiddleware
from pydantic.schema import schema from pydantic.schema import schema
from .api.dependencies import ApiDependencies from .api.dependencies import ApiDependencies
from .api.routers import image_resources, images, sessions, models from .api.routers import image_records, images, sessions, models
from .api.sockets import SocketIO from .api.sockets import SocketIO
from .invocations.baseinvocation import BaseInvocation from .invocations.baseinvocation import BaseInvocation
from .services.config import InvokeAIAppConfig from .services.config import InvokeAIAppConfig
@ -75,7 +75,7 @@ app.include_router(images.images_router, prefix="/api")
app.include_router(models.models_router, prefix="/api") app.include_router(models.models_router, prefix="/api")
app.include_router(image_resources.image_resources_router, prefix="/api") app.include_router(image_records.image_records_router, prefix="/api")
# Build a custom OpenAPI to include all outputs # Build a custom OpenAPI to include all outputs

View File

@ -75,6 +75,20 @@ class ImageStorageBase(ABC):
"""Gets the external URI to an image or its thumbnail.""" """Gets the external URI to an image or its thumbnail."""
pass pass
@abstractmethod
def get_image_location(
self, image_type: ImageType, image_name: str
) -> str:
"""Gets the location of an image."""
pass
@abstractmethod
def get_thumbnail_location(
self, image_type: ImageType, image_name: str
) -> str:
"""Gets the location of an image's thumbnail."""
pass
# TODO: make this a bit more flexible for e.g. cloud storage # TODO: make this a bit more flexible for e.g. cloud storage
@abstractmethod @abstractmethod
def validate_path(self, path: str) -> bool: def validate_path(self, path: str) -> bool: