15m44n 互斥二选一: type=GitHub时附件全走issue不走图床(easy关+@gh占位名+前端切文案)
This commit is contained in:
@@ -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']));
|
||||
|
||||
+10
-2
@@ -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)];
|
||||
|
||||
@@ -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 值,
|
||||
|
||||
+6
-3
@@ -3944,7 +3944,7 @@ if ($currentVersion !== $BUILD_VERSION) {
|
||||
改成自定义"选择图片"按钮触发隐藏 input, 缩略图列表用 URL.createObjectURL 本地预览 -->
|
||||
<input type="file" id="ticketImg" accept=".png,.jpg,.jpeg,image/png,image/jpeg" multiple style="display:none" onchange="uploadTicketImage(this)">
|
||||
<button class="btn" style="font-size:13px;padding:6px 12px" onclick="document.getElementById('ticketImg').click()">📷 选择图片</button>
|
||||
<p style="color:var(--dim);font-size:12px;margin-top:4px">仅支持 png / jpg,单张 ≤ 2048K,最多 3 张;提交工单时一并上传图床(暂存阶段不上传 API)</p>
|
||||
<p id="ticketImgHint" style="color:var(--dim);font-size:12px;margin-top:4px">仅支持 png / jpg,单张 ≤ 2048K,最多 3 张;提交工单时一并上传图床(暂存阶段不上传 API)</p>
|
||||
<div id="ticketImgList" style="display:flex;gap:8px;flex-wrap:wrap;margin-top:8px"></div>
|
||||
<p id="ticketImgMsg" style="color:var(--red);font-size:12px;margin-top:4px"></p></div>
|
||||
<!-- 15m44m: GitHub issue 同步授权区(gh_enabled=true 才显示,由 renderTicketCreate 后 loadGhCfg 填充) -->
|
||||
@@ -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 = '重新授权'; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user