15m44v 附件走图床嵌真实图片: GitHub 模式附件也传图床拿URL, issue body 用 ![](url) 显示实际图片(图床没配才回退 @gh: 占位)

This commit is contained in:
ypsdf1
2026-11-25 16:42:57 +08:00
parent df37f3ae32
commit 8543f8e573
4 changed files with 34 additions and 14 deletions
+14 -8
View File
@@ -293,15 +293,21 @@ function uploadTicketFiles() {
return $GLOBALS['__ticket_dbg_urls']; return $GLOBALS['__ticket_dbg_urls'];
} }
// ★ 15m44n 互斥二选一(用户定调):type=GitHub 时附件【全走 issue,不走图床】。 // ★ 15m44n 互斥 → ★ 15m44v 变更(用户定调"附件要显示实际图片"):
// 不上传图床(easy=false),只记录附件文件名(带 @gh: 标记),由前端把"附件"以 // GitHub 模式下附件【也走图床】拿真实 URL(图床配了真值时),ghSyncCreate 把 URL 用
// 占位文本塞进工单描述,ghSyncCreate 同步到 issue body。玩家真要贴图,直接贴 // markdown 图片语法 ![](url) 嵌进 issue body,GitHub 会把外链图片转存到自家 CDN 正常显示。
// 图床外链或 GitHub issue 的拖拽上传。 // 这样 PHP 后台 + GitHub 都显示实际图片,不再是"只显示文件名"。
// 仅当图床没配(baseurl/key 空)时才回退 @gh: 文件名占位(玩家去 GitHub 手动传)。
if (!empty($cfg['gh_enabled'])) { if (!empty($cfg['gh_enabled'])) {
$out = ghTicketFileNames(); // 图床可用 → 不拦截,落到下方 uploadTicketFiles 走 easyUploadFile 拿真实 URL
$GLOBALS['__ticket_dbg_uploaded'] = count($out); // 图床没配 → 回退 ghTicketFileNames(@gh: 占位,仅记文件名)
$GLOBALS['__ticket_dbg_urls'] = $out; if ($cfg['baseurl'] === '' || $cfg['key'] === '' || !$cfg['attach_enabled']) {
return $out; $out = ghTicketFileNames();
$GLOBALS['__ticket_dbg_uploaded'] = count($out);
$GLOBALS['__ticket_dbg_urls'] = $out;
return $out;
}
// 图床可用:继续往下走(不 return),附件传图床拿真实 URL
} }
$maxImages = max(1, (int)($cfg['max_images'] ?? 3)); $maxImages = max(1, (int)($cfg['max_images'] ?? 3));
$maxBytes = max(1, (int)($cfg['max_size_mb'] ?? 2)) * 1024 * 1024; $maxBytes = max(1, (int)($cfg['max_size_mb'] ?? 2)) * 1024 * 1024;
+6 -1
View File
@@ -165,9 +165,14 @@ function ghSyncCreate($ticketId, $player, $title, $description, $images = [], $t
$bodyParts[] = ''; $bodyParts[] = '';
foreach ($images as $i => $u) { foreach ($images as $i => $u) {
if (is_string($u) && strpos($u, '@gh:') === 0) { if (is_string($u) && strpos($u, '@gh:') === 0) {
// @gh:附件图N:文件名.png → 取冒号后的文件名展示 // @gh:附件图N:文件名(图床没配时的回退占位)→ 只显示文件名,让玩家去 GitHub 传原图
$label = str_replace('@gh:', '', $u); $label = str_replace('@gh:', '', $u);
$bodyParts[] = '📎 附件' . ($i + 1) . ':`' . $label . '`(需在 GitHub issue 上传原图)'; $bodyParts[] = '📎 附件' . ($i + 1) . ':`' . $label . '`(需在 GitHub issue 上传原图)';
} elseif (is_string($u) && (strpos($u, 'http://') === 0 || strpos($u, 'https://') === 0)) {
// ★ 15m44v: 真实图床 URL → markdown 图片语法嵌进 issue body。
// GitHub 会把 ![](外链) 的图片自动转存到 user-images.githubusercontent.com CDN,
// issue 页正常显示实际图片(不再只是文件名)。
$bodyParts[] = '附件' . ($i + 1) . ':' . "\n" . '![' . $u . '](' . $u . ')';
} else { } else {
$bodyParts[] = '附件图' . ($i + 1) . ':' . $u; $bodyParts[] = '附件图' . ($i + 1) . ':' . $u;
} }
+12 -3
View File
@@ -236,16 +236,25 @@ function easyUploadFile($tmpPath, $origName) {
*/ */
function ticketImageUpload($tmpPath, $origName) { function ticketImageUpload($tmpPath, $origName) {
$cfg = loadImgJson(); $cfg = loadImgJson();
// 本期只做 EasyImages2.0(用户明令 GitHub issue 先不做) // 15m44v: 图床可用(baseurl+key 配了真值)就传图床拿真实 URL —— 无论是否 GitHub 模式。
// 旧版(15m44n 互斥铁律)GitHub 模式附件全走 issue 不走图床(easy=false 直接报"图床未配置"),
// 导致 PHP 后台 + GitHub 都只显示文件名。用户 2026-11-25 定调"附件要显示实际图片",
// 故 GitHub 模式附件【也走图床】:传 EasyImages2.0 拿真实 URL,ghSyncCreate 把 URL 用
// markdown 图片语法 ![](url) 嵌进 issue body(GitHub 会把外链图片转存到自家 CDN 正常显示)。
// 只要 baseurl+key 配了(图床可用)就传图床;图床没配才走兜底/报错。
if ($cfg['easy']) { if ($cfg['easy']) {
return easyUploadFile($tmpPath, $origName); return easyUploadFile($tmpPath, $origName);
} }
// easy=false 但 baseurl/key 配了(GitHub 模式 + 图床可用):也传图床拿 URL
// (loadImgJson 的 easy 在 gh_type 时被置 false,但图床真值仍可传 —— 15m44v 放开)
if ($cfg['baseurl'] !== '' && $cfg['key'] !== '' && $cfg['attach_enabled']) {
return easyUploadFile($tmpPath, $origName);
}
// easy 未配置且非 GitHub(含 gh/GH/GitHub/github 任意写法):兜底旧兰空图床(lsky_keys.php 还在时) // easy 未配置且非 GitHub(含 gh/GH/GitHub/github 任意写法):兜底旧兰空图床(lsky_keys.php 还在时)
if (!$cfg['gh_type'] && $cfg['type'] === '') { if (!$cfg['gh_type'] && $cfg['type'] === '') {
return lskyUploadFile($tmpPath, $origName); return lskyUploadFile($tmpPath, $origName);
} }
return ['ok' => false, 'msg' => '图床未配置:img.json 的 baseurl/key 缺失(GitHub 模式附件走 issue,不走图床)']; return ['ok' => false, 'msg' => '图床未配置:img.json 的 baseurl/key 缺失(GitHub 模式附件走图床拿 URL 嵌 issue)'];
return ['ok' => false, 'msg' => '图床未配置:GitHub 模式附件走 issue,不走图床(loadImgJson.easy=false)'];
} }
/** 加载 lsky_keys.php(只加载一次),并检查必填项 */ /** 加载 lsky_keys.php(只加载一次),并检查必填项 */
+2 -2
View File
@@ -3984,9 +3984,9 @@ if ($currentVersion !== $BUILD_VERSION) {
const txt = document.getElementById('ghAuthText'); const txt = document.getElementById('ghAuthText');
const sub = document.getElementById('ghAuthSub'); const sub = document.getElementById('ghAuthSub');
const btn = document.getElementById('ghAuthBtn'); const btn = document.getElementById('ghAuthBtn');
// ★ 15m44n 互斥二选一:GitHub 模式附件全走 issue,不走图床 → 切附件区文案 // ★ 15m44v:GitHub 模式附件也走图床拿真实 URL,issue body 用 ![](url) 嵌图显示实际图片
const hint = document.getElementById('ticketImgHint'); const hint = document.getElementById('ticketImgHint');
if (hint) hint.textContent = '📎 GitHub 模式:附件随工单同步到 GitHub issue(不走图床)。选中的文件名会记入 issue,原图请在 GitHub issue 页直接上传。'; if (hint) hint.textContent = '📎 GitHub 模式:附件上传图床后随工单同步到 GitHub issue(issue 内显示实际图片,不再是文件名)。选中的图片会一并上传图床。';
// ★ 15m44v: 按 gh_authorized 显示授权态(不再只靠 URL gh_ok 参数) // ★ 15m44v: 按 gh_authorized 显示授权态(不再只靠 URL gh_ok 参数)
const isAuthed = d.gh_authorized === true const isAuthed = d.gh_authorized === true
|| new URLSearchParams(location.search).get('gh_ok') === '1'; || new URLSearchParams(location.search).get('gh_ok') === '1';