This commit is contained in:
2026-01-23 15:02:19 -08:00
parent 523d9f839c
commit 797b5fee40
3 changed files with 58 additions and 42 deletions

View File

@@ -368,8 +368,8 @@ def save_config(
from SYS.database import db, save_config_value from SYS.database import db, save_config_value
with db.transaction(): with db.transaction():
# We want to clear and re-save or just update? # Replace the table contents so removed entries disappear from the DB.
# For simplicity, we'll iterate and update. db.execute("DELETE FROM config")
for key, value in config.items(): for key, value in config.items():
if key in ('store', 'provider', 'tool'): if key in ('store', 'provider', 'tool'):
if isinstance(value, dict): if isinstance(value, dict):
@@ -393,6 +393,7 @@ def save_config(
log(f"Failed to save config to database: {e}") log(f"Failed to save config to database: {e}")
cache_key = _make_cache_key(config_dir, filename, config_path) cache_key = _make_cache_key(config_dir, filename, config_path)
clear_config_cache()
_CONFIG_CACHE[cache_key] = config _CONFIG_CACHE[cache_key] = config

View File

@@ -544,14 +544,23 @@ class ConfigModal(ModalScreen):
self.editing_item_name = name self.editing_item_name = name
self.refresh_view() self.refresh_view()
elif action == "del": elif action == "del":
removed = False
if itype.startswith("store-"): if itype.startswith("store-"):
stype = itype.replace("store-", "") stype = itype.replace("store-", "")
if "store" in self.config_data and stype in self.config_data["store"]: if "store" in self.config_data and stype in self.config_data["store"]:
if name in self.config_data["store"][stype]: if name in self.config_data["store"][stype]:
del self.config_data["store"][stype][name] del self.config_data["store"][stype][name]
removed = True
elif itype == "provider": elif itype == "provider":
if "provider" in self.config_data and name in self.config_data["provider"]: if "provider" in self.config_data and name in self.config_data["provider"]:
del self.config_data["provider"][name] del self.config_data["provider"][name]
removed = True
if removed:
try:
self.save_all()
self.notify("Configuration saved!")
except Exception as exc:
self.notify(f"Save failed: {exc}", severity="error", timeout=10)
self.refresh_view() self.refresh_view()
elif bid == "add-store-btn": elif bid == "add-store-btn":
all_classes = _discover_store_classes() all_classes = _discover_store_classes()

View File

@@ -159,55 +159,61 @@ def run_git_pull(git: str, dest: Path) -> None:
subprocess.run([git, "-C", str(dest), "pull"], check=True) subprocess.run([git, "-C", str(dest), "pull"], check=True)
def _sanitize_store_name(name: str) -> str:
clean = "".join(ch for ch in name if ch.isalnum() or ch in {"-", "_"})
return clean or "hydrus"
def update_medios_config(hydrus_path: Path) -> bool: def update_medios_config(hydrus_path: Path) -> bool:
"""Attempt to update Medios-Macina root configuration with the hydrus path. """Attempt to update Medios-Macina root configuration with the hydrus path.
This helps link the newly installed Hydrus instance with the main project. We look for an existing hydrusnetwork backend entry and attach the gitclone
We check for medios.db first, then fall back to config.conf. path to that backend. This avoids hard-coded store names such as "hydrus" or
"hn-local" so users can pick their own alias.
""" """
script_dir = Path(__file__).resolve().parent script_dir = Path(__file__).resolve().parent
root = script_dir.parent root = script_dir.parent
db_path = root / "medios.db" db_path = root / "medios.db"
config_path = root / "config.conf"
hydrus_abs_path = str(hydrus_path.resolve()) hydrus_abs_path = str(hydrus_path.resolve())
# Try database first if not db_path.exists():
if db_path.exists(): return False
try: try:
import sqlite3 import sqlite3
import json
with sqlite3.connect(str(db_path), timeout=30.0) as conn: with sqlite3.connect(str(db_path), timeout=30.0) as conn:
conn.row_factory = sqlite3.Row conn.row_factory = sqlite3.Row
cur = conn.cursor() cur = conn.cursor()
# We want to set store.hydrusnetwork.hydrus.gitclone cur.execute(
# First check if hydrusnetwork store exists "SELECT DISTINCT item_name FROM config WHERE category='store' AND subtype='hydrusnetwork'"
cur.execute("SELECT 1 FROM config WHERE category='store' AND subtype='hydrusnetwork'") )
if cur.fetchone(): rows = [row[0] for row in cur.fetchall() if row[0]]
# Update or insert gitclone for the hydrus subtype
# Note: we assume the name is 'hydrus' or 'hn-local' or something. if not rows:
# Usually it's 'hydrus' if newly created. store_name = _sanitize_store_name(hydrus_path.name)
cur.execute( cur.execute(
"INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)", "INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)",
('store', 'hydrusnetwork', 'hydrus', 'gitclone', hydrus_abs_path) ('store', 'hydrusnetwork', store_name, 'name', store_name)
) )
else: rows = [store_name]
# Create the section
for name in rows:
cur.execute( cur.execute(
"INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)", "INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)",
('store', 'hydrusnetwork', 'hydrus', 'name', 'hydrus') ('store', 'hydrusnetwork', name, 'gitclone', hydrus_abs_path)
)
cur.execute(
"INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)",
('store', 'hydrusnetwork', 'hydrus', 'gitclone', hydrus_abs_path)
) )
conn.commit() conn.commit()
logging.info("✅ Linked Hydrus installation in medios.db (gitclone=\"%s\")", hydrus_abs_path) logging.info(
"✅ Linked Hydrus installation in medios.db for [%s] (gitclone=\"%s\")",
rows,
hydrus_abs_path,
)
return True return True
except Exception as e: except Exception as e:
logging.error("Failed to update medios.db: %s", e) logging.error("Failed to update medios.db: %s", e)
return False return False