2023-05-17 09:13:53 +00:00
|
|
|
import os
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
|
|
|
|
|
|
|
class UrlServiceBase(ABC):
|
2023-05-21 12:44:16 +00:00
|
|
|
"""Responsible for building URLs for resources."""
|
2023-05-17 09:13:53 +00:00
|
|
|
|
|
|
|
@abstractmethod
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_image_url(self, image_name: str, thumbnail: bool = False) -> str:
|
2023-05-21 12:44:16 +00:00
|
|
|
"""Gets the URL for an image or thumbnail."""
|
2023-05-17 09:13:53 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class LocalUrlService(UrlServiceBase):
|
|
|
|
def __init__(self, base_url: str = "api/v1"):
|
|
|
|
self._base_url = base_url
|
|
|
|
|
2023-06-14 11:40:09 +00:00
|
|
|
def get_image_url(self, image_name: str, thumbnail: bool = False) -> str:
|
2023-05-17 09:13:53 +00:00
|
|
|
image_basename = os.path.basename(image_name)
|
2023-05-23 12:57:29 +00:00
|
|
|
|
|
|
|
# These paths are determined by the routes in invokeai/app/api/routers/images.py
|
2023-05-21 12:44:16 +00:00
|
|
|
if thumbnail:
|
2023-06-14 11:40:09 +00:00
|
|
|
return f"{self._base_url}/images/{image_basename}/thumbnail"
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-07-12 15:14:22 +00:00
|
|
|
return f"{self._base_url}/images/{image_basename}/full"
|