15m44v 续: 修附件替换串 \u 残留+前端授权态误判
- gh_api.php ghSyncCreate 替换串终版:'\u📎 附件\1' 的 \u 在 PHP 单引号里是字面 反斜杠+u, 传给 PCRE 替换串 \u=下个字符转大写, 对 emoji 无效→吐出字面 u (issue body 出现 'u 📎 附件1')。 改 "\U0001F4CE 附件\1" (emoji 直接字面值, 只留 \1 反向引用, 无任何大小写/转义指令)。 - api/gh_cfg.php 加 gh_authorized 字段: 带 token 反解玩家名查 gh_auth_tokens, /user 验活(破CF缓存), 有效→true。根治前端'重新进表单 URL 无 gh_ok 就误判未授权'。 - player.php loadGhCfg 改 fetch gh_cfg.php?token= 按 gh_authorized 显示已授权态(不再只靠 URL 参数)。 commit 083f760/9b081a6
This commit is contained in:
+32
-2
@@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* 15m44m: 工单前端判断「GitHub issue 同步是否启用」的懒重载端点。
|
* 15m44m: 工单前端判断「GitHub issue 同步是否启用」的懒重载端点。
|
||||||
* 返回 {gh_enabled:bool, gh_repo:string}。前端进工单表单时 fetch,
|
* 返回 {gh_enabled:bool, gh_repo:string, gh_authorized:bool}。前端进工单表单时 fetch:
|
||||||
* - gh_enabled=true 才显示「授权 GitHub 工单同步」按钮
|
* - gh_enabled=true 才显示「授权 GitHub 工单同步」按钮
|
||||||
* - gh_repo 用于按钮文案(caoyuanwiki)
|
* - gh_repo 用于按钮文案(caoyuanwiki)
|
||||||
* 无 token(配置非敏感)。
|
* - 15m44v: gh_authorized=true 时前端显示「已授权」态(不再误判为未授权)
|
||||||
|
* 带 ?token= 时反解玩家名查 gh_auth_tokens 是否已有有效 token。
|
||||||
*/
|
*/
|
||||||
while (ob_get_level() > 0) { @ob_end_clean(); }
|
while (ob_get_level() > 0) { @ob_end_clean(); }
|
||||||
ob_start();
|
ob_start();
|
||||||
@@ -14,9 +15,38 @@ header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
|||||||
|
|
||||||
require_once __DIR__ . '/../core.php';
|
require_once __DIR__ . '/../core.php';
|
||||||
require_once __DIR__ . '/../lsky.php';
|
require_once __DIR__ . '/../lsky.php';
|
||||||
|
require_once __DIR__ . '/../gh_api.php'; // 15m44v: ghApiRequest(验活 token)
|
||||||
|
|
||||||
$cfg = loadImgJson();
|
$cfg = loadImgJson();
|
||||||
|
$ghAuthorized = false;
|
||||||
|
|
||||||
|
// ★ 15m44v: 带 token 时查该玩家是否已有【有效】GitHub token(验活,非只看存没存)。
|
||||||
|
// 前端 loadGhCfg 改成 fetch('gh_cfg.php?token=' + TOKEN) 后,据此显示「已授权」态,
|
||||||
|
// 根治"重新进表单 URL 无 gh_ok 就误判为未授权"的老问题。
|
||||||
|
$probeTk = isset($_GET['token']) ? trim((string)$_GET['token']) : '';
|
||||||
|
if ($cfg['gh_enabled'] && $probeTk !== '') {
|
||||||
|
$pi = validateTokenSilent($probeTk);
|
||||||
|
$probePlayer = ($pi && !empty($pi['player'])) ? $pi['player'] : '';
|
||||||
|
if ($probePlayer !== '') {
|
||||||
|
try {
|
||||||
|
$db = getDB();
|
||||||
|
$db->exec("CREATE TABLE IF NOT EXISTS gh_auth_tokens (
|
||||||
|
player_name TEXT PRIMARY KEY, gh_login TEXT DEFAULT '',
|
||||||
|
access_token TEXT NOT NULL, updated_at INTEGER NOT NULL)");
|
||||||
|
$st = $db->prepare("SELECT access_token FROM gh_auth_tokens WHERE player_name = :p AND access_token != '' ORDER BY updated_at DESC LIMIT 1");
|
||||||
|
$st->bindValue(':p', $probePlayer, SQLITE3_TEXT);
|
||||||
|
$trow = $st->execute()->fetchArray(SQLITE3_ASSOC);
|
||||||
|
if ($trow && !empty($trow['access_token'])) {
|
||||||
|
// 验活:/user 加唯一 query 破 CF 缓存(同 gh_oauth.php 15m44v 修法)
|
||||||
|
$v = ghApiRequest('GET', '/user?x=nocache_' . (int)microtime(true) . mt_rand(100000, 999999), null, $trow['access_token']);
|
||||||
|
$ghAuthorized = !empty($v['ok']);
|
||||||
|
}
|
||||||
|
} catch (\Throwable $e) { $ghAuthorized = false; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
success([
|
success([
|
||||||
'gh_enabled' => !empty($cfg['gh_enabled']),
|
'gh_enabled' => !empty($cfg['gh_enabled']),
|
||||||
'gh_repo' => isset($cfg['gh_repo']) ? $cfg['gh_repo'] : '',
|
'gh_repo' => isset($cfg['gh_repo']) ? $cfg['gh_repo'] : '',
|
||||||
|
'gh_authorized' => $ghAuthorized,
|
||||||
], 'ok');
|
], 'ok');
|
||||||
|
|||||||
+7
-5
@@ -135,17 +135,19 @@ function ghSyncCreate($ticketId, $player, $title, $description, $images = [], $t
|
|||||||
// 仍带着 [图片N]。旧版 ghSyncCreate 直接把原始描述塞进 issue body,导致 GitHub 上
|
// 仍带着 [图片N]。旧版 ghSyncCreate 直接把原始描述塞进 issue body,导致 GitHub 上
|
||||||
// 显示「abc[图片1]」占位符没被替换(用户实测附件不对根因)。附件名统一在末尾集中
|
// 显示「abc[图片1]」占位符没被替换(用户实测附件不对根因)。附件名统一在末尾集中
|
||||||
// 展示一次,描述里的 [图片N] 只标记"此处有附件"不重复展示文件名。
|
// 展示一次,描述里的 [图片N] 只标记"此处有附件"不重复展示文件名。
|
||||||
// ★ 15m44v: 替换串从 '\U📎 附件\1\E' 改为 '\u📎 附件\1'。
|
// ★ 15m44v 修:替换串几经踩坑——
|
||||||
// 根因:PCRE 的 \U…\E 是【大小写转换开关】(\U=后续全大写,\E=恢复正常),
|
// 初版 '\U📎 附件\1\E':\U..\E 是 PCRE【大小写转换开关】(\U=全大写\E=恢复),夹在 emoji 后误转 CJK。
|
||||||
// 夹在 emoji 之后会把中文「附件」误转成小写/乱码;且大小写开关对 CJK 无意义。
|
// 二版 '\u📎 附件\1':PHP 单引号里 \u 是【字面 反斜杠+u】(单引号只认 \' 和 \\),
|
||||||
// \u=单个字符转大写(对 CJK/emoji 恒等无副作用),\U/\E 全删,替换串干净。
|
// 传给 PCRE 替换串的 \u = "下个字符转大写"指令,对 emoji 无效→吐出字面 u(issue body 出现 "u 📎 附件1")。
|
||||||
|
// 终版:替换串不含任何大小写/转义指令,emoji 直接写字面值,只留 \1 反向引用(数字组号)。
|
||||||
|
// PCRE 替换串里 \1 = 引用捕获组 1(占位符里的数字 N),emoji「📎」直接是普通字符,无副作用。
|
||||||
$desc = (string)$description;
|
$desc = (string)$description;
|
||||||
$hasAttach = false;
|
$hasAttach = false;
|
||||||
foreach ((is_array($images) ? $images : []) as $u) {
|
foreach ((is_array($images) ? $images : []) as $u) {
|
||||||
if (is_string($u)) { $hasAttach = true; break; }
|
if (is_string($u)) { $hasAttach = true; break; }
|
||||||
}
|
}
|
||||||
if ($hasAttach) {
|
if ($hasAttach) {
|
||||||
$desc = preg_replace('/\[图片(\d+)\]/u', '\u📎 附件\1', $desc);
|
$desc = preg_replace('/\[图片(\d+)\]/u', "\U0001F4CE 附件\1", $desc);
|
||||||
}
|
}
|
||||||
// ★ 15m44v: 建单诊断日志(写 /plugin/gh_sync.log),记录替换后描述 + 附件,定位占位符未替换。
|
// ★ 15m44v: 建单诊断日志(写 /plugin/gh_sync.log),记录替换后描述 + 附件,定位占位符未替换。
|
||||||
ghLog('create ticket=' . $ticketId . ' has_attach=' . ($hasAttach ? 'y' : 'n')
|
ghLog('create ticket=' . $ticketId . ' has_attach=' . ($hasAttach ? 'y' : 'n')
|
||||||
|
|||||||
+12
-6
@@ -3974,7 +3974,9 @@ if ($currentVersion !== $BUILD_VERSION) {
|
|||||||
const box = document.getElementById('ghTicketAuth');
|
const box = document.getElementById('ghTicketAuth');
|
||||||
if (!box) return;
|
if (!box) return;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(API + 'gh_cfg.php');
|
// ★ 15m44v: fetch 带 token,后端据此验活该玩家 GitHub token,返回 gh_authorized。
|
||||||
|
// 根治"重新进表单 URL 无 gh_ok 就误判未授权"——现在只要 token 真有效就显示已授权。
|
||||||
|
const res = await fetch(API + 'gh_cfg.php?token=' + encodeURIComponent(TOKEN));
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const d = (data.success && data.data) ? data.data : null;
|
const d = (data.success && data.data) ? data.data : null;
|
||||||
if (d && d.gh_enabled) {
|
if (d && d.gh_enabled) {
|
||||||
@@ -3985,13 +3987,17 @@ if ($currentVersion !== $BUILD_VERSION) {
|
|||||||
// ★ 15m44n 互斥二选一:GitHub 模式附件全走 issue,不走图床 → 切附件区文案
|
// ★ 15m44n 互斥二选一:GitHub 模式附件全走 issue,不走图床 → 切附件区文案
|
||||||
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,原图请在 GitHub issue 页直接上传。';
|
||||||
|
// ★ 15m44v: 按 gh_authorized 显示授权态(不再只靠 URL gh_ok 参数)
|
||||||
|
const isAuthed = d.gh_authorized === true
|
||||||
|
|| new URLSearchParams(location.search).get('gh_ok') === '1';
|
||||||
|
if (isAuthed) {
|
||||||
|
if (txt) txt.textContent = '✅ GitHub 已授权,工单+附件会自动同步到 issue';
|
||||||
|
if (sub) sub.textContent = '当前账号 token 有效,工单提交将自动同步到 GitHub issue';
|
||||||
|
if (btn) { btn.textContent = '重新授权'; btn.onclick = gotoGhOAuth; }
|
||||||
|
} else {
|
||||||
if (txt) txt.textContent = '⛓️ GitHub 工单同步(' + (d.gh_repo || '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;
|
if (btn) { btn.textContent = '授权 GitHub'; btn.onclick = gotoGhOAuth; }
|
||||||
// URL 带 gh_ok=1(刚从 GitHub 回跳)→ 提示已授权
|
|
||||||
if (new URLSearchParams(location.search).get('gh_ok') === '1') {
|
|
||||||
if (txt) txt.textContent = '✅ GitHub 已授权,工单+附件会自动同步到 issue';
|
|
||||||
if (btn) { btn.textContent = '重新授权'; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) { /* 端点不存在/未部署 → 不显示 */ }
|
} catch (e) { /* 端点不存在/未部署 → 不显示 */ }
|
||||||
|
|||||||
Reference in New Issue
Block a user