2026-07-05 00:11:05 +08:00
|
|
|
"""Configuration loading helpers."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
2026-07-11 21:50:34 +08:00
|
|
|
from core.runtime_paths import resolve_config_path
|
|
|
|
|
from database.db_helper import load_config_payload
|
2026-07-05 00:11:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
|
class PluginConfig:
|
|
|
|
|
name: str = "astrbot_plugin_imagestudio"
|
|
|
|
|
display_name: str = "ImageStudio"
|
|
|
|
|
version: str = "3.0.0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
|
class StorageConfig:
|
|
|
|
|
images_path: str = "data/images"
|
|
|
|
|
thumbnails_path: str = "data/thumbnails"
|
|
|
|
|
materials_path: str = "data/materials"
|
|
|
|
|
styles_path: str = "data/styles"
|
|
|
|
|
archives_path: str = "data/archives"
|
|
|
|
|
temp_path: str = "data/temp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
|
class ImageStudioConfig:
|
|
|
|
|
plugin: PluginConfig = PluginConfig()
|
|
|
|
|
features: dict[str, bool] | None = None
|
|
|
|
|
storage: StorageConfig = StorageConfig()
|
|
|
|
|
|
|
|
|
|
def feature_flags(self) -> dict[str, bool]:
|
|
|
|
|
defaults = {
|
|
|
|
|
"quick_profile": True,
|
|
|
|
|
"workspace": True,
|
|
|
|
|
"material_library": True,
|
|
|
|
|
"wardrobe": True,
|
|
|
|
|
"api_discovery": True,
|
|
|
|
|
"private_companion_integration": False,
|
|
|
|
|
}
|
|
|
|
|
defaults.update(self.features or {})
|
|
|
|
|
return defaults
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ConfigService:
|
|
|
|
|
def __init__(self, config_path: str | Path = "config.yaml"):
|
|
|
|
|
self.config_path = _resolve_path(config_path)
|
|
|
|
|
|
|
|
|
|
def load(self) -> ImageStudioConfig:
|
2026-07-06 10:59:28 +08:00
|
|
|
payload = load_config_payload(self.config_path)
|
|
|
|
|
if not payload:
|
2026-07-05 00:11:05 +08:00
|
|
|
return ImageStudioConfig()
|
|
|
|
|
plugin = payload.get("plugin", {})
|
|
|
|
|
features = payload.get("features", {})
|
|
|
|
|
storage = payload.get("storage", {})
|
|
|
|
|
return ImageStudioConfig(
|
|
|
|
|
plugin=PluginConfig(
|
|
|
|
|
name=str(plugin.get("name", "astrbot_plugin_imagestudio")),
|
|
|
|
|
display_name=str(plugin.get("display_name", "ImageStudio")),
|
|
|
|
|
version=str(plugin.get("version", "3.0.0")),
|
|
|
|
|
),
|
|
|
|
|
features={key: bool(value) for key, value in features.items()},
|
|
|
|
|
storage=StorageConfig(
|
|
|
|
|
images_path=str(storage.get("images_path", "data/images")),
|
|
|
|
|
thumbnails_path=str(storage.get("thumbnails_path", "data/thumbnails")),
|
|
|
|
|
materials_path=str(storage.get("materials_path", "data/materials")),
|
|
|
|
|
styles_path=str(storage.get("styles_path", "data/styles")),
|
|
|
|
|
archives_path=str(storage.get("archives_path", "data/archives")),
|
|
|
|
|
temp_path=str(storage.get("temp_path", "data/temp")),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _resolve_path(path: str | Path) -> Path:
|
2026-07-11 21:50:34 +08:00
|
|
|
return resolve_config_path(path)
|