修复(半自动履约): 拆分虎牙账号与角色身份并恢复CK注入

This commit is contained in:
yml
2026-11-19 14:41:57 +08:00
parent 7f74772dab
commit b9dadf2e02
36 changed files with 2208 additions and 878 deletions
@@ -31,6 +31,7 @@ import {
} from './weibo-connector-client.js'
import { WEIBO_TICKET_PREFIX } from './weibo-native/weibo-native-connector.js'
import { querySemiAutoTraces } from './semi-auto-trace.js'
import { isHuyaRoleToken } from './binding-role-id.js'
import { getAccountBindingPolicy } from '../account-binding/platform-policy.js'
import {
appendTaskEvent,
@@ -87,7 +88,7 @@ export async function listAdminSemiAutoTasks(input: Record<string, unknown> = {}
params.push(`%${keyword.replace(/[\\%_]/g, '\\$&')}%`)
const p = `$${params.length}`
conditions.push(
`(o.platform_order_id ILIKE ${p} OR oi.sku_name ILIKE ${p} OR oi.sku_code ILIKE ${p} OR task.huya_uid ILIKE ${p} OR task.bind_game_role ILIKE ${p})`,
`(o.platform_order_id ILIKE ${p} OR oi.sku_name ILIKE ${p} OR oi.sku_code ILIKE ${p} OR task.huya_uid ILIKE ${p} OR task.bind_game_role ILIKE ${p} OR task.pending_bind_game_role ILIKE ${p})`,
)
}
const where = conditions.join(' AND ')
@@ -141,11 +142,12 @@ export async function getAdminSemiAutoTask(taskIdInput: unknown) {
)
return {
task: mapTask(task),
// 管理端详情直接复用与客户页相同的三项比对口径,避免出现第二套判定。
// 管理端详情直接复用与客户页相同的角色核对口径。
comparison: compareBindingRole(task, {
bindGameRole: task.bind_game_role,
bindGameRoleId: task.bind_game_role_id,
bindGameChannel: task.bind_game_channel,
bindGameRole: task.pending_bind_game_role || task.bind_game_role,
bindGameRoleToken: task.pending_bind_game_role_token || task.bind_game_role_token,
bindGameChannel: task.pending_bind_game_channel || task.bind_game_channel,
platformGameRoleUid: task.platform_game_role_uid,
}),
events: events.rows.map((event) => ({
id: Number(event.id),
@@ -398,6 +400,14 @@ const BINDING_STATUSES = new Set<BindingStatus>([
'failed',
'expired',
])
const ROLE_IDENTITY_SOURCES = new Set([
'',
'huya_outer_current',
'huya_inner_pending',
'legacy_account_uid_fallback',
'manual',
])
const VERIFICATION_BASES = new Set(['', 'role_name_zone', 'platform_numeric_uid', 'manual'])
function parseSnapshotStatus<T extends string>(value: unknown, allowed: Set<T>, label: string): T {
const status = String(value || '').trim() as T
@@ -470,8 +480,71 @@ export async function applySemiAutoTaskStateSnapshot(
const nickname = String(input.platformNickname ?? input.platform_nickname ?? '').trim()
const bindGameAccount = String(input.bindGameAccount ?? input.bind_game_account ?? '').trim()
const bindGameRole = String(input.bindGameRole ?? input.bind_game_role ?? '').trim()
const bindGameRoleId = String(input.bindGameRoleId ?? input.bind_game_role_id ?? '').trim()
const legacyRoleId = String(input.bindGameRoleId ?? input.bind_game_role_id ?? '').trim()
const bindGameRoleToken = String(
input.bindGameRoleToken ??
input.bind_game_role_token ??
(isHuyaRoleToken(legacyRoleId) ? legacyRoleId : ''),
).trim()
const platformGameRoleUid = String(
input.platformGameRoleUid ?? input.platform_game_role_uid ?? '',
).trim()
const bindGameChannel = String(input.bindGameChannel ?? input.bind_game_channel ?? '').trim()
const pendingBindGameAccount = String(
input.pendingBindGameAccount ?? input.pending_bind_game_account ?? '',
).trim()
const pendingBindGameRole = String(
input.pendingBindGameRole ?? input.pending_bind_game_role ?? '',
).trim()
const pendingBindGameRoleToken = String(
input.pendingBindGameRoleToken ?? input.pending_bind_game_role_token ?? '',
).trim()
const pendingBindGameChannel = String(
input.pendingBindGameChannel ?? input.pending_bind_game_channel ?? '',
).trim()
const roleIdentitySource = String(
input.roleIdentitySource ?? input.role_identity_source ?? '',
).trim()
const verificationBasis = String(
input.verificationBasis ?? input.verification_basis ?? '',
).trim()
if (bindGameRoleToken && !isHuyaRoleToken(bindGameRoleToken)) {
throw createHttpError('虎牙平台角色 token 格式无效', {
statusCode: 400,
errorCode: 'semi_auto_snapshot_role_token_invalid',
})
}
if (pendingBindGameRoleToken && !isHuyaRoleToken(pendingBindGameRoleToken)) {
throw createHttpError('虎牙待确认角色 token 格式无效', {
statusCode: 400,
errorCode: 'semi_auto_snapshot_pending_role_token_invalid',
})
}
if (platformGameRoleUid && !/^\d+$/.test(platformGameRoleUid)) {
throw createHttpError('平台游戏角色 UID 格式无效', {
statusCode: 400,
errorCode: 'semi_auto_snapshot_platform_role_uid_invalid',
})
}
const effectiveHuyaUid = uid || task.huya_uid
if (platformGameRoleUid && effectiveHuyaUid && platformGameRoleUid === effectiveHuyaUid) {
throw createHttpError('平台游戏角色 UID 不能复用虎牙账号 UID', {
statusCode: 400,
errorCode: 'semi_auto_snapshot_platform_role_uid_reused',
})
}
if (!ROLE_IDENTITY_SOURCES.has(roleIdentitySource)) {
throw createHttpError('角色身份来源无效', {
statusCode: 400,
errorCode: 'semi_auto_snapshot_role_source_invalid',
})
}
if (!VERIFICATION_BASES.has(verificationBasis)) {
throw createHttpError('角色核验依据无效', {
statusCode: 400,
errorCode: 'semi_auto_snapshot_verification_basis_invalid',
})
}
const message = String(input.message ?? input.lastError ?? input.last_error ?? '')
.trim()
.slice(0, 1000)
@@ -485,8 +558,15 @@ export async function applySemiAutoTaskStateSnapshot(
platform_nickname = CASE WHEN $6 <> '' THEN $6 ELSE platform_nickname END,
bind_game_account = CASE WHEN $7 <> '' THEN $7 ELSE bind_game_account END,
bind_game_role = CASE WHEN $8 <> '' THEN $8 ELSE bind_game_role END,
bind_game_role_id = CASE WHEN $9 <> '' THEN $9 ELSE bind_game_role_id END,
bind_game_role_token = CASE WHEN $9 <> '' THEN $9 ELSE bind_game_role_token END,
bind_game_channel = CASE WHEN $10 <> '' THEN $10 ELSE bind_game_channel END,
pending_bind_game_account = $12,
pending_bind_game_role = $13,
pending_bind_game_role_token = $14,
pending_bind_game_channel = $15,
platform_game_role_uid = $18,
role_identity_source = CASE WHEN $16 <> '' THEN $16 ELSE role_identity_source END,
verification_basis = CASE WHEN $17 <> '' THEN $17 ELSE verification_basis END,
authenticated_at = CASE
WHEN $2 = 'authenticated' THEN COALESCE(authenticated_at, NOW())
ELSE authenticated_at
@@ -508,9 +588,16 @@ export async function applySemiAutoTaskStateSnapshot(
nickname,
bindGameAccount,
bindGameRole,
bindGameRoleId,
bindGameRoleToken,
bindGameChannel,
message,
pendingBindGameAccount,
pendingBindGameRole,
pendingBindGameRoleToken,
pendingBindGameChannel,
roleIdentitySource,
verificationBasis,
platformGameRoleUid,
],
)
if (