S-18 JM 代理与登录配置
这个提交存在于:
父节点
c0eeb169e2
当前提交
cc95a67f3f
共有 7 个文件被更改,包括 213 次插入 和 8 次删除
|
|
@ -46,6 +46,12 @@ CBZ 内部会包含:
|
||||||
POST /api/v1/libraries/{libraryId}/scan
|
POST /api/v1/libraries/{libraryId}/scan
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 代理与登录
|
||||||
|
|
||||||
|
- 代理:配置 `jm_proxy.mode`。常用值是 `system`、`clash`、`v2ray`、`custom`。
|
||||||
|
- 自定义代理:`jm_proxy.mode=custom`,再填写 `jm_proxy.proxy_url`,例如 `127.0.0.1:7890`。
|
||||||
|
- 登录:默认不需要。少部分敏感题材可能需要登录,此时填写 `jm_avs_cookie`,只填浏览器 Cookie 中 `AVS` 的值。
|
||||||
|
|
||||||
## 测试
|
## 测试
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,39 @@
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"default": 20
|
"default": 20
|
||||||
},
|
},
|
||||||
|
"jm_proxy": {
|
||||||
|
"description": "JM 下载代理配置。",
|
||||||
|
"type": "object",
|
||||||
|
"items": {
|
||||||
|
"mode": {
|
||||||
|
"description": "代理模式:inherit=不写入配置,none=禁用代理,system=系统代理,clash/v2ray=jmcomic 内置快捷代理,custom=自定义代理。",
|
||||||
|
"type": "string",
|
||||||
|
"default": "inherit",
|
||||||
|
"options": ["inherit", "none", "system", "clash", "v2ray", "custom"]
|
||||||
|
},
|
||||||
|
"proxy_url": {
|
||||||
|
"description": "custom 模式下的统一代理,例如 127.0.0.1:7890 或 http://127.0.0.1:7890。",
|
||||||
|
"type": "string",
|
||||||
|
"default": ""
|
||||||
|
},
|
||||||
|
"http_proxy": {
|
||||||
|
"description": "custom 模式下单独指定 HTTP 代理;留空时使用 proxy_url。",
|
||||||
|
"type": "string",
|
||||||
|
"default": ""
|
||||||
|
},
|
||||||
|
"https_proxy": {
|
||||||
|
"description": "custom 模式下单独指定 HTTPS 代理;留空时使用 proxy_url。",
|
||||||
|
"type": "string",
|
||||||
|
"default": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"jm_avs_cookie": {
|
||||||
|
"description": "可选 JM 登录 Cookie,只填写 AVS 的值。大部分本子不需要登录,敏感题材可能需要。",
|
||||||
|
"type": "string",
|
||||||
|
"default": "",
|
||||||
|
"invisible": true
|
||||||
|
},
|
||||||
"jm_domains": {
|
"jm_domains": {
|
||||||
"description": "jmcomic 域名列表,按优先级排序。",
|
"description": "jmcomic 域名列表,按优先级排序。",
|
||||||
"type": "list",
|
"type": "list",
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,45 @@ komga.password
|
||||||
POST /api/v1/libraries/{libraryId}/scan
|
POST /api/v1/libraries/{libraryId}/scan
|
||||||
```
|
```
|
||||||
|
|
||||||
## 4. 命令
|
## 4. JM 代理与登录
|
||||||
|
|
||||||
|
jmcomic 的代理配置位于 `client.postman.meta_data.proxies`。本插件在 WebUI 中提供 `jm_proxy`:
|
||||||
|
|
||||||
|
```text
|
||||||
|
jm_proxy.mode: inherit
|
||||||
|
```
|
||||||
|
|
||||||
|
可选值:
|
||||||
|
|
||||||
|
```text
|
||||||
|
inherit 不写入代理配置,沿用 jmcomic 默认行为
|
||||||
|
none 写入 proxies: null,禁用代理
|
||||||
|
system 使用系统代理
|
||||||
|
clash 使用 jmcomic 内置 clash 快捷代理
|
||||||
|
v2ray 使用 jmcomic 内置 v2ray 快捷代理
|
||||||
|
custom 使用自定义代理
|
||||||
|
```
|
||||||
|
|
||||||
|
自定义代理示例:
|
||||||
|
|
||||||
|
```text
|
||||||
|
jm_proxy.mode: custom
|
||||||
|
jm_proxy.proxy_url: 127.0.0.1:7890
|
||||||
|
```
|
||||||
|
|
||||||
|
如果 HTTP 和 HTTPS 代理不同:
|
||||||
|
|
||||||
|
```text
|
||||||
|
jm_proxy.mode: custom
|
||||||
|
jm_proxy.http_proxy: 127.0.0.1:7890
|
||||||
|
jm_proxy.https_proxy: 127.0.0.1:7890
|
||||||
|
```
|
||||||
|
|
||||||
|
JM 下载大部分本子不需要登录。少部分敏感题材可能需要登录态,此时只需要配置 `jm_avs_cookie`,填写浏览器 Cookie 中 `AVS` 的值即可。
|
||||||
|
|
||||||
|
注意:AVS Cookie 和访问域名有关,使用的 JM 域名要和 Cookie 来源域名一致。
|
||||||
|
|
||||||
|
## 5. 命令
|
||||||
|
|
||||||
```text
|
```text
|
||||||
/jm download <id>
|
/jm download <id>
|
||||||
|
|
@ -88,15 +126,17 @@ POST /api/v1/libraries/{libraryId}/scan
|
||||||
/jm cleanup
|
/jm cleanup
|
||||||
```
|
```
|
||||||
|
|
||||||
## 5. 故障排查
|
## 6. 故障排查
|
||||||
|
|
||||||
- 插件无法加载:检查 `requirements.txt` 是否安装成功。
|
- 插件无法加载:检查 `requirements.txt` 是否安装成功。
|
||||||
- 下载后没有文件:检查 `jm_domains` 是否可用,或降低 `jm_batch_count`。
|
- 下载后没有文件:检查 `jm_domains` 是否可用,或降低 `jm_batch_count`。
|
||||||
|
- 代理未生效:检查 `jm_proxy.mode`,custom 模式下确认代理端口可用。
|
||||||
|
- 登录后仍不可下载:确认 `jm_avs_cookie` 来自当前实际访问的 JM 域名。
|
||||||
- Komga 没有识别:确认 `archive_root` 是 Komga library 根目录,并手动执行 `/jm scan`。
|
- Komga 没有识别:确认 `archive_root` 是 Komga library 根目录,并手动执行 `/jm scan`。
|
||||||
- 文件发送失败:不同平台对文件消息支持不同;归档仍会保存在 `archive_root`。
|
- 文件发送失败:不同平台对文件消息支持不同;归档仍会保存在 `archive_root`。
|
||||||
- PDF 转换失败:确认 `PyPDF2` 已安装,或改用默认 `cbz`。
|
- PDF 转换失败:确认 `PyPDF2` 已安装,或改用默认 `cbz`。
|
||||||
|
|
||||||
## 6. 本地测试
|
## 7. 本地测试
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python -m unittest discover -s tests
|
python -m unittest discover -s tests
|
||||||
|
|
|
||||||
2
main.py
2
main.py
|
|
@ -97,6 +97,8 @@ class JMDownloadPlugin(Star):
|
||||||
f"并发任务数:{self.settings.max_concurrent_tasks}",
|
f"并发任务数:{self.settings.max_concurrent_tasks}",
|
||||||
f"下载重试次数:{self.settings.download_retry_count}",
|
f"下载重试次数:{self.settings.download_retry_count}",
|
||||||
f"进度提示间隔:{self.settings.progress_interval_seconds} 秒",
|
f"进度提示间隔:{self.settings.progress_interval_seconds} 秒",
|
||||||
|
f"JM 代理模式:{self.settings.jm_proxy.mode}",
|
||||||
|
f"JM 登录 Cookie:{'已配置' if self.settings.jm_avs_cookie else '未配置'}",
|
||||||
f"发送归档文件:{self.settings.send_archive_file}",
|
f"发送归档文件:{self.settings.send_archive_file}",
|
||||||
f"临时目录保留:{self.settings.cleanup_retention_days} 天",
|
f"临时目录保留:{self.settings.cleanup_retention_days} 天",
|
||||||
f"Komga 自动扫描:{self.settings.komga.enabled}",
|
f"Komga 自动扫描:{self.settings.komga.enabled}",
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,14 @@ class JMDownloadService:
|
||||||
return str(title).strip()
|
return str(title).strip()
|
||||||
|
|
||||||
def _write_jmcomic_config(self, config_path: Path, download_dir: Path) -> None:
|
def _write_jmcomic_config(self, config_path: Path, download_dir: Path) -> None:
|
||||||
|
config = self._build_jmcomic_config(download_dir)
|
||||||
|
config_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
config_path.write_text(
|
||||||
|
yaml.safe_dump(config, allow_unicode=True, sort_keys=False),
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
|
||||||
|
def _build_jmcomic_config(self, download_dir: Path) -> dict:
|
||||||
config = {
|
config = {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"dir_rule": {
|
"dir_rule": {
|
||||||
|
|
@ -248,8 +256,14 @@ class JMDownloadService:
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
config_path.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
config_path.write_text(
|
meta_data = {}
|
||||||
yaml.safe_dump(config, allow_unicode=True, sort_keys=False),
|
should_write_proxy, proxy_value = self.settings.jm_proxy.to_jmcomic_value()
|
||||||
encoding="utf-8",
|
if should_write_proxy:
|
||||||
)
|
meta_data["proxies"] = proxy_value
|
||||||
|
if self.settings.jm_avs_cookie:
|
||||||
|
meta_data["cookies"] = {"AVS": self.settings.jm_avs_cookie}
|
||||||
|
if meta_data:
|
||||||
|
config["client"]["postman"] = {"meta_data": meta_data}
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,43 @@ DEFAULT_JM_DOMAINS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class JmProxySettings:
|
||||||
|
mode: str = "inherit"
|
||||||
|
proxy_url: str = ""
|
||||||
|
http_proxy: str = ""
|
||||||
|
https_proxy: str = ""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_config(cls, config: dict[str, Any]) -> "JmProxySettings":
|
||||||
|
mode = str(config.get("mode", "inherit")).strip().lower()
|
||||||
|
if mode not in {"inherit", "none", "system", "clash", "v2ray", "custom"}:
|
||||||
|
mode = "inherit"
|
||||||
|
return cls(
|
||||||
|
mode=mode,
|
||||||
|
proxy_url=str(config.get("proxy_url", "")).strip(),
|
||||||
|
http_proxy=str(config.get("http_proxy", "")).strip(),
|
||||||
|
https_proxy=str(config.get("https_proxy", "")).strip(),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_jmcomic_value(self) -> tuple[bool, str | dict[str, str] | None]:
|
||||||
|
if self.mode == "inherit":
|
||||||
|
return False, None
|
||||||
|
if self.mode == "none":
|
||||||
|
return True, None
|
||||||
|
if self.mode in {"system", "clash", "v2ray"}:
|
||||||
|
return True, self.mode
|
||||||
|
|
||||||
|
http_proxy = self.http_proxy or self.proxy_url
|
||||||
|
https_proxy = self.https_proxy or self.proxy_url
|
||||||
|
if http_proxy and https_proxy and http_proxy != https_proxy:
|
||||||
|
return True, {"http": http_proxy, "https": https_proxy}
|
||||||
|
proxy = http_proxy or https_proxy
|
||||||
|
if not proxy:
|
||||||
|
return False, None
|
||||||
|
return True, proxy
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class KomgaSettings:
|
class KomgaSettings:
|
||||||
enabled: bool = False
|
enabled: bool = False
|
||||||
|
|
@ -62,6 +99,8 @@ class PluginSettings:
|
||||||
progress_interval_seconds: int = 30
|
progress_interval_seconds: int = 30
|
||||||
max_concurrent_tasks: int = 1
|
max_concurrent_tasks: int = 1
|
||||||
jm_batch_count: int = 20
|
jm_batch_count: int = 20
|
||||||
|
jm_proxy: JmProxySettings = JmProxySettings()
|
||||||
|
jm_avs_cookie: str = ""
|
||||||
jm_domains: list[str] | None = None
|
jm_domains: list[str] | None = None
|
||||||
komga: KomgaSettings = KomgaSettings()
|
komga: KomgaSettings = KomgaSettings()
|
||||||
|
|
||||||
|
|
@ -82,6 +121,10 @@ class PluginSettings:
|
||||||
if not isinstance(jm_domains, list) or not jm_domains:
|
if not isinstance(jm_domains, list) or not jm_domains:
|
||||||
jm_domains = DEFAULT_JM_DOMAINS
|
jm_domains = DEFAULT_JM_DOMAINS
|
||||||
|
|
||||||
|
jm_proxy_config = config.get("jm_proxy", {})
|
||||||
|
if not isinstance(jm_proxy_config, dict):
|
||||||
|
jm_proxy_config = {}
|
||||||
|
|
||||||
komga_config = config.get("komga", {})
|
komga_config = config.get("komga", {})
|
||||||
if not isinstance(komga_config, dict):
|
if not isinstance(komga_config, dict):
|
||||||
komga_config = {}
|
komga_config = {}
|
||||||
|
|
@ -119,6 +162,8 @@ class PluginSettings:
|
||||||
_int_value(config.get("max_concurrent_tasks"), 1),
|
_int_value(config.get("max_concurrent_tasks"), 1),
|
||||||
),
|
),
|
||||||
jm_batch_count=max(1, _int_value(config.get("jm_batch_count"), 20)),
|
jm_batch_count=max(1, _int_value(config.get("jm_batch_count"), 20)),
|
||||||
|
jm_proxy=JmProxySettings.from_config(jm_proxy_config),
|
||||||
|
jm_avs_cookie=str(config.get("jm_avs_cookie", "")).strip(),
|
||||||
jm_domains=[str(domain).strip() for domain in jm_domains if str(domain).strip()],
|
jm_domains=[str(domain).strip() for domain in jm_domains if str(domain).strip()],
|
||||||
komga=KomgaSettings.from_config(komga_config),
|
komga=KomgaSettings.from_config(komga_config),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
65
tests/test_jmcomic_config.py
普通文件
65
tests/test_jmcomic_config.py
普通文件
|
|
@ -0,0 +1,65 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from tests.helpers import install_runtime_stubs
|
||||||
|
|
||||||
|
install_runtime_stubs()
|
||||||
|
|
||||||
|
from services.download import JMDownloadService # noqa: E402
|
||||||
|
from services.settings import JmProxySettings, PluginSettings # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
class JmComicConfigTest(unittest.TestCase):
|
||||||
|
def test_default_proxy_is_not_written(self) -> None:
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
settings = PluginSettings.from_config({}, Path(temp_dir) / "data")
|
||||||
|
config = JMDownloadService(settings)._build_jmcomic_config(Path(temp_dir) / "downloads")
|
||||||
|
|
||||||
|
self.assertNotIn("postman", config["client"])
|
||||||
|
|
||||||
|
def test_proxy_modes_convert_to_jmcomic_values(self) -> None:
|
||||||
|
self.assertEqual(JmProxySettings(mode="none").to_jmcomic_value(), (True, None))
|
||||||
|
self.assertEqual(JmProxySettings(mode="system").to_jmcomic_value(), (True, "system"))
|
||||||
|
self.assertEqual(JmProxySettings(mode="clash").to_jmcomic_value(), (True, "clash"))
|
||||||
|
self.assertEqual(JmProxySettings(mode="v2ray").to_jmcomic_value(), (True, "v2ray"))
|
||||||
|
self.assertEqual(JmProxySettings(mode="custom").to_jmcomic_value(), (False, None))
|
||||||
|
self.assertEqual(
|
||||||
|
JmProxySettings(mode="custom", proxy_url="127.0.0.1:7890").to_jmcomic_value(),
|
||||||
|
(True, "127.0.0.1:7890"),
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
JmProxySettings(
|
||||||
|
mode="custom",
|
||||||
|
http_proxy="http://127.0.0.1:7890",
|
||||||
|
https_proxy="http://127.0.0.1:7891",
|
||||||
|
).to_jmcomic_value(),
|
||||||
|
(
|
||||||
|
True,
|
||||||
|
{
|
||||||
|
"http": "http://127.0.0.1:7890",
|
||||||
|
"https": "http://127.0.0.1:7891",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_proxy_and_avs_cookie_are_written_to_postman_metadata(self) -> None:
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
settings = PluginSettings.from_config(
|
||||||
|
{
|
||||||
|
"jm_proxy": {"mode": "custom", "proxy_url": "127.0.0.1:7890"},
|
||||||
|
"jm_avs_cookie": "avs-token",
|
||||||
|
},
|
||||||
|
Path(temp_dir) / "data",
|
||||||
|
)
|
||||||
|
config = JMDownloadService(settings)._build_jmcomic_config(Path(temp_dir) / "downloads")
|
||||||
|
|
||||||
|
meta_data = config["client"]["postman"]["meta_data"]
|
||||||
|
self.assertEqual(meta_data["proxies"], "127.0.0.1:7890")
|
||||||
|
self.assertEqual(meta_data["cookies"], {"AVS": "avs-token"})
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
正在加载…
添加表格
在新工单中引用