tidy(app): make workflow thumbnails base class an ABC, move it to own file

This commit is contained in:
psychedelicious
2025-03-03 15:37:10 +10:00
parent 04b96dd7b4
commit bf209663ac
3 changed files with 29 additions and 26 deletions

View File

@@ -0,0 +1,28 @@
from abc import ABC, abstractmethod
from pathlib import Path
from PIL import Image
class WorkflowThumbnailServiceBase(ABC):
"""Base class for workflow thumbnail services"""
@abstractmethod
def get_path(self, workflow_id: str) -> Path:
"""Gets the path to a workflow thumbnail"""
pass
@abstractmethod
def get_url(self, workflow_id: str) -> str | None:
"""Gets the URL of a workflow thumbnail"""
pass
@abstractmethod
def save(self, workflow_id: str, image: Image.Image) -> None:
"""Saves a workflow thumbnail"""
pass
@abstractmethod
def delete(self, workflow_id: str) -> None:
"""Deletes a workflow thumbnail"""
pass

View File

@@ -1,8 +1,3 @@
from pathlib import Path
from PIL import Image
class WorkflowThumbnailFileNotFoundException(Exception):
"""Raised when a workflow thumbnail file is not found"""
@@ -25,23 +20,3 @@ class WorkflowThumbnailFileDeleteException(Exception):
def __init__(self, message: str = "Workflow thumbnail file cannot be deleted"):
self.message = message
super().__init__(self.message)
class WorkflowThumbnailServiceBase:
"""Base class for workflow thumbnail services"""
def get_path(self, workflow_id: str) -> Path:
"""Gets the path to a workflow thumbnail"""
raise NotImplementedError
def get_url(self, workflow_id: str) -> str | None:
"""Gets the URL of a workflow thumbnail"""
raise NotImplementedError
def save(self, workflow_id: str, image: Image.Image) -> None:
"""Saves a workflow thumbnail"""
raise NotImplementedError
def delete(self, workflow_id: str) -> None:
"""Deletes a workflow thumbnail"""
raise NotImplementedError

View File

@@ -4,11 +4,11 @@ from PIL import Image
from PIL.Image import Image as PILImageType
from invokeai.app.services.invoker import Invoker
from invokeai.app.services.workflow_thumbnails.workflow_thumbnails_base import WorkflowThumbnailServiceBase
from invokeai.app.services.workflow_thumbnails.workflow_thumbnails_common import (
WorkflowThumbnailFileDeleteException,
WorkflowThumbnailFileNotFoundException,
WorkflowThumbnailFileSaveException,
WorkflowThumbnailServiceBase,
)
from invokeai.app.util.misc import uuid_string
from invokeai.app.util.thumbnails import make_thumbnail