mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-02-02 19:24:58 -05:00
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
from abc import ABC, abstractmethod
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
from PIL.Image import Image as PILImageType
|
|
|
|
from invokeai.app.invocations.fields import MetadataField
|
|
from invokeai.app.services.workflow_records.workflow_records_common import WorkflowWithoutID
|
|
|
|
|
|
class ImageFileStorageBase(ABC):
|
|
"""Low-level service responsible for storing and retrieving image files."""
|
|
|
|
@abstractmethod
|
|
def get(self, image_name: str) -> PILImageType:
|
|
"""Retrieves an image as PIL Image."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_path(self, image_name: str, thumbnail: bool = False) -> Path:
|
|
"""Gets the internal path to an image or thumbnail."""
|
|
pass
|
|
|
|
# TODO: We need to validate paths before starlette makes the FileResponse, else we get a
|
|
# 500 internal server error. I don't like having this method on the service.
|
|
@abstractmethod
|
|
def validate_path(self, path: str) -> bool:
|
|
"""Validates the path given for an image or thumbnail."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def save(
|
|
self,
|
|
image: PILImageType,
|
|
image_name: str,
|
|
metadata: Optional[MetadataField] = None,
|
|
workflow: Optional[WorkflowWithoutID] = None,
|
|
thumbnail_size: int = 256,
|
|
) -> None:
|
|
"""Saves an image and a 256x256 WEBP thumbnail. Returns a tuple of the image name, thumbnail name, and created timestamp."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def delete(self, image_name: str) -> None:
|
|
"""Deletes an image and its thumbnail (if one exists)."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_workflow(self, image_name: str) -> Optional[WorkflowWithoutID]:
|
|
"""Gets the workflow of an image."""
|
|
pass
|