2023-05-17 09:13:53 +00:00
|
|
|
import os
|
|
|
|
|
2024-07-03 16:20:35 +00:00
|
|
|
from invokeai.app.services.urls.urls_base import UrlServiceBase
|
2023-05-17 09:13:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LocalUrlService(UrlServiceBase):
|
2024-03-06 18:15:33 +00:00
|
|
|
def __init__(self, base_url: str = "api/v1", base_url_v2: str = "api/v2"):
|
2023-05-17 09:13:53 +00:00
|
|
|
self._base_url = base_url
|
2024-03-06 18:15:33 +00:00
|
|
|
self._base_url_v2 = base_url_v2
|
2023-05-17 09:13:53 +00:00
|
|
|
|
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-07-31 08:16:52 +00:00
|
|
|
return f"{self._base_url}/images/i/{image_basename}/thumbnail"
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-07-31 08:16:52 +00:00
|
|
|
return f"{self._base_url}/images/i/{image_basename}/full"
|
2024-03-06 03:57:05 +00:00
|
|
|
|
|
|
|
def get_model_image_url(self, model_key: str) -> str:
|
2024-03-06 19:05:27 +00:00
|
|
|
return f"{self._base_url_v2}/models/i/{model_key}/image"
|
2024-08-07 13:58:27 +00:00
|
|
|
|
|
|
|
def get_style_preset_image_url(self, style_preset_id: str) -> str:
|
|
|
|
return f"{self._base_url}/style_presets/i/{style_preset_id}/image"
|