81 行
2.7 KiB
Python
81 行
2.7 KiB
Python
"""Configuration loading helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from database.db_helper import REPO_ROOT, load_config_payload
|
|
|
|
|
|
@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:
|
|
payload = load_config_payload(self.config_path)
|
|
if not payload:
|
|
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:
|
|
resolved = Path(path)
|
|
if not resolved.is_absolute():
|
|
resolved = REPO_ROOT / resolved
|
|
return resolved
|