feat: store packaged user data under data directory

This commit is contained in:
chengma
2026-07-07 14:12:32 +08:00
parent caa04a9aa7
commit 148c4a73eb
33 changed files with 602 additions and 196 deletions
+4 -4
View File
@@ -48,8 +48,8 @@ class GenerateTab(QWidget):
self.db_path = _database_path(db_path, self.config)
self.status_callback = status_callback
self.open_accounts_callback = open_accounts_callback
self.title_prompt_path = title_prompt_path or prompts.TITLE_PROMPT_PATH
self.cover_prompts_dir = cover_prompts_dir or prompts.COVER_PROMPTS_DIR
self.title_prompt_path = title_prompt_path or appconfig.title_prompt_path(self.config)
self.cover_prompts_dir = cover_prompts_dir or appconfig.cover_prompts_dir(self.config)
self.current_cover_template = None
self.generate_worker = None
self.generate_thread = None
@@ -288,7 +288,7 @@ class GenerateTab(QWidget):
payload = {
key: value
for key, value in self.config.items()
if key not in {"config_path", "ai_models_path", "cmhub_config_path"}
if key not in {"config_path", "ai_models_path", "cmhub_config_path", "data_dir"}
}
payload["ai"] = ai_settings
try:
@@ -299,7 +299,7 @@ class GenerateTab(QWidget):
internal = {
key: value
for key, value in self.config.items()
if key in {"config_path", "ai_models_path", "cmhub_config_path"}
if key in {"config_path", "ai_models_path", "cmhub_config_path", "data_dir"}
}
self.config.clear()
self.config.update(saved)
+12 -19
View File
@@ -10,7 +10,7 @@ from ..workers import CMHubSettingsWorker as _RealCMHubSettingsWorker
PLAINTEXT_CMHUB_API_KEY_WARNING = (
"cmhub API Key 会以本地明文保存到 config/cmhub.json,仅供本机调用 cmhub 网关使用。"
"cmhub API Key 会以本地明文保存到 data/config/cmhub.json,仅供本机调用 cmhub 网关使用。"
"该文件已 gitignore,UI 打码显示,日志/导出不记录明文。"
)
@@ -23,7 +23,7 @@ def CMHubSettingsWorker(*args, **kwargs):
return _call_package_attr("CMHubSettingsWorker", _RealCMHubSettingsWorker, *args, **kwargs)
class SettingsTab(QWidget):
"""Tab 5: AI model definitions stored in config/ai_models.json."""
"""Tab 5: AI model definitions stored in data/config/ai_models.json."""
BACKEND_ITEMS = [("直连模型", "direct"), ("cmhub 网关", "cmhub")]
CATEGORY_ITEMS = [("文本", "text"), ("图像", "image")]
@@ -48,11 +48,11 @@ class SettingsTab(QWidget):
self.ai_models_path = (
ai_models_path
or self.config.get("ai_models_path")
or appconfig.AI_MODELS_PATH
or appconfig.ai_models_config_path(self.config)
)
self.cmhub_config_path = (
self.config.get("cmhub_config_path")
or self._default_cmhub_config_path(self.config_path)
or appconfig.cmhub_config_file_path(self.config)
)
self.status_callback = status_callback
self.models = []
@@ -546,15 +546,6 @@ class SettingsTab(QWidget):
self._cmhub_auto_refresh_done = True
self.refresh_cmhub_models()
def _default_cmhub_config_path(self, config_path):
if config_path and config_path != appconfig.CONFIG_PATH:
return os.path.join(
os.path.dirname(os.path.abspath(config_path)),
"config",
"cmhub.json",
)
return appconfig.CMHUB_CONFIG_PATH
def _on_backend_changed(self, index=None):
self.backend_combo.setVisible(False)
self.model_picker_panel.setVisible(False)
@@ -752,7 +743,7 @@ class SettingsTab(QWidget):
settings = {
key: value
for key, value in self.config.items()
if key not in {"config_path", "ai_models_path", "cmhub_config_path"}
if key not in {"config_path", "ai_models_path", "cmhub_config_path", "data_dir"}
}
settings.update(
{
@@ -799,6 +790,8 @@ class SettingsTab(QWidget):
internal["ai_models_path"] = self.ai_models_path
if self.cmhub_config_path != appconfig.CMHUB_CONFIG_PATH:
internal["cmhub_config_path"] = self.cmhub_config_path
if self.config.get("data_dir"):
internal["data_dir"] = self.config.get("data_dir")
self.config.clear()
self.config.update(saved)
self.config.update(internal)
@@ -847,9 +840,11 @@ class SettingsTab(QWidget):
)
self.jpg_quality_spin.setValue(int(ai_cfg.get("jpg_quality", 90) or 90))
self.chrome_path_edit.setText(appconfig.chrome_path(self.config))
self.user_data_root_edit.setText(appconfig.user_data_root(self.config))
self.image_dir_edit.setText(appconfig.image_dir(self.config))
self.db_path_edit.setText(appconfig.db_path(self.config))
self.user_data_root_edit.setText(
str(self.config.get("user_data_root", "chrome_user_data_dir") or "")
)
self.image_dir_edit.setText(str(self.config.get("image_dir", "images") or ""))
self.db_path_edit.setText(str(self.config.get("db_path", "cmshopee.db") or ""))
self.default_debug_port_spin.setValue(
int(appconfig.default_debug_port(self.config))
)
@@ -1318,5 +1313,3 @@ class SettingsTab(QWidget):
def _category_label(self, category):
return {"text": "文本", "image": "图像"}.get(category, category)