feat: 完成配置与SQLite地基
- 新增 appconfig 配置读写、默认值、AI 参数和敏感字段拦截 - 新增 SQLite batches/accounts/tasks schema 与阶段写库函数 - 校准本地配置、DB、图片和登录态文件的 gitignore 规则 - 更新任务看板、模块合约、当前状态和进度记录
This commit is contained in:
+38
-24
@@ -9,22 +9,34 @@
|
||||
- 凭证:登录态在 user-data-dir;密码、AI Key 本地明文存于 config/DB;`config.json`、`config/ai_models.json`、`cmshopee.db`、`chrome_user_data_dir/`、`images/` 必须 gitignore;UI 打码显示,不出现在日志/导出。
|
||||
- 失败处理:抛带中文说明的异常或返回状态字段;GUI 负责提示,不静默吞错。
|
||||
|
||||
## appconfig 模块(`app/appconfig.py`,待建)
|
||||
## appconfig 模块(`app/appconfig.py`,已建)
|
||||
|
||||
读写 `config.json`(schema 见 [架构 5.1](04-architecture.md))。
|
||||
|
||||
```python
|
||||
class ConfigError(RuntimeError): ...
|
||||
default_config() -> dict
|
||||
load_config(path="config.json") -> dict # 不存在则写默认
|
||||
chrome_path() -> str
|
||||
user_data_root() -> str
|
||||
image_dir() -> str
|
||||
db_path() -> str
|
||||
ai_config() -> dict # default_text_model/default_image_model/
|
||||
save_config(config, path="config.json") -> dict
|
||||
update_config(updates, path="config.json") -> dict
|
||||
chrome_path(config=None) -> str
|
||||
user_data_root(config=None) -> str
|
||||
image_dir(config=None) -> str
|
||||
db_path(config=None) -> str
|
||||
default_debug_port(config=None) -> int
|
||||
debug_port_range(config=None) -> tuple # (start, end)
|
||||
cdp_ready_timeout(config=None) -> int
|
||||
ai_config(config=None) -> dict # default_text_model/default_image_model/
|
||||
# title_concurrency/image_concurrency/retry/jpg_quality/
|
||||
# resolution/resolution_timeouts
|
||||
response_timeout() -> int # = resolution_timeouts[resolution](返回超时,随分辨率)
|
||||
response_timeout(config=None) -> int # = resolution_timeouts[resolution](返回超时,随分辨率)
|
||||
```
|
||||
|
||||
# AI 模型清单 config/ai_models.json(含本地明文密钥;CRUD 由 ⑤ 设置)
|
||||
`config.json` 不保存 AI Key;写入 `api_key` / `*_key` / `token` / `password` 等敏感字段时抛 `ConfigError`。AI Key 留给 `config/ai_models.json`。
|
||||
|
||||
AI 模型清单(`config/ai_models.json`,含本地明文密钥;CRUD 由 ⑤ 设置,T-005 待建):
|
||||
|
||||
```python
|
||||
list_ai_models(category=None) -> list[dict] # category=text/image 过滤;含 connect_timeout_seconds 等
|
||||
add_ai_model(model) -> None # name 唯一校验
|
||||
update_ai_model(name, **fields) -> None
|
||||
@@ -33,32 +45,34 @@ test_ai_model(name) -> dict # 「测试连接」:用 key/url
|
||||
get_model(name) -> dict # 返回模型定义,含 api_key(调用方不得写日志)
|
||||
```
|
||||
|
||||
## db 模块(`app/db.py`,待建)
|
||||
## db 模块(`app/db.py`,已建)
|
||||
|
||||
SQLite 读写,表见 [架构 5.2](04-architecture.md)。
|
||||
|
||||
```python
|
||||
class DbError(RuntimeError): ...
|
||||
Batch / Account / Task # dataclass,字段同 SQLite schema
|
||||
connect(path=None) -> sqlite3.Connection # 设置 foreign_keys/WAL/busy_timeout/synchronous/row_factory
|
||||
init_db(path)
|
||||
create_batch(file_paths, note=None) -> str
|
||||
get_batch(batch_id) -> Batch|None
|
||||
list_batches(status=None) -> list[Batch]
|
||||
update_batch(batch_id, **fields) -> None
|
||||
init_db(path=None)
|
||||
create_batch(file_paths, note=None, path=None) -> str
|
||||
get_batch(batch_id, path=None) -> Batch|None
|
||||
list_batches(status=None, path=None) -> list[Batch]
|
||||
update_batch(batch_id, **fields) -> None # 支持 status/note/source_files_json
|
||||
# 账号
|
||||
list_accounts() -> list[Account]
|
||||
get_account_by_alias(alias) -> Account|None
|
||||
list_accounts(path=None) -> list[Account]
|
||||
get_account_by_alias(alias, path=None) -> Account|None
|
||||
add_account(account_name, alias, region_host, debug_port, password=None, note=None) -> Account
|
||||
update_account(alias, **fields) -> None
|
||||
update_account(alias, **fields) -> None # 支持账号展示字段、端口、密码、note、last_login_at
|
||||
delete_account(alias) -> None
|
||||
# 任务 / 各阶段结果
|
||||
insert_tasks(batch_id, rows) -> int # 写输入列;rows 含 source_file_abs/source_sheet/source_row/row_key
|
||||
list_tasks(batch_id=None, stage=None, status=None, alias=None) -> list[Task]
|
||||
insert_tasks(batch_id, rows, path=None) -> int # 写输入列;rows 含 source_file_abs/source_sheet/source_row/row_key
|
||||
list_tasks(batch_id=None, stage=None, status=None, alias=None, path=None) -> list[Task]
|
||||
mark_running(task_id, phase) -> None
|
||||
mark_failed(task_id, phase, error) -> None
|
||||
mark_skipped(task_id, reason) -> None
|
||||
set_collected(task_id, old_title, old_cover_path) -> None # stage=collected,status=success, attempts+1
|
||||
set_generated(task_id, new_title, new_cover_path) -> None # stage=generated,status=success, attempts+1
|
||||
set_applied(task_id, committed, error=None) -> None # stage=applied,status=success/failed, attempts+1
|
||||
mark_failed(task_id, phase, error) -> None # status=failed,stage 不前进,对应 attempts+1
|
||||
mark_skipped(task_id, reason) -> None # status=skipped,stage 不前进
|
||||
set_collected(task_id, old_title, old_cover_path) -> None # stage=collected,status=success,collect_attempts+1
|
||||
set_generated(task_id, new_title, new_cover_path) -> None # stage=generated,status=success,generate_attempts+1
|
||||
set_applied(task_id, committed, error=None) -> None # 成功 stage=applied;失败 status=failed 且 stage 不前进
|
||||
```
|
||||
|
||||
`stage` 表示最后成功业务阶段(imported→collected→generated→applied);`status` 表示当前处理结果(pending/running/success/failed/skipped/cancelled)。任意步失败写 `last_error` 且 `status=failed`,`stage` 不前进。无 confirmed 阶段。
|
||||
|
||||
Reference in New Issue
Block a user