feat: 新增去水印失败自动回退配置、优化批量删除逻辑及错误处理机制

This commit is contained in:
TheSmallHanCat
2026-01-24 19:19:33 +08:00
parent d300f94683
commit ef49e3e670
5 changed files with 131 additions and 59 deletions

View File

@@ -105,6 +105,7 @@ class Database:
parse_method = "third_party"
custom_parse_url = None
custom_parse_token = None
fallback_on_failure = True # Default to True
if config_dict:
watermark_config = config_dict.get("watermark_free", {})
@@ -112,15 +113,16 @@ class Database:
parse_method = watermark_config.get("parse_method", "third_party")
custom_parse_url = watermark_config.get("custom_parse_url", "")
custom_parse_token = watermark_config.get("custom_parse_token", "")
fallback_on_failure = watermark_config.get("fallback_on_failure", True)
# Convert empty strings to None
custom_parse_url = custom_parse_url if custom_parse_url else None
custom_parse_token = custom_parse_token if custom_parse_token else None
await db.execute("""
INSERT INTO watermark_free_config (id, watermark_free_enabled, parse_method, custom_parse_url, custom_parse_token)
VALUES (1, ?, ?, ?, ?)
""", (watermark_free_enabled, parse_method, custom_parse_url, custom_parse_token))
INSERT INTO watermark_free_config (id, watermark_free_enabled, parse_method, custom_parse_url, custom_parse_token, fallback_on_failure)
VALUES (1, ?, ?, ?, ?, ?)
""", (watermark_free_enabled, parse_method, custom_parse_url, custom_parse_token, fallback_on_failure))
# Ensure cache_config has a row
cursor = await db.execute("SELECT COUNT(*) FROM cache_config")
@@ -251,6 +253,7 @@ class Database:
("parse_method", "TEXT DEFAULT 'third_party'"),
("custom_parse_url", "TEXT"),
("custom_parse_token", "TEXT"),
("fallback_on_failure", "BOOLEAN DEFAULT 1"),
]
for col_name, col_type in columns_to_add:
@@ -406,6 +409,7 @@ class Database:
parse_method TEXT DEFAULT 'third_party',
custom_parse_url TEXT,
custom_parse_token TEXT,
fallback_on_failure BOOLEAN DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
@@ -1048,10 +1052,11 @@ class Database:
return WatermarkFreeConfig(watermark_free_enabled=False, parse_method="third_party")
async def update_watermark_free_config(self, enabled: bool, parse_method: str = None,
custom_parse_url: str = None, custom_parse_token: str = None):
custom_parse_url: str = None, custom_parse_token: str = None,
fallback_on_failure: bool = None):
"""Update watermark-free configuration"""
async with aiosqlite.connect(self.db_path) as db:
if parse_method is None and custom_parse_url is None and custom_parse_token is None:
if parse_method is None and custom_parse_url is None and custom_parse_token is None and fallback_on_failure is None:
# Only update enabled status
await db.execute("""
UPDATE watermark_free_config
@@ -1063,9 +1068,10 @@ class Database:
await db.execute("""
UPDATE watermark_free_config
SET watermark_free_enabled = ?, parse_method = ?, custom_parse_url = ?,
custom_parse_token = ?, updated_at = CURRENT_TIMESTAMP
custom_parse_token = ?, fallback_on_failure = ?, updated_at = CURRENT_TIMESTAMP
WHERE id = 1
""", (enabled, parse_method or "third_party", custom_parse_url, custom_parse_token))
""", (enabled, parse_method or "third_party", custom_parse_url, custom_parse_token,
fallback_on_failure if fallback_on_failure is not None else True))
await db.commit()
# Cache config operations