修复(半自动注入): 平台首页占位值不再抢默认落地页
现象:本地注入浏览器仍跳到 https://www.huya.com/。 原因:开发 Mock 与人工配置把 semi_auto_config_json.browserTargets 默认写成平台首页, 而落地页解析里 browserTargets 优先级最高,导致公共策略的默认落地页永远不生效。 - platform-policy 新增 isPlatformHomepagePlaceholder / resolveBrowserTargetUrl: 平台首页(huya/weibo/douyu 首页及其带斜杠写法)一律视为「未配置」, 回落到各平台策略默认落地页;显式自定义 URL 仍然优先。 - createAdminBrowserSession 与 CK 导出的目标 URL 都走同一解析函数。 - 开发 Mock(后端默认值 + 后台造单页默认值)改用策略默认落地页, 不再产生新的首页占位配置。 - 前端 resolveInjectionTargetUrl 同步同一规则,并补后端 2 条、前端 1 条断言。
This commit is contained in:
@@ -2,7 +2,11 @@ import assert from 'node:assert/strict'
|
|||||||
import test from 'node:test'
|
import test from 'node:test'
|
||||||
|
|
||||||
import { buildServerZone, compareBindingIdentity, resolveServerZone } from './binding-identity.js'
|
import { buildServerZone, compareBindingIdentity, resolveServerZone } from './binding-identity.js'
|
||||||
import { getAccountBindingPolicy } from './platform-policy.js'
|
import {
|
||||||
|
getAccountBindingPolicy,
|
||||||
|
isPlatformHomepagePlaceholder,
|
||||||
|
resolveBrowserTargetUrl,
|
||||||
|
} from './platform-policy.js'
|
||||||
|
|
||||||
test('平台能力声明统一描述角色查询、确认与换绑方式', () => {
|
test('平台能力声明统一描述角色查询、确认与换绑方式', () => {
|
||||||
const huya = getAccountBindingPolicy('huya')
|
const huya = getAccountBindingPolicy('huya')
|
||||||
@@ -41,6 +45,28 @@ test('注入浏览器的默认落地页由公共策略声明,虎牙固定为
|
|||||||
assert.notEqual(getAccountBindingPolicy('douyu').defaultTargetUrl, huya.defaultTargetUrl)
|
assert.notEqual(getAccountBindingPolicy('douyu').defaultTargetUrl, huya.defaultTargetUrl)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('平台首页占位值视为未配置,注入落地页回落到策略默认', () => {
|
||||||
|
assert.equal(isPlatformHomepagePlaceholder('huya', 'https://www.huya.com/'), true)
|
||||||
|
assert.equal(isPlatformHomepagePlaceholder('huya', 'https://www.huya.com'), true)
|
||||||
|
assert.equal(isPlatformHomepagePlaceholder('weibo', 'https://weibo.com/'), true)
|
||||||
|
assert.equal(isPlatformHomepagePlaceholder('huya', 'https://m-shop.huya.com/points.html'), false)
|
||||||
|
assert.equal(isPlatformHomepagePlaceholder('huya', ''), false)
|
||||||
|
|
||||||
|
// 历史 Mock/配置写入的首页占位值不能再把落地页带偏。
|
||||||
|
assert.equal(
|
||||||
|
resolveBrowserTargetUrl('huya', ['https://www.huya.com/']),
|
||||||
|
getAccountBindingPolicy('huya').defaultTargetUrl,
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
resolveBrowserTargetUrl('huya', ['', 'https://www.huya.com/', 'https://custom.example.com/x']),
|
||||||
|
'https://custom.example.com/x',
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
resolveBrowserTargetUrl('weibo', ['https://weibo.com/']),
|
||||||
|
getAccountBindingPolicy('weibo').defaultTargetUrl,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('区服规范化为同一口径', () => {
|
test('区服规范化为同一口径', () => {
|
||||||
assert.equal(resolveServerZone('苹果(iOS) · QQ'), '苹果Q区')
|
assert.equal(resolveServerZone('苹果(iOS) · QQ'), '苹果Q区')
|
||||||
assert.equal(resolveServerZone('微信 安卓(android)'), '安卓V区')
|
assert.equal(resolveServerZone('微信 安卓(android)'), '安卓V区')
|
||||||
|
|||||||
@@ -66,6 +66,50 @@ const POLICIES: Record<AccountBindingPlatform, AccountBindingPolicy> = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 平台首页占位值。
|
||||||
|
*
|
||||||
|
* 历史开发 Mock 和人工配置把 `browserTargets` 默认填成平台首页,
|
||||||
|
* 这类值等于「没有配置落地页」,必须回落到 `defaultTargetUrl`,
|
||||||
|
* 否则注入浏览器会停在首页而不是兑换入口。
|
||||||
|
*/
|
||||||
|
const PLATFORM_HOMEPAGE_PLACEHOLDERS: Record<AccountBindingPlatform, readonly string[]> = {
|
||||||
|
huya: ['https://www.huya.com', 'https://www.huya.com/'],
|
||||||
|
douyu: ['https://www.douyu.com', 'https://www.douyu.com/'],
|
||||||
|
weibo: ['https://weibo.com', 'https://weibo.com/'],
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isPlatformHomepagePlaceholder(
|
||||||
|
platform: AccountBindingPlatform,
|
||||||
|
urlInput: unknown,
|
||||||
|
): boolean {
|
||||||
|
const url = String(urlInput || '')
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
if (!url) return false
|
||||||
|
return (PLATFORM_HOMEPAGE_PLACEHOLDERS[platform] || []).includes(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析注入浏览器要打开的落地页。
|
||||||
|
*
|
||||||
|
* 优先级:显式传入(后台点了自定义目标)→ SKU 配置的 `browserTargets`
|
||||||
|
* → 平台策略默认落地页。平台首页占位值一律视为「未配置」。
|
||||||
|
*/
|
||||||
|
export function resolveBrowserTargetUrl(
|
||||||
|
platform: AccountBindingPlatform,
|
||||||
|
candidates: Array<unknown>,
|
||||||
|
): string {
|
||||||
|
for (const candidate of candidates) {
|
||||||
|
const url = String(candidate || '').trim()
|
||||||
|
if (!url) continue
|
||||||
|
if (isPlatformHomepagePlaceholder(platform, url)) continue
|
||||||
|
if (!/^https?:\/\//i.test(url)) continue
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
return POLICIES[platform].defaultTargetUrl
|
||||||
|
}
|
||||||
|
|
||||||
export function getAccountBindingPolicy(platform: AccountBindingPlatform) {
|
export function getAccountBindingPolicy(platform: AccountBindingPlatform) {
|
||||||
return POLICIES[platform]
|
return POLICIES[platform]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
} from '../../repositories/fulfillment-profile-repo.js'
|
} from '../../repositories/fulfillment-profile-repo.js'
|
||||||
import { buildOrderClaimUrl, createTaskClaimToken } from '../claim/claim-service.js'
|
import { buildOrderClaimUrl, createTaskClaimToken } from '../claim/claim-service.js'
|
||||||
import { assertValidClaimUid, normalizeClaimUid } from '../claim/claim-identity.js'
|
import { assertValidClaimUid, normalizeClaimUid } from '../claim/claim-identity.js'
|
||||||
|
import { getAccountBindingPolicy } from '../account-binding/platform-policy.js'
|
||||||
import { saveManualFulfillmentConfig } from '../cost-center/manual-fulfillment-config-service.js'
|
import { saveManualFulfillmentConfig } from '../cost-center/manual-fulfillment-config-service.js'
|
||||||
import {
|
import {
|
||||||
assignFulfillmentChannelsWithExecutor,
|
assignFulfillmentChannelsWithExecutor,
|
||||||
@@ -378,8 +379,7 @@ export async function createSemiAutoMock(
|
|||||||
.trim()
|
.trim()
|
||||||
.slice(0, 500)
|
.slice(0, 500)
|
||||||
const browserTargetUrl = String(
|
const browserTargetUrl = String(
|
||||||
input.browserTargetUrl ||
|
input.browserTargetUrl || getAccountBindingPolicy(platform).defaultTargetUrl,
|
||||||
(platform === 'weibo' ? 'https://weibo.com/' : 'https://www.huya.com/'),
|
|
||||||
)
|
)
|
||||||
.trim()
|
.trim()
|
||||||
.slice(0, 1000)
|
.slice(0, 1000)
|
||||||
@@ -802,8 +802,7 @@ export async function createSemiAutoIntegrationMock(
|
|||||||
.trim()
|
.trim()
|
||||||
.slice(0, 60)
|
.slice(0, 60)
|
||||||
const browserTargetUrl = String(
|
const browserTargetUrl = String(
|
||||||
input.browserTargetUrl ||
|
input.browserTargetUrl || getAccountBindingPolicy(platform).defaultTargetUrl,
|
||||||
(platform === 'weibo' ? 'https://weibo.com/' : 'https://www.huya.com/'),
|
|
||||||
)
|
)
|
||||||
.trim()
|
.trim()
|
||||||
.slice(0, 1000)
|
.slice(0, 1000)
|
||||||
|
|||||||
@@ -27,7 +27,10 @@ import {
|
|||||||
import { revokeWeiboSession } from './weibo-connector-client.js'
|
import { revokeWeiboSession } from './weibo-connector-client.js'
|
||||||
import { querySemiAutoTraces } from './semi-auto-trace.js'
|
import { querySemiAutoTraces } from './semi-auto-trace.js'
|
||||||
import { isHuyaRoleToken } from './binding-role-id.js'
|
import { isHuyaRoleToken } from './binding-role-id.js'
|
||||||
import { getAccountBindingPolicy } from '../account-binding/platform-policy.js'
|
import {
|
||||||
|
getAccountBindingPolicy,
|
||||||
|
resolveBrowserTargetUrl,
|
||||||
|
} from '../account-binding/platform-policy.js'
|
||||||
import {
|
import {
|
||||||
ensureConnectorSessionForTask,
|
ensureConnectorSessionForTask,
|
||||||
ensureSemiAutoTasksForAdminList,
|
ensureSemiAutoTasksForAdminList,
|
||||||
@@ -249,9 +252,7 @@ export async function exportAdminSemiAutoCredential(taskIdInput: unknown) {
|
|||||||
targets.find((item): item is { url?: string } => Boolean(item && typeof item === 'object'))
|
targets.find((item): item is { url?: string } => Boolean(item && typeof item === 'object'))
|
||||||
?.url || '',
|
?.url || '',
|
||||||
).trim()
|
).trim()
|
||||||
const targetUrl = /^https:\/\//i.test(configuredTarget)
|
const targetUrl = resolveBrowserTargetUrl(credential.platform, [configuredTarget])
|
||||||
? configuredTarget
|
|
||||||
: getAccountBindingPolicy(credential.platform).defaultTargetUrl
|
|
||||||
const cookieHeader = targetUrl
|
const cookieHeader = targetUrl
|
||||||
? buildSemiAutoCredentialCookieHeader(credential.cookies, targetUrl)
|
? buildSemiAutoCredentialCookieHeader(credential.cookies, targetUrl)
|
||||||
: ''
|
: ''
|
||||||
@@ -820,8 +821,11 @@ export async function createAdminBrowserSession(
|
|||||||
const fallbackTarget = targets.find((item): item is { url?: string } =>
|
const fallbackTarget = targets.find((item): item is { url?: string } =>
|
||||||
Boolean(item && typeof item === 'object'),
|
Boolean(item && typeof item === 'object'),
|
||||||
)?.url
|
)?.url
|
||||||
const policyTarget = getAccountBindingPolicy(task.platform).defaultTargetUrl
|
// 平台首页占位值(历史 Mock/配置默认)视为「未配置」,回落到策略默认落地页。
|
||||||
const targetUrl = explicitTarget || String(fallbackTarget || '') || policyTarget
|
const targetUrl = resolveBrowserTargetUrl(task.platform, [
|
||||||
|
explicitTarget,
|
||||||
|
String(fallbackTarget || ''),
|
||||||
|
])
|
||||||
|
|
||||||
// 直接下发账号级 CK:不再签发一次性票据,也不做额外的 TTL。
|
// 直接下发账号级 CK:不再签发一次性票据,也不做额外的 TTL。
|
||||||
// 权限边界是后台登录态 + 任务领取人 + 审计日志,与「导出 CK」同一级。
|
// 权限边界是后台登录态 + 任务领取人 + 审计日志,与「导出 CK」同一级。
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import {
|
|||||||
type DevDouyuFulfillmentMockResult,
|
type DevDouyuFulfillmentMockResult,
|
||||||
type DevSemiAutoIntegrationResult,
|
type DevSemiAutoIntegrationResult,
|
||||||
} from '@/services/admin'
|
} from '@/services/admin'
|
||||||
|
import { POST_INJECTION_URLS } from '@/utils/semi-auto-injection'
|
||||||
import { buildCustomerFulfillmentPath } from '@/utils/customer-fulfillment-link'
|
import { buildCustomerFulfillmentPath } from '@/utils/customer-fulfillment-link'
|
||||||
|
|
||||||
type MockTabKey = 'douyu' | 'semi-auto' | 'affiliate-dash' | 'kuaishou-voucher' | 'open91'
|
type MockTabKey = 'douyu' | 'semi-auto' | 'affiliate-dash' | 'kuaishou-voucher' | 'open91'
|
||||||
@@ -926,7 +927,7 @@ function SemiAutoMockForm({
|
|||||||
platform: 'huya',
|
platform: 'huya',
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
pageTitle: '虎牙账号授权测试',
|
pageTitle: '虎牙账号授权测试',
|
||||||
browserTargetUrl: 'https://www.huya.com/',
|
browserTargetUrl: POST_INJECTION_URLS.huya,
|
||||||
connectorMode: defaultMode,
|
connectorMode: defaultMode,
|
||||||
}}
|
}}
|
||||||
onFinish={onSubmit}
|
onFinish={onSubmit}
|
||||||
@@ -944,7 +945,8 @@ function SemiAutoMockForm({
|
|||||||
onChange={(value: 'huya' | 'weibo') => {
|
onChange={(value: 'huya' | 'weibo') => {
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
pageTitle: value === 'weibo' ? '微博角色绑定测试' : '虎牙账号授权测试',
|
pageTitle: value === 'weibo' ? '微博角色绑定测试' : '虎牙账号授权测试',
|
||||||
browserTargetUrl: value === 'weibo' ? 'https://weibo.com/' : 'https://www.huya.com/',
|
browserTargetUrl:
|
||||||
|
value === 'weibo' ? POST_INJECTION_URLS.weibo : POST_INJECTION_URLS.huya,
|
||||||
...(value === 'weibo' ? { connectorMode: 'embedded' } : {}),
|
...(value === 'weibo' ? { connectorMode: 'embedded' } : {}),
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
@@ -1031,7 +1033,7 @@ function SemiAutoMockForm({
|
|||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
placeholder={
|
placeholder={
|
||||||
selectedPlatform === 'weibo' ? 'https://weibo.com/' : 'https://www.huya.com/'
|
selectedPlatform === 'weibo' ? POST_INJECTION_URLS.weibo : POST_INJECTION_URLS.huya
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|||||||
@@ -20,6 +20,20 @@ export function resolvePostInjectionUrl(platform: string | null | undefined): st
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 平台首页占位值:历史开发 Mock / 人工配置把它填进 `browserTargets`,
|
||||||
|
* 等于「没有配置落地页」,必须当作未配置处理(后端同一规则)。
|
||||||
|
*/
|
||||||
|
const PLATFORM_HOMEPAGE_PLACEHOLDERS: Record<SemiAutoPlatform, readonly string[]> = {
|
||||||
|
huya: ['https://www.huya.com', 'https://www.huya.com/'],
|
||||||
|
weibo: ['https://weibo.com', 'https://weibo.com/'],
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPlatformHomepagePlaceholder(platform: string, url: string): boolean {
|
||||||
|
if (platform !== 'huya' && platform !== 'weibo') return false
|
||||||
|
return PLATFORM_HOMEPAGE_PLACEHOLDERS[platform].includes(url.trim().toLowerCase())
|
||||||
|
}
|
||||||
|
|
||||||
/** 计算注入时要打开的目标页所需的最小任务信息。 */
|
/** 计算注入时要打开的目标页所需的最小任务信息。 */
|
||||||
export type SemiAutoInjectionTargetTask = {
|
export type SemiAutoInjectionTargetTask = {
|
||||||
platform: string
|
platform: string
|
||||||
@@ -39,7 +53,7 @@ export function resolveInjectionTargetUrl(task: SemiAutoInjectionTargetTask): st
|
|||||||
? task.semiAutoConfig.browserTargets
|
? task.semiAutoConfig.browserTargets
|
||||||
: []
|
: []
|
||||||
const configured = String(targets.find((item) => item?.url)?.url || '').trim()
|
const configured = String(targets.find((item) => item?.url)?.url || '').trim()
|
||||||
if (configured) return configured
|
if (configured && !isPlatformHomepagePlaceholder(task.platform, configured)) return configured
|
||||||
const policyTarget = String(task.bindingPolicy?.defaultTargetUrl || '').trim()
|
const policyTarget = String(task.bindingPolicy?.defaultTargetUrl || '').trim()
|
||||||
if (policyTarget) return policyTarget
|
if (policyTarget) return policyTarget
|
||||||
return resolvePostInjectionUrl(task.platform)
|
return resolvePostInjectionUrl(task.platform)
|
||||||
|
|||||||
@@ -50,6 +50,15 @@ test('注入目标页优先级:SKU 配置 → 后端策略 → 前端兜底',
|
|||||||
}),
|
}),
|
||||||
'https://custom.example.com/x',
|
'https://custom.example.com/x',
|
||||||
)
|
)
|
||||||
|
// 平台首页占位值(历史开发 Mock 的默认配置)等于「没配置」,不能用它当落地页。
|
||||||
|
assert.equal(
|
||||||
|
resolveInjectionTargetUrl({
|
||||||
|
platform: 'huya',
|
||||||
|
semiAutoConfig: { browserTargets: [{ url: 'https://www.huya.com/' }] },
|
||||||
|
bindingPolicy: { defaultTargetUrl: policyTarget },
|
||||||
|
}),
|
||||||
|
policyTarget,
|
||||||
|
)
|
||||||
// 后端没给(老 DTO)时才回落到前端常量。
|
// 后端没给(老 DTO)时才回落到前端常量。
|
||||||
assert.equal(resolveInjectionTargetUrl({ platform: 'huya' }), POST_INJECTION_URLS.huya)
|
assert.equal(resolveInjectionTargetUrl({ platform: 'huya' }), POST_INJECTION_URLS.huya)
|
||||||
assert.equal(resolveInjectionTargetUrl({ platform: 'weibo' }), POST_INJECTION_URLS.weibo)
|
assert.equal(resolveInjectionTargetUrl({ platform: 'weibo' }), POST_INJECTION_URLS.weibo)
|
||||||
|
|||||||
Reference in New Issue
Block a user