feat(cherry-tomato): 新增图片混淆/解混淆插件(小番茄)
Gilbert 曲线像素重排,可与网页版互解;`混淆` / `解混淆` 命令 (回复图片或图文同条消息发送),附 tests/test_cherry_tomato.py Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
968b3d1cfe
commit
fb15b976aa
9 files changed
+862
No files matched your search
@@ -0,0 +1,84 @@
|
||||
"""配置:按《插件配置文件标准》注册到统一 Web 管理台。
|
||||
|
||||
3 个配置项来源都是本模块常量:Web 保存后由 register_config_items 的
|
||||
setter(setattr 本模块)热更新、立即生效;重启后按 plugin_config.json
|
||||
已存值回退(读取一律走本模块 helper,不要在别处缓存值)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys as _sys
|
||||
from typing import Any
|
||||
|
||||
from hexi.web_hub.config_standard import register_config_items
|
||||
from hexi.web_hub.web_config import get_effective_value
|
||||
|
||||
_PLUGIN_ID = __package__ or __name__.rsplit(".", 1)[0]
|
||||
|
||||
# —— 可配置常量(来源为本模块) ——
|
||||
# 加密前超过该像素数则等比缩小(并在回复里提示已压缩)
|
||||
MAX_PIXELS = 8_000_000
|
||||
# 解混淆硬上限:解密不能缩放(缩了就永远解不出),超过直接拒绝
|
||||
DECRYPT_MAX_PIXELS = 16_000_000
|
||||
# 输出 JPEG 质量(1-95,网页版固定最高档 95)
|
||||
JPEG_QUALITY = 95
|
||||
|
||||
|
||||
def _as_int(key: str, default: int) -> int:
|
||||
value: Any = get_effective_value(_PLUGIN_ID, key, default)
|
||||
if value in (None, ""):
|
||||
return default
|
||||
try:
|
||||
return int(value)
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
|
||||
|
||||
def max_pixels() -> int:
|
||||
"""加密缩放阈值(像素数)。"""
|
||||
return _as_int("MAX_PIXELS", MAX_PIXELS)
|
||||
|
||||
|
||||
def decrypt_max_pixels() -> int:
|
||||
"""解混淆硬上限(像素数)。"""
|
||||
return _as_int("DECRYPT_MAX_PIXELS", DECRYPT_MAX_PIXELS)
|
||||
|
||||
|
||||
def jpeg_quality() -> int:
|
||||
"""输出 JPEG 质量。"""
|
||||
return _as_int("JPEG_QUALITY", JPEG_QUALITY)
|
||||
|
||||
|
||||
def register_config() -> None:
|
||||
register_config_items(
|
||||
_PLUGIN_ID,
|
||||
[
|
||||
{
|
||||
"key": "MAX_PIXELS",
|
||||
"label": "加密最大像素数",
|
||||
"type": "int",
|
||||
"default": MAX_PIXELS,
|
||||
"description": (
|
||||
"混淆前超过该像素数则等比缩小(回复里会提示已压缩)。"
|
||||
"默认 8000000(8MP)"
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "DECRYPT_MAX_PIXELS",
|
||||
"label": "解混淆像素上限",
|
||||
"type": "int",
|
||||
"default": DECRYPT_MAX_PIXELS,
|
||||
"description": (
|
||||
"解混淆不能缩放,超过该像素数直接拒绝。默认 16000000(16MP)"
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "JPEG_QUALITY",
|
||||
"label": "输出 JPEG 质量",
|
||||
"type": "int",
|
||||
"default": JPEG_QUALITY,
|
||||
"description": "1-95,默认 95(与网页版一致的最高档)。",
|
||||
},
|
||||
],
|
||||
store=_sys.modules[__name__],
|
||||
)
|
||||
Reference in new issue
Block a user