fix: 钉钉桌面端通知二维码被裁剪
桌面端钉钉会把 Markdown 图片裁成横向区域,正方形二维码上下被裁掉。 二维码居中放到 3:2 白底画布上;网页中的二维码图片改用 object-fit 避免拉伸。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8f2f23682f
commit
6890f13aa9
@@ -454,6 +454,22 @@ def _upload_oss(config: dict, files: list[tuple[Path, str]]) -> dict[str, str]:
|
||||
return urls
|
||||
|
||||
|
||||
# 桌面端钉钉会把 Markdown 图片裁成约 1.4:1 的横向区域,正方形二维码上下被裁掉
|
||||
# (手机端完整显示)。居中放到 3:2 的白底画布上:桌面端裁掉的只是空白,
|
||||
# 手机端二维码仍占图片宽度的 2/3,不至于太小。
|
||||
_QR_CANVAS_RATIO = 1.5
|
||||
|
||||
|
||||
def _pad_to_wide(image):
|
||||
from PIL import Image
|
||||
|
||||
image = image.convert("RGB")
|
||||
width, height = image.size
|
||||
canvas = Image.new("RGB", (round(height * _QR_CANVAS_RATIO), height), "white")
|
||||
canvas.paste(image, ((canvas.width - width) // 2, 0))
|
||||
return canvas
|
||||
|
||||
|
||||
def publish_ipa(config: dict, ipa_path: Path, build_dir: Path) -> tuple[str, str]:
|
||||
"""发布 IPA,返回下载 URL 与二维码公开 URL。"""
|
||||
upload = config.get("_upload_config", {})
|
||||
@@ -487,7 +503,7 @@ def publish_ipa(config: dict, ipa_path: Path, build_dir: Path) -> tuple[str, str
|
||||
qr = qrcode.QRCode(box_size=5, border=4)
|
||||
qr.add_data(urls[".html"])
|
||||
qr.make(fit=True)
|
||||
qr.make_image(fill_color="black", back_color="white").save(qr_path)
|
||||
_pad_to_wide(qr.make_image(fill_color="black", back_color="white").get_image()).save(qr_path)
|
||||
urls.update(uploader(upload, [(qr_path, qr_remote)]))
|
||||
return urls[".html"], urls[".png"]
|
||||
|
||||
|
||||
@@ -513,7 +513,7 @@ const errorCategoryHint = (cat) => {
|
||||
.download-link { color: #1890ff; text-decoration: none; }
|
||||
.download-link:hover { text-decoration: underline; }
|
||||
.qr-section { text-align: center; padding: 16px; background: #fafafa; border-radius: 8px; }
|
||||
.qr-image { width: 180px; height: 180px; border: 1px solid #f0f0f0; border-radius: 8px; }
|
||||
.qr-image { width: 180px; height: 180px; object-fit: contain; border: 1px solid #f0f0f0; border-radius: 8px; }
|
||||
.qr-hint { margin-top: 8px; font-size: 13px; color: #999; }
|
||||
.error-msg { color: #ff4d4f; font-size: 13px; word-break: break-all; }
|
||||
|
||||
|
||||
@@ -570,7 +570,7 @@ const errorCategoryLabel = (cat) => {
|
||||
.download-link:disabled { color: #999; cursor: default; }
|
||||
.download-link:disabled:hover { text-decoration: none; }
|
||||
.text-muted { color: #999; font-size: 13px; }
|
||||
.qr-thumb { width: 40px; height: 40px; cursor: pointer; border-radius: 4px; border: 1px solid #e8e8e8; }
|
||||
.qr-thumb { width: 40px; height: 40px; object-fit: cover; cursor: pointer; border-radius: 4px; border: 1px solid #e8e8e8; }
|
||||
.qr-thumb:hover { border-color: #1890ff; }
|
||||
.btn-danger { color: #ff4d4f; border-color: #ff4d4f; }
|
||||
.btn-danger:hover { background: #ff4d4f; color: white; }
|
||||
@@ -580,7 +580,7 @@ const errorCategoryLabel = (cat) => {
|
||||
.qr-preview-modal .modal-header { display: flex; justify-content: center; align-items: center; position: relative; margin-bottom: 16px; }
|
||||
.qr-preview-modal .modal-close { position: absolute; right: 0; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 20px; cursor: pointer; color: #999; }
|
||||
.qr-preview-modal .modal-close:hover { color: #333; }
|
||||
.qr-preview-img { width: 260px; height: 260px; border: 1px solid #f0f0f0; border-radius: 8px; margin: 16px 0; }
|
||||
.qr-preview-img { width: 260px; height: 260px; object-fit: contain; border: 1px solid #f0f0f0; border-radius: 8px; margin: 16px 0; }
|
||||
.qr-preview-info { text-align: left; padding: 12px 16px; background: #fafafa; border-radius: 8px; }
|
||||
.qr-preview-info p { margin: 6px 0; font-size: 13px; color: #555; }
|
||||
</style>
|
||||
|
||||
@@ -87,6 +87,11 @@ def test_adhoc_distribution_uploads_qrcode(tmp_path):
|
||||
".ipa", ".plist", ".html", ".png",
|
||||
]
|
||||
|
||||
# 桌面端钉钉会把图片裁成横向比例,二维码需放在 3:2 的横向画布上
|
||||
from PIL import Image
|
||||
with Image.open(tmp_path / "build" / "distribution" / "100_2_0_0_dev_adhoc.png") as image:
|
||||
assert image.width == round(image.height * 1.5)
|
||||
|
||||
|
||||
def test_delete_adhoc_artifacts_deletes_all_remote_files():
|
||||
config = {"APPID": "100", "VERSION": "2.0.0.0", "SOURCE_BRANCH": "main", "BUILD_TYPE": "Ad_Hoc", "OSS_FLODER": "readoor"}
|
||||
|
||||
Reference in New Issue
Block a user