2023-05-21 12:15:44 +00:00
|
|
|
from abc import ABC, abstractmethod
|
2023-05-21 10:24:59 +00:00
|
|
|
from logging import Logger
|
2023-05-22 05:48:12 +00:00
|
|
|
from typing import Optional, TYPE_CHECKING, Union
|
2023-05-17 09:13:53 +00:00
|
|
|
from PIL.Image import Image as PILImageType
|
2023-05-21 12:15:44 +00:00
|
|
|
|
2023-05-23 08:59:43 +00:00
|
|
|
from invokeai.app.models.image import (
|
|
|
|
ImageCategory,
|
2023-05-27 11:39:20 +00:00
|
|
|
ResourceOrigin,
|
2023-05-23 08:59:43 +00:00
|
|
|
InvalidImageCategoryException,
|
2023-05-27 11:39:20 +00:00
|
|
|
InvalidOriginException,
|
2023-05-23 08:59:43 +00:00
|
|
|
)
|
2023-05-21 12:15:44 +00:00
|
|
|
from invokeai.app.models.metadata import ImageMetadata
|
2023-06-16 05:52:32 +00:00
|
|
|
from invokeai.app.services.board_image_record_storage import BoardImageRecordStorageBase
|
2023-05-21 10:05:33 +00:00
|
|
|
from invokeai.app.services.image_record_storage import (
|
2023-05-23 08:59:43 +00:00
|
|
|
ImageRecordDeleteException,
|
|
|
|
ImageRecordNotFoundException,
|
|
|
|
ImageRecordSaveException,
|
2023-05-21 10:05:33 +00:00
|
|
|
ImageRecordStorageBase,
|
2023-05-28 08:59:14 +00:00
|
|
|
OffsetPaginatedResults,
|
2023-05-17 09:13:53 +00:00
|
|
|
)
|
2023-05-21 10:05:33 +00:00
|
|
|
from invokeai.app.services.models.image_record import (
|
|
|
|
ImageRecord,
|
|
|
|
ImageDTO,
|
2023-05-25 13:47:18 +00:00
|
|
|
ImageRecordChanges,
|
2023-05-21 10:05:33 +00:00
|
|
|
image_record_to_dto,
|
|
|
|
)
|
2023-05-23 08:59:43 +00:00
|
|
|
from invokeai.app.services.image_file_storage import (
|
|
|
|
ImageFileDeleteException,
|
|
|
|
ImageFileNotFoundException,
|
|
|
|
ImageFileSaveException,
|
|
|
|
ImageFileStorageBase,
|
|
|
|
)
|
2023-05-22 05:48:12 +00:00
|
|
|
from invokeai.app.services.item_storage import ItemStorageABC, PaginatedResults
|
2023-05-17 09:13:53 +00:00
|
|
|
from invokeai.app.services.metadata import MetadataServiceBase
|
2023-05-26 23:10:02 +00:00
|
|
|
from invokeai.app.services.resource_name import NameServiceBase
|
2023-05-17 09:13:53 +00:00
|
|
|
from invokeai.app.services.urls import UrlServiceBase
|
|
|
|
|
2023-05-22 05:48:12 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from invokeai.app.services.graph import GraphExecutionState
|
|
|
|
|
|
|
|
|
2023-05-21 12:15:44 +00:00
|
|
|
class ImageServiceABC(ABC):
|
2023-05-22 09:44:35 +00:00
|
|
|
"""High-level service for image management."""
|
2023-05-21 12:15:44 +00:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def create(
|
|
|
|
self,
|
|
|
|
image: PILImageType,
|
2023-05-27 11:39:20 +00:00
|
|
|
image_origin: ResourceOrigin,
|
2023-05-21 12:15:44 +00:00
|
|
|
image_category: ImageCategory,
|
|
|
|
node_id: Optional[str] = None,
|
|
|
|
session_id: Optional[str] = None,
|
2023-06-14 14:07:20 +00:00
|
|
|
is_intermediate: bool = False,
|
2023-05-21 12:15:44 +00:00
|
|
|
) -> ImageDTO:
|
|
|
|
"""Creates an image, storing the file and its metadata."""
|
|
|
|
pass
|
|
|
|
|
2023-05-25 13:47:18 +00:00
|
|
|
@abstractmethod
|
|
|
|
def update(
|
|
|
|
self,
|
|
|
|
image_name: str,
|
|
|
|
changes: ImageRecordChanges,
|
|
|
|
) -> ImageDTO:
|
|
|
|
"""Updates an image."""
|
|
|
|
pass
|
|
|
|
|
2023-05-21 12:15:44 +00:00
|
|
|
@abstractmethod
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_pil_image(self, image_name: str) -> PILImageType:
|
2023-05-21 12:15:44 +00:00
|
|
|
"""Gets an image as a PIL image."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_record(self, image_name: str) -> ImageRecord:
|
2023-05-21 12:15:44 +00:00
|
|
|
"""Gets an image record."""
|
|
|
|
pass
|
|
|
|
|
2023-05-23 08:59:43 +00:00
|
|
|
@abstractmethod
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_dto(self, image_name: str) -> ImageDTO:
|
2023-05-23 08:59:43 +00:00
|
|
|
"""Gets an image DTO."""
|
|
|
|
pass
|
|
|
|
|
2023-05-21 12:15:44 +00:00
|
|
|
@abstractmethod
|
2023-06-14 14:07:20 +00:00
|
|
|
def get_path(self, image_name: str, thumbnail: bool = False) -> str:
|
2023-05-23 12:57:29 +00:00
|
|
|
"""Gets an image's path."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def validate_path(self, path: str) -> bool:
|
|
|
|
"""Validates an image's path."""
|
2023-05-21 12:15:44 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_url(self, image_name: str, thumbnail: bool = False) -> str:
|
2023-05-23 12:57:29 +00:00
|
|
|
"""Gets an image's or thumbnail's URL."""
|
2023-05-21 12:15:44 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_many(
|
|
|
|
self,
|
2023-05-28 08:59:14 +00:00
|
|
|
offset: int = 0,
|
|
|
|
limit: int = 10,
|
2023-05-27 11:39:20 +00:00
|
|
|
image_origin: Optional[ResourceOrigin] = None,
|
2023-05-28 08:59:14 +00:00
|
|
|
categories: Optional[list[ImageCategory]] = None,
|
2023-05-27 08:32:16 +00:00
|
|
|
is_intermediate: Optional[bool] = None,
|
2023-06-21 09:56:19 +00:00
|
|
|
board_id: Optional[str] = None,
|
2023-05-28 08:59:14 +00:00
|
|
|
) -> OffsetPaginatedResults[ImageDTO]:
|
2023-05-21 12:15:44 +00:00
|
|
|
"""Gets a paginated list of image DTOs."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-06-14 11:40:09 +00:00
|
|
|
def delete(self, image_name: str):
|
2023-05-21 12:15:44 +00:00
|
|
|
"""Deletes an image."""
|
|
|
|
pass
|
|
|
|
|
2023-06-26 19:53:21 +00:00
|
|
|
@abstractmethod
|
|
|
|
def delete_images_on_board(self, board_id: str):
|
|
|
|
"""Deletes all images on a board."""
|
|
|
|
pass
|
|
|
|
|
2023-05-21 12:15:44 +00:00
|
|
|
|
2023-05-17 09:13:53 +00:00
|
|
|
class ImageServiceDependencies:
|
2023-05-21 12:15:44 +00:00
|
|
|
"""Service dependencies for the ImageService."""
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-06-16 05:52:32 +00:00
|
|
|
image_records: ImageRecordStorageBase
|
|
|
|
image_files: ImageFileStorageBase
|
|
|
|
board_image_records: BoardImageRecordStorageBase
|
2023-05-17 09:13:53 +00:00
|
|
|
metadata: MetadataServiceBase
|
|
|
|
urls: UrlServiceBase
|
2023-05-21 10:24:59 +00:00
|
|
|
logger: Logger
|
2023-05-26 23:10:02 +00:00
|
|
|
names: NameServiceBase
|
2023-05-22 05:48:12 +00:00
|
|
|
graph_execution_manager: ItemStorageABC["GraphExecutionState"]
|
2023-05-17 09:13:53 +00:00
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
2023-05-21 10:05:33 +00:00
|
|
|
image_record_storage: ImageRecordStorageBase,
|
|
|
|
image_file_storage: ImageFileStorageBase,
|
2023-06-16 05:52:32 +00:00
|
|
|
board_image_record_storage: BoardImageRecordStorageBase,
|
2023-05-21 10:05:33 +00:00
|
|
|
metadata: MetadataServiceBase,
|
|
|
|
url: UrlServiceBase,
|
2023-05-21 10:24:59 +00:00
|
|
|
logger: Logger,
|
2023-05-26 23:10:02 +00:00
|
|
|
names: NameServiceBase,
|
2023-05-22 05:48:12 +00:00
|
|
|
graph_execution_manager: ItemStorageABC["GraphExecutionState"],
|
2023-05-17 09:13:53 +00:00
|
|
|
):
|
2023-06-16 05:52:32 +00:00
|
|
|
self.image_records = image_record_storage
|
|
|
|
self.image_files = image_file_storage
|
|
|
|
self.board_image_records = board_image_record_storage
|
2023-05-21 10:05:33 +00:00
|
|
|
self.metadata = metadata
|
|
|
|
self.urls = url
|
2023-05-21 10:24:59 +00:00
|
|
|
self.logger = logger
|
2023-05-26 23:10:02 +00:00
|
|
|
self.names = names
|
2023-05-22 05:48:12 +00:00
|
|
|
self.graph_execution_manager = graph_execution_manager
|
2023-05-17 09:13:53 +00:00
|
|
|
|
|
|
|
|
2023-05-21 12:15:44 +00:00
|
|
|
class ImageService(ImageServiceABC):
|
2023-05-17 09:13:53 +00:00
|
|
|
_services: ImageServiceDependencies
|
|
|
|
|
2023-06-16 05:52:32 +00:00
|
|
|
def __init__(self, services: ImageServiceDependencies):
|
|
|
|
self._services = services
|
2023-05-17 09:13:53 +00:00
|
|
|
|
|
|
|
def create(
|
|
|
|
self,
|
|
|
|
image: PILImageType,
|
2023-05-27 11:39:20 +00:00
|
|
|
image_origin: ResourceOrigin,
|
2023-05-17 09:13:53 +00:00
|
|
|
image_category: ImageCategory,
|
2023-05-21 10:05:33 +00:00
|
|
|
node_id: Optional[str] = None,
|
|
|
|
session_id: Optional[str] = None,
|
2023-05-25 13:47:18 +00:00
|
|
|
is_intermediate: bool = False,
|
2023-05-21 10:05:33 +00:00
|
|
|
) -> ImageDTO:
|
2023-05-27 11:39:20 +00:00
|
|
|
if image_origin not in ResourceOrigin:
|
|
|
|
raise InvalidOriginException
|
2023-05-23 08:59:43 +00:00
|
|
|
|
|
|
|
if image_category not in ImageCategory:
|
|
|
|
raise InvalidImageCategoryException
|
|
|
|
|
2023-05-26 23:10:02 +00:00
|
|
|
image_name = self._services.names.create_image_name()
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-05-22 05:48:12 +00:00
|
|
|
metadata = self._get_metadata(session_id, node_id)
|
2023-05-21 12:15:44 +00:00
|
|
|
|
2023-05-23 08:59:43 +00:00
|
|
|
(width, height) = image.size
|
|
|
|
|
2023-05-17 09:13:53 +00:00
|
|
|
try:
|
|
|
|
# TODO: Consider using a transaction here to ensure consistency between storage and database
|
2023-06-16 05:52:32 +00:00
|
|
|
self._services.image_records.save(
|
2023-05-23 08:59:43 +00:00
|
|
|
# Non-nullable fields
|
2023-05-17 09:13:53 +00:00
|
|
|
image_name=image_name,
|
2023-05-27 11:39:20 +00:00
|
|
|
image_origin=image_origin,
|
2023-05-17 09:13:53 +00:00
|
|
|
image_category=image_category,
|
2023-05-23 08:59:43 +00:00
|
|
|
width=width,
|
|
|
|
height=height,
|
2023-05-25 13:47:18 +00:00
|
|
|
# Meta fields
|
|
|
|
is_intermediate=is_intermediate,
|
2023-05-23 08:59:43 +00:00
|
|
|
# Nullable fields
|
2023-05-17 09:13:53 +00:00
|
|
|
node_id=node_id,
|
|
|
|
session_id=session_id,
|
|
|
|
metadata=metadata,
|
2023-05-23 08:59:43 +00:00
|
|
|
)
|
|
|
|
|
2023-06-16 05:52:32 +00:00
|
|
|
self._services.image_files.save(
|
2023-05-23 08:59:43 +00:00
|
|
|
image_name=image_name,
|
|
|
|
image=image,
|
|
|
|
metadata=metadata,
|
2023-05-17 09:13:53 +00:00
|
|
|
)
|
|
|
|
|
2023-06-16 05:52:32 +00:00
|
|
|
image_dto = self.get_dto(image_name)
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-06-16 05:52:32 +00:00
|
|
|
return image_dto
|
2023-05-23 08:59:43 +00:00
|
|
|
except ImageRecordSaveException:
|
2023-05-21 10:24:59 +00:00
|
|
|
self._services.logger.error("Failed to save image record")
|
2023-05-17 09:13:53 +00:00
|
|
|
raise
|
2023-05-23 08:59:43 +00:00
|
|
|
except ImageFileSaveException:
|
2023-05-21 10:24:59 +00:00
|
|
|
self._services.logger.error("Failed to save image file")
|
2023-05-17 09:13:53 +00:00
|
|
|
raise
|
2023-05-21 12:15:44 +00:00
|
|
|
except Exception as e:
|
|
|
|
self._services.logger.error("Problem saving image record and file")
|
|
|
|
raise e
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-05-25 13:47:18 +00:00
|
|
|
def update(
|
|
|
|
self,
|
|
|
|
image_name: str,
|
|
|
|
changes: ImageRecordChanges,
|
|
|
|
) -> ImageDTO:
|
|
|
|
try:
|
2023-06-16 05:52:32 +00:00
|
|
|
self._services.image_records.update(image_name, changes)
|
2023-06-14 11:40:09 +00:00
|
|
|
return self.get_dto(image_name)
|
2023-05-25 13:47:18 +00:00
|
|
|
except ImageRecordSaveException:
|
|
|
|
self._services.logger.error("Failed to update image record")
|
|
|
|
raise
|
|
|
|
except Exception as e:
|
|
|
|
self._services.logger.error("Problem updating image record")
|
|
|
|
raise e
|
|
|
|
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_pil_image(self, image_name: str) -> PILImageType:
|
2023-05-17 09:13:53 +00:00
|
|
|
try:
|
2023-06-16 05:52:32 +00:00
|
|
|
return self._services.image_files.get(image_name)
|
2023-05-23 08:59:43 +00:00
|
|
|
except ImageFileNotFoundException:
|
2023-05-21 10:24:59 +00:00
|
|
|
self._services.logger.error("Failed to get image file")
|
2023-05-17 09:13:53 +00:00
|
|
|
raise
|
2023-05-21 12:15:44 +00:00
|
|
|
except Exception as e:
|
|
|
|
self._services.logger.error("Problem getting image file")
|
|
|
|
raise e
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_record(self, image_name: str) -> ImageRecord:
|
2023-05-17 09:13:53 +00:00
|
|
|
try:
|
2023-06-16 05:52:32 +00:00
|
|
|
return self._services.image_records.get(image_name)
|
2023-05-23 08:59:43 +00:00
|
|
|
except ImageRecordNotFoundException:
|
2023-05-21 12:15:44 +00:00
|
|
|
self._services.logger.error("Image record not found")
|
2023-05-21 10:05:33 +00:00
|
|
|
raise
|
2023-05-21 12:15:44 +00:00
|
|
|
except Exception as e:
|
|
|
|
self._services.logger.error("Problem getting image record")
|
|
|
|
raise e
|
|
|
|
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_dto(self, image_name: str) -> ImageDTO:
|
2023-05-21 10:05:33 +00:00
|
|
|
try:
|
2023-06-16 05:52:32 +00:00
|
|
|
image_record = self._services.image_records.get(image_name)
|
2023-05-21 10:05:33 +00:00
|
|
|
|
|
|
|
image_dto = image_record_to_dto(
|
|
|
|
image_record,
|
2023-06-14 11:40:09 +00:00
|
|
|
self._services.urls.get_image_url(image_name),
|
|
|
|
self._services.urls.get_image_url(image_name, True),
|
2023-06-16 05:52:32 +00:00
|
|
|
self._services.board_image_records.get_board_for_image(image_name),
|
2023-05-17 09:13:53 +00:00
|
|
|
)
|
2023-05-21 10:05:33 +00:00
|
|
|
|
|
|
|
return image_dto
|
2023-05-23 08:59:43 +00:00
|
|
|
except ImageRecordNotFoundException:
|
2023-05-21 12:15:44 +00:00
|
|
|
self._services.logger.error("Image record not found")
|
2023-05-17 09:13:53 +00:00
|
|
|
raise
|
2023-05-21 12:15:44 +00:00
|
|
|
except Exception as e:
|
|
|
|
self._services.logger.error("Problem getting image DTO")
|
|
|
|
raise e
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_path(self, image_name: str, thumbnail: bool = False) -> str:
|
2023-05-22 05:48:12 +00:00
|
|
|
try:
|
2023-06-16 05:52:32 +00:00
|
|
|
return self._services.image_files.get_path(image_name, thumbnail)
|
2023-05-22 05:48:12 +00:00
|
|
|
except Exception as e:
|
|
|
|
self._services.logger.error("Problem getting image path")
|
|
|
|
raise e
|
|
|
|
|
2023-05-23 12:57:29 +00:00
|
|
|
def validate_path(self, path: str) -> bool:
|
|
|
|
try:
|
2023-06-16 05:52:32 +00:00
|
|
|
return self._services.image_files.validate_path(path)
|
2023-05-23 12:57:29 +00:00
|
|
|
except Exception as e:
|
|
|
|
self._services.logger.error("Problem validating image path")
|
|
|
|
raise e
|
|
|
|
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_url(self, image_name: str, thumbnail: bool = False) -> str:
|
2023-05-22 05:48:12 +00:00
|
|
|
try:
|
2023-06-14 11:40:09 +00:00
|
|
|
return self._services.urls.get_image_url(image_name, thumbnail)
|
2023-05-22 05:48:12 +00:00
|
|
|
except Exception as e:
|
|
|
|
self._services.logger.error("Problem getting image path")
|
|
|
|
raise e
|
|
|
|
|
2023-05-17 09:13:53 +00:00
|
|
|
def get_many(
|
|
|
|
self,
|
2023-05-28 08:59:14 +00:00
|
|
|
offset: int = 0,
|
|
|
|
limit: int = 10,
|
2023-05-27 11:39:20 +00:00
|
|
|
image_origin: Optional[ResourceOrigin] = None,
|
2023-05-28 08:59:14 +00:00
|
|
|
categories: Optional[list[ImageCategory]] = None,
|
2023-05-27 08:32:16 +00:00
|
|
|
is_intermediate: Optional[bool] = None,
|
2023-06-21 09:56:19 +00:00
|
|
|
board_id: Optional[str] = None,
|
2023-05-28 08:59:14 +00:00
|
|
|
) -> OffsetPaginatedResults[ImageDTO]:
|
2023-05-17 09:13:53 +00:00
|
|
|
try:
|
2023-06-16 05:52:32 +00:00
|
|
|
results = self._services.image_records.get_many(
|
2023-05-28 08:59:14 +00:00
|
|
|
offset,
|
|
|
|
limit,
|
2023-05-27 11:39:20 +00:00
|
|
|
image_origin,
|
2023-05-28 08:59:14 +00:00
|
|
|
categories,
|
2023-05-26 23:17:06 +00:00
|
|
|
is_intermediate,
|
2023-06-21 09:56:19 +00:00
|
|
|
board_id,
|
2023-05-17 09:13:53 +00:00
|
|
|
)
|
|
|
|
|
2023-05-21 10:05:33 +00:00
|
|
|
image_dtos = list(
|
|
|
|
map(
|
|
|
|
lambda r: image_record_to_dto(
|
|
|
|
r,
|
2023-06-14 11:40:09 +00:00
|
|
|
self._services.urls.get_image_url(r.image_name),
|
|
|
|
self._services.urls.get_image_url(r.image_name, True),
|
2023-06-16 05:52:32 +00:00
|
|
|
self._services.board_image_records.get_board_for_image(
|
|
|
|
r.image_name
|
|
|
|
),
|
2023-05-21 10:05:33 +00:00
|
|
|
),
|
|
|
|
results.items,
|
2023-05-17 09:13:53 +00:00
|
|
|
)
|
2023-05-21 10:05:33 +00:00
|
|
|
)
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-05-28 08:59:14 +00:00
|
|
|
return OffsetPaginatedResults[ImageDTO](
|
2023-05-21 10:05:33 +00:00
|
|
|
items=image_dtos,
|
2023-05-28 08:59:14 +00:00
|
|
|
offset=results.offset,
|
|
|
|
limit=results.limit,
|
2023-05-21 10:05:33 +00:00
|
|
|
total=results.total,
|
|
|
|
)
|
2023-05-17 09:13:53 +00:00
|
|
|
except Exception as e:
|
2023-05-21 12:15:44 +00:00
|
|
|
self._services.logger.error("Problem getting paginated image DTOs")
|
|
|
|
raise e
|
|
|
|
|
2023-06-14 11:40:09 +00:00
|
|
|
def delete(self, image_name: str):
|
2023-05-21 12:15:44 +00:00
|
|
|
try:
|
2023-06-16 05:52:32 +00:00
|
|
|
self._services.image_files.delete(image_name)
|
|
|
|
self._services.image_records.delete(image_name)
|
2023-05-23 08:59:43 +00:00
|
|
|
except ImageRecordDeleteException:
|
2023-05-21 12:15:44 +00:00
|
|
|
self._services.logger.error(f"Failed to delete image record")
|
|
|
|
raise
|
2023-05-23 08:59:43 +00:00
|
|
|
except ImageFileDeleteException:
|
2023-05-21 12:15:44 +00:00
|
|
|
self._services.logger.error(f"Failed to delete image file")
|
|
|
|
raise
|
|
|
|
except Exception as e:
|
|
|
|
self._services.logger.error("Problem deleting image record and file")
|
2023-05-17 09:13:53 +00:00
|
|
|
raise e
|
|
|
|
|
2023-06-26 19:53:21 +00:00
|
|
|
def delete_images_on_board(self, board_id: str):
|
|
|
|
try:
|
|
|
|
images = self._services.board_image_records.get_images_for_board(board_id)
|
|
|
|
image_name_list = list(
|
|
|
|
map(
|
|
|
|
lambda r: r.image_name,
|
|
|
|
images.items,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
for image_name in image_name_list:
|
|
|
|
self._services.image_files.delete(image_name)
|
|
|
|
self._services.image_records.delete_many(image_name_list)
|
|
|
|
except ImageRecordDeleteException:
|
|
|
|
self._services.logger.error(f"Failed to delete image records")
|
|
|
|
raise
|
|
|
|
except ImageFileDeleteException:
|
|
|
|
self._services.logger.error(f"Failed to delete image files")
|
|
|
|
raise
|
|
|
|
except Exception as e:
|
|
|
|
self._services.logger.error("Problem deleting image records and files")
|
|
|
|
raise e
|
|
|
|
|
2023-05-22 05:48:12 +00:00
|
|
|
def _get_metadata(
|
|
|
|
self, session_id: Optional[str] = None, node_id: Optional[str] = None
|
|
|
|
) -> Union[ImageMetadata, None]:
|
|
|
|
"""Get the metadata for a node."""
|
|
|
|
metadata = None
|
|
|
|
|
|
|
|
if node_id is not None and session_id is not None:
|
|
|
|
session = self._services.graph_execution_manager.get(session_id)
|
|
|
|
metadata = self._services.metadata.create_image_metadata(session, node_id)
|
|
|
|
|
|
|
|
return metadata
|