From c21b35c676a5a0909080c8eaf2f2479d7eb49622 Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Wed, 25 Nov 2026 13:05:06 +0800 Subject: [PATCH] =?UTF-8?q?15m44n=20=E4=BA=92=E6=96=A5=E4=BA=8C=E9=80=89?= =?UTF-8?q?=E4=B8=80:=20type=3DGitHub=E6=97=B6=E9=99=84=E4=BB=B6=E5=85=A8?= =?UTF-8?q?=E8=B5=B0issue=E4=B8=8D=E8=B5=B0=E5=9B=BE=E5=BA=8A(easy?= =?UTF-8?q?=E5=85=B3+@gh=E5=8D=A0=E4=BD=8D=E5=90=8D+=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E5=88=87=E6=96=87=E6=A1=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/ticket.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ gh_api.php | 12 ++++++++++-- lsky.php | 10 +++++----- player.php | 9 ++++++--- 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/api/ticket.php b/api/ticket.php index 0361503..a707787 100644 --- a/api/ticket.php +++ b/api/ticket.php @@ -249,6 +249,40 @@ function normalizeImageExt($ext) { * 避免「填单一半图片就进了图床 API」——只有真正点提交工单才转存。 * 单张校验逻辑(错误码/文件名清洗/大小/真实格式/后缀归一)与 ticketUploadImage 完全一致。 */ + +/** + * 15m44n: GitHub 模式下的附件处理 —— 不上传图床,只取文件名(带 @gh: 前缀标记)。 + * 返回 ['@gh:附件图1:xxx.png', '@gh:附件图2:yy.png', ...],供 ghSyncCreate 拼进 issue body。 + * 前端拿到 @gh: 开头的"URL"知道这是占位附件(非真实图床链接),渲染时显示为「附件名」而非图片。 + */ +function ghTicketFileNames() { + $cfg = loadImgJson(); + $maxImages = max(1, (int)($cfg['max_images'] ?? 3)); + // 兼容三种字段名(与 uploadTicketFiles 一致) + $files = null; + if (isset($_FILES['images[]']) && is_array($_FILES['images[]']) && !empty($_FILES['images[]']['name'])) { + $files = $_FILES['images[]']; + } elseif (isset($_FILES['images']) && is_array($_FILES['images'])) { + $files = $_FILES['images']; + if (!isset($files['name']) || !is_array($files['name'])) { + $files = ['name' => [$files['name'] ?? ''], 'tmp_name' => [$files['tmp_name'] ?? ''], 'size' => [$files['size'] ?? 0], 'error' => [$files['error'] ?? UPLOAD_ERR_NO_FILE]]; + } + } elseif (isset($_FILES['image']) && is_array($_FILES['image'])) { + $f = $_FILES['image']; + $files = ['name' => [$f['name'] ?? ''], 'tmp_name' => [$f['tmp_name'] ?? ''], 'size' => [$f['size'] ?? 0], 'error' => [$f['error'] ?? UPLOAD_ERR_NO_FILE]]; + } + if (empty($files) || !is_array($files) || empty($files['name'])) return []; + $out = []; + $n = 0; + for ($i = 0; $i < count($files['name']) && $n < $maxImages; $i++) { + if ((int)($files['error'][$i] ?? UPLOAD_ERR_NO_FILE) === UPLOAD_ERR_NO_FILE) continue; + $name = sanitizeImageFileName(basename((string)$files['name'][$i])); + if ($name === '') $name = 'attachment'; + $out[] = '@gh:附件图' . (++$n) . ':' . $name; + } + return $out; +} + function uploadTicketFiles() { // 15m44j: 每次 ticketCreate 前懒重载 img.json(不缓存),读最大图片数量/最大大小/后缀格式 $cfg = loadImgJson(); @@ -258,6 +292,17 @@ function uploadTicketFiles() { $GLOBALS['__ticket_dbg_urls'] = normalizeTicketImages(); return $GLOBALS['__ticket_dbg_urls']; } + + // ★ 15m44n 互斥二选一(用户定调):type=GitHub 时附件【全走 issue,不走图床】。 + // 不上传图床(easy=false),只记录附件文件名(带 @gh: 标记),由前端把"附件"以 + // 占位文本塞进工单描述,ghSyncCreate 同步到 issue body。玩家真要贴图,直接贴 + // 图床外链或 GitHub issue 的拖拽上传。 + if (!empty($cfg['gh_enabled'])) { + $out = ghTicketFileNames(); + $GLOBALS['__ticket_dbg_uploaded'] = count($out); + $GLOBALS['__ticket_dbg_urls'] = $out; + return $out; + } $maxImages = max(1, (int)($cfg['max_images'] ?? 3)); $maxBytes = max(1, (int)($cfg['max_size_mb'] ?? 2)) * 1024 * 1024; $allowedExts = array_map('strtolower', (array)($cfg['allowed_exts'] ?? ['jpg','jpeg','png'])); diff --git a/gh_api.php b/gh_api.php index c146305..cf33581 100644 --- a/gh_api.php +++ b/gh_api.php @@ -105,13 +105,21 @@ function ghSyncCreate($ticketId, $player, $title, $description, $images = [], $t } $repo = $cfg['gh_repo']; $ghTitle = GH_TICKET_PREFIX . $ticketId . '] ' . $title; - // issue body:玩家名 + 描述 + 图片链接(GitHub issue 支持 markdown 图片) + // issue body:玩家名 + 描述 + 附件 + // - @gh: 开头 = GitHub 模式占位附件(只记文件名,不走图床)→ 显示为「📎 附件:文件名」 + // - http(s) = 真实图床外链 → 用 markdown 图片语法 $bodyParts = ['玩家:`' . $player . '`', '']; if ($description !== '') $bodyParts[] = $description; if (is_array($images) && count($images) > 0) { $bodyParts[] = ''; foreach ($images as $i => $u) { - $bodyParts[] = '附件图' . ($i + 1) . ':' . $u; + if (is_string($u) && strpos($u, '@gh:') === 0) { + // @gh:附件图N:文件名.png → 取冒号后的文件名展示 + $label = str_replace('@gh:', '', $u); + $bodyParts[] = '📎 附件' . ($i + 1) . ':`' . $label . '`(需在 GitHub issue 上传原图)'; + } else { + $bodyParts[] = '附件图' . ($i + 1) . ':' . $u; + } } } $payload = ['title' => mb_substr($ghTitle, 0, 100), 'body' => implode("\n", $bodyParts)]; diff --git a/lsky.php b/lsky.php index 6dffa08..fe7b2b7 100644 --- a/lsky.php +++ b/lsky.php @@ -99,11 +99,11 @@ function loadImgJson() { $cfg['attach_enabled'] = $attach; } - // easy = 走 EasyImages2.0(有 baseurl+key 且附件支持开) - // 15m44m 修正:不再被 模式.type=GitHub 压制。type=GitHub 时图床与 issue 同步并存—— - // 图片照走 EasyImages 图床,工单/回复【额外】同步 GitHub issue(用户 2026-11-25 实测反馈: - // type=GitHub 仍走内置工单不跳授权 → 根因是 easy 被压 + 前端根本没接授权按钮)。 - $cfg['easy'] = ($cfg['baseurl'] !== '' && $cfg['key'] !== '' && $cfg['attach_enabled']); + // easy = 走 EasyImages2.0 图床。★ 互斥二选一(用户 2026-11-25 定调): + // - type 留空 → 内置工单 + 附件走图床(easy=true) + // - type=GitHub → 附件全走 GitHub issue,图床关闭(easy=false) + // 两者不并存:选 GitHub 后图床彻底不碰,附件由 ghSyncCreate/ghSyncReply 塞进 issue body。 + $cfg['easy'] = ($cfg['type'] !== 'GitHub' && $cfg['baseurl'] !== '' && $cfg['key'] !== '' && $cfg['attach_enabled']); // GitHub issue 集成(15m44m 修正): // webhook_secret 挪进 repo 段(用户明令:仓库 img.json 模板里 webhook_secret 塞进 repo 值, diff --git a/player.php b/player.php index 984797f..7d7feaf 100644 --- a/player.php +++ b/player.php @@ -3944,7 +3944,7 @@ if ($currentVersion !== $BUILD_VERSION) { 改成自定义"选择图片"按钮触发隐藏 input, 缩略图列表用 URL.createObjectURL 本地预览 --> -

仅支持 png / jpg,单张 ≤ 2048K,最多 3 张;提交工单时一并上传图床(暂存阶段不上传 API)

+

仅支持 png / jpg,单张 ≤ 2048K,最多 3 张;提交工单时一并上传图床(暂存阶段不上传 API)

@@ -3982,12 +3982,15 @@ if ($currentVersion !== $BUILD_VERSION) { const txt = document.getElementById('ghAuthText'); const sub = document.getElementById('ghAuthSub'); const btn = document.getElementById('ghAuthBtn'); + // ★ 15m44n 互斥二选一:GitHub 模式附件全走 issue,不走图床 → 切附件区文案 + const hint = document.getElementById('ticketImgHint'); + if (hint) hint.textContent = '📎 GitHub 模式:附件随工单同步到 GitHub issue(不走图床)。选中的文件名会记入 issue,原图请在 GitHub issue 页直接上传。'; if (txt) txt.textContent = '⛓️ GitHub 工单同步(' + (d.gh_repo || 'issue') + ')'; - if (sub) sub.textContent = '提交工单时会同步到 GitHub issue,点右侧按钮授权你的 GitHub 账号'; + if (sub) sub.textContent = '工单与附件都同步到 GitHub issue,点右侧按钮授权你的 GitHub 账号'; if (btn) btn.onclick = gotoGhOAuth; // URL 带 gh_ok=1(刚从 GitHub 回跳)→ 提示已授权 if (new URLSearchParams(location.search).get('gh_ok') === '1') { - if (txt) txt.textContent = '✅ GitHub 已授权,工单会自动同步到 issue'; + if (txt) txt.textContent = '✅ GitHub 已授权,工单+附件会自动同步到 issue'; if (btn) { btn.textContent = '重新授权'; } } }