调整(虎牙客户资料): 增加游戏主页截图、UID 纯数字与角色名混入校验
- 迁移 191:semi_auto_tasks 增加客户游戏主页截图 5 个正式字段
(object_key / url / thumbnail_url / filename / uploaded_at)。
- 新增 POST /customer-fulfillment/:orderNo/tasks/:taskId/homepage-screenshot
(writeLimit + 单文件上传),场景 semi-auto-homepage-screenshot、
归属 semi-auto-task-{taskId},与斗鱼同一套 file_assets 校验口径。
- 保存资料改为四要素必填:区服 / 游戏角色 UID / 角色名 / 游戏主页截图;
截图须在同一事务内校验归属与类型,缺失或越权直接 400。
- 游戏角色 UID 改为 1..20 位纯数字校验(semi_auto_profile_role_id_invalid);
角色名新增「不得混入 UID/区服/登录方式」校验,规则与斗鱼一致并在后端再实现一份。
- 客户页:UID 提示改为「请输入游戏角色 UID,纯数字uid」、只接受数字输入并实时提示;
角色名加斗鱼同款提示与混入警告;新增「游戏主页截图(必填)」上传区 + 示例图 + 说明文案;
已保存截图按 DTO 的 objectKey 回填预览,不再从文件链接反解。
- 角色名规则收敛到共享 game-role-name(删除 douyu-role-name 转发层,斗鱼页面与文案不变)。
- 「资料已完成」判断仍只看已保存三要素:截图在保存时强制,
避免本次改造前已填好资料的历史任务被卡回第一步。
- 权威文档同步虎牙资料四要素、UID 纯数字、角色名混入校验与截图用途,并补迁移 191 记录。
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
-- 191_semi_auto_homepage_screenshot.sql
|
||||
--
|
||||
-- 虎牙客户授权页增加必填「游戏主页截图」,与斗鱼客户资料收集口径一致:
|
||||
-- 1. 截图对象、展示地址、缩略图、原始文件名和提交时间作为半自动任务正式字段保存;
|
||||
-- 2. 图片台账与归属校验以 file_assets 为准,任务表只保存已校验通过的结果;
|
||||
-- 3. 客服据此核对客户填写的角色名 / 游戏角色 UID 与账号绑定是否正确。
|
||||
|
||||
ALTER TABLE semi_auto_tasks
|
||||
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_object_key TEXT NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_url TEXT NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_thumbnail_url TEXT NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_filename TEXT NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_uploaded_at TIMESTAMPTZ;
|
||||
|
||||
COMMENT ON COLUMN semi_auto_tasks.customer_homepage_screenshot_object_key IS
|
||||
'客户上传的游戏主页截图对象 key;文件台账和归属校验以 file_assets 为准';
|
||||
COMMENT ON COLUMN semi_auto_tasks.customer_homepage_screenshot_url IS
|
||||
'客户游戏主页截图稳定展示地址;客服核对绑定使用';
|
||||
COMMENT ON COLUMN semi_auto_tasks.customer_homepage_screenshot_thumbnail_url IS
|
||||
'客户游戏主页截图缩略图稳定展示地址';
|
||||
COMMENT ON COLUMN semi_auto_tasks.customer_homepage_screenshot_filename IS
|
||||
'客户游戏主页截图原始文件名';
|
||||
COMMENT ON COLUMN semi_auto_tasks.customer_homepage_screenshot_uploaded_at IS
|
||||
'客户游戏主页截图随资料提交保存的时间';
|
||||
@@ -18,10 +18,12 @@ import {
|
||||
startPublicLogin,
|
||||
startPublicWeiboQrLogin,
|
||||
submitPublicRebind,
|
||||
uploadPublicTaskHomepageScreenshot,
|
||||
verifyPublicHuyaSmsChallenge,
|
||||
} from '../services/semi-auto/semi-auto-task-service.js'
|
||||
import { createSemiAutoTaskTraceHandler } from '../middleware/semi-auto-trace.js'
|
||||
import { createRateLimitMiddleware, getParamRateLimitKey } from '../middleware/rate-limit.js'
|
||||
import { uploadSingleFile } from './file-upload.js'
|
||||
import { createRouteHandler } from '../utils/http.js'
|
||||
|
||||
const router = Router()
|
||||
@@ -99,6 +101,21 @@ router.post(
|
||||
),
|
||||
)
|
||||
|
||||
// 客户游戏主页截图:与角色资料分开上传,保存资料时再按 objectKey 校验归属。
|
||||
router.post(
|
||||
'/:orderNo/tasks/:taskId/homepage-screenshot',
|
||||
writeLimit,
|
||||
uploadSingleFile,
|
||||
createRouteHandler(
|
||||
(req) => uploadPublicTaskHomepageScreenshot(req.params.orderNo, req.params.taskId, req.file),
|
||||
{
|
||||
successMessage: '主页截图已上传',
|
||||
errorMessage: '上传主页截图失败',
|
||||
scope: '[customer-fulfillment/:orderNo/tasks/:taskId/homepage-screenshot]',
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
router.post(
|
||||
'/:orderNo/tasks/:taskId/binding/reset',
|
||||
writeLimit,
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
GAME_ROLE_NAME_MIXED_WARNING,
|
||||
getGameRoleNameIssue,
|
||||
isValidGameRoleId,
|
||||
} from './game-role-name.js'
|
||||
|
||||
test('游戏角色 UID 只接受 1..20 位纯数字', () => {
|
||||
assert.equal(isValidGameRoleId('1192083858'), true)
|
||||
assert.equal(isValidGameRoleId(' 4212063544 '), true)
|
||||
assert.equal(isValidGameRoleId('0'), true)
|
||||
assert.equal(isValidGameRoleId('12345678901234567890'), true)
|
||||
assert.equal(isValidGameRoleId('123456789012345678901'), false)
|
||||
assert.equal(isValidGameRoleId('uid-not-number'), false)
|
||||
assert.equal(isValidGameRoleId('UID-not-number'), false)
|
||||
assert.equal(isValidGameRoleId('1192083858a'), false)
|
||||
assert.equal(isValidGameRoleId('-1192083858'), false)
|
||||
assert.equal(isValidGameRoleId('1192083858'), false)
|
||||
assert.equal(isValidGameRoleId(''), false)
|
||||
assert.equal(isValidGameRoleId(' '), false)
|
||||
})
|
||||
|
||||
test('纯角色名通过角色名校验', () => {
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精'), null)
|
||||
assert.equal(getGameRoleNameIssue('狙神123'), null)
|
||||
assert.equal(getGameRoleNameIssue('QQ战神'), null)
|
||||
assert.equal(getGameRoleNameIssue(''), null)
|
||||
assert.equal(getGameRoleNameIssue(' '), null)
|
||||
})
|
||||
|
||||
test('角色名混入 UID、区服或登录方式时拒绝', () => {
|
||||
assert.equal(
|
||||
getGameRoleNameIssue('花乔妖精 3379480446 安卓区 微信'),
|
||||
GAME_ROLE_NAME_MIXED_WARNING,
|
||||
)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 3379480446'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精3379480446'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 安卓区'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 微信'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('花乔妖精 qq'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('安卓区'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
assert.equal(getGameRoleNameIssue('ios'), GAME_ROLE_NAME_MIXED_WARNING)
|
||||
})
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 游戏角色名与角色 UID 的公共校验口径。
|
||||
*
|
||||
* 与前端 `apps/frontend/src/utils/game-role-name.ts` 保持同一套规则:
|
||||
* 角色名只允许填写角色名称,UID、区服、登录方式属于其它字段,混入即视为填写错误。
|
||||
* 后端必须独立校验,不能只依赖前端提示。
|
||||
*/
|
||||
export const GAME_ROLE_NAME_MIXED_WARNING =
|
||||
'这里只能填写游戏角色名。检测到 UID、区服或登录方式,请只保留角色名称,例如“花乔妖精”。'
|
||||
|
||||
const ROLE_NAME_SEPARATOR = /[\s,,、|/\\·::;;_-]+/u
|
||||
const STANDALONE_UID = /^\d{6,}$/u
|
||||
const LONG_NUMBER = /\d{8,}/u
|
||||
const STANDALONE_LOGIN_OR_SYSTEM = /^(?:安卓区?|苹果区?|ios|android|微信|qq|q区|v区|手q)$/iu
|
||||
|
||||
/** 角色名允许的最大长度(与客户页输入框上限一致)。 */
|
||||
export const GAME_ROLE_NAME_MAX_LENGTH = 100
|
||||
/** 游戏角色 UID 允许的最大长度(与客户页输入框上限一致)。 */
|
||||
export const GAME_ROLE_ID_MAX_LENGTH = 20
|
||||
|
||||
const GAME_ROLE_ID_PATTERN = /^\d+$/u
|
||||
|
||||
/** 返回角色名混入 UID / 区服 / 登录方式时的提示;没有混入返回 null。 */
|
||||
export function getGameRoleNameIssue(value: string): string | null {
|
||||
const roleName = String(value ?? '').trim()
|
||||
if (!roleName) return null
|
||||
|
||||
const tokens = roleName.split(ROLE_NAME_SEPARATOR).filter(Boolean)
|
||||
const hasStandaloneUid = tokens.some((token) => STANDALONE_UID.test(token))
|
||||
const hasLongNumber = LONG_NUMBER.test(roleName)
|
||||
const hasStandaloneLoginOrSystem = tokens.some((token) => STANDALONE_LOGIN_OR_SYSTEM.test(token))
|
||||
|
||||
return hasStandaloneUid || hasLongNumber || hasStandaloneLoginOrSystem
|
||||
? GAME_ROLE_NAME_MIXED_WARNING
|
||||
: null
|
||||
}
|
||||
|
||||
/** 游戏角色 UID 必须是 1..20 位纯数字。 */
|
||||
export function isValidGameRoleId(value: string) {
|
||||
const roleId = String(value ?? '').trim()
|
||||
return (
|
||||
roleId.length > 0 &&
|
||||
roleId.length <= GAME_ROLE_ID_MAX_LENGTH &&
|
||||
GAME_ROLE_ID_PATTERN.test(roleId)
|
||||
)
|
||||
}
|
||||
@@ -154,7 +154,7 @@ describe('虎牙角色比对', () => {
|
||||
})
|
||||
|
||||
describe('客户角色资料校验', () => {
|
||||
it('游戏角色 UID 必填但不校验格式', () => {
|
||||
it('游戏角色 UID 必填且只接受纯数字', () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
@@ -164,20 +164,38 @@ describe('客户角色资料校验', () => {
|
||||
}),
|
||||
/请完整填写区服、游戏角色 UID 和角色名/,
|
||||
)
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc',
|
||||
roleId: 'uid-not-number',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
/游戏角色 UID 只能填写纯数字/,
|
||||
)
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc',
|
||||
roleId: '123456789012345678901',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
/游戏角色 UID 只能填写纯数字/,
|
||||
)
|
||||
|
||||
const profile = normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc',
|
||||
roleId: 'uid-not-number',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
})
|
||||
assert.deepEqual(profile, {
|
||||
roleName: '落地盒子怪cc',
|
||||
roleId: 'uid-not-number',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
})
|
||||
assert.equal(
|
||||
hasCustomerProfile({
|
||||
customer_game_id: 'uid-not-number',
|
||||
customer_game_id: '4212063544',
|
||||
customer_game_role: '落地盒子怪cc',
|
||||
customer_server_zone: '安卓Q区',
|
||||
}),
|
||||
@@ -193,6 +211,36 @@ describe('客户角色资料校验', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('角色名混入 UID、区服或登录方式时拒绝保存', () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc 4212063544',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
/这里只能填写游戏角色名/,
|
||||
)
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc 安卓区',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
/这里只能填写游戏角色名/,
|
||||
)
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCustomerProfile({
|
||||
roleName: '落地盒子怪cc QQ',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
/这里只能填写游戏角色名/,
|
||||
)
|
||||
})
|
||||
|
||||
it('清理空白并保留纯数字游戏角色 UID', () => {
|
||||
const profile = normalizeCustomerProfile({
|
||||
roleName: ' 落地盒子怪cc ',
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
import { runtimeConfig } from '../../config/runtime.js'
|
||||
import { query, withTransaction } from '../../db/client.js'
|
||||
import { getFileAssetByObjectKey } from '../../repositories/file-asset-repo.js'
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
import { logWarn } from '../../utils/logger.js'
|
||||
import {
|
||||
ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES,
|
||||
buildFileUrl,
|
||||
uploadFileAsset,
|
||||
} from '../file-storage/file-storage-service.js'
|
||||
import {
|
||||
GAME_ROLE_NAME_MAX_LENGTH,
|
||||
getGameRoleNameIssue,
|
||||
isValidGameRoleId,
|
||||
} from '../account-binding/game-role-name.js'
|
||||
import {
|
||||
confirmHuyaBinding,
|
||||
exportHuyaSessionCredential,
|
||||
@@ -103,15 +115,24 @@ export type CustomerProfileInput = {
|
||||
serverZone?: unknown
|
||||
}
|
||||
|
||||
/** 客户上传游戏主页截图的文件场景与归属,用于校验 file_assets 台账。 */
|
||||
export const SEMI_AUTO_HOMEPAGE_SCREENSHOT_SCENE = 'semi-auto-homepage-screenshot'
|
||||
export const SEMI_AUTO_HOMEPAGE_UPLOADER_TYPE = 'semi-auto-customer'
|
||||
|
||||
/** 截图资产必须由本次任务自己的客户上传,不能复用其它任务或其它场景的文件。 */
|
||||
export function semiAutoHomepageScreenshotUploaderId(taskId: number) {
|
||||
return `semi-auto-task-${taskId}`
|
||||
}
|
||||
|
||||
const CUSTOMER_SERVER_ZONES = new Set(['苹果Q区', '苹果V区', '安卓Q区', '安卓V区'])
|
||||
|
||||
export function normalizeCustomerProfile(input: CustomerProfileInput = {}) {
|
||||
const roleName = String(input.roleName ?? '')
|
||||
.trim()
|
||||
.slice(0, 100)
|
||||
.slice(0, GAME_ROLE_NAME_MAX_LENGTH)
|
||||
const roleId = String(input.roleId ?? '')
|
||||
.trim()
|
||||
.replace(/\s+/g, '')
|
||||
.slice(0, 64)
|
||||
const serverZone = String(input.serverZone ?? '')
|
||||
.trim()
|
||||
.slice(0, 100)
|
||||
@@ -127,18 +148,45 @@ export function normalizeCustomerProfile(input: CustomerProfileInput = {}) {
|
||||
errorCode: 'semi_auto_profile_required',
|
||||
})
|
||||
}
|
||||
if (!isValidGameRoleId(roleId)) {
|
||||
throw createHttpError('游戏角色 UID 只能填写纯数字', {
|
||||
statusCode: 400,
|
||||
errorCode: 'semi_auto_profile_role_id_invalid',
|
||||
})
|
||||
}
|
||||
const roleNameIssue = getGameRoleNameIssue(roleName)
|
||||
if (roleNameIssue) {
|
||||
throw createHttpError(roleNameIssue, {
|
||||
statusCode: 400,
|
||||
errorCode: 'semi_auto_profile_role_name_invalid',
|
||||
})
|
||||
}
|
||||
return { roleName, roleId, serverZone }
|
||||
}
|
||||
|
||||
function absoluteOrderSiteFileUrl(pathname: string) {
|
||||
const normalizedPath = String(pathname || '').trim()
|
||||
if (!normalizedPath) return ''
|
||||
try {
|
||||
return new URL(normalizedPath, new URL(runtimeConfig.orders.claimBaseUrl).origin).toString()
|
||||
} catch {
|
||||
return normalizedPath
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 半自动订单没有 work_orders,客户资料在授权页 /c/<订单号>(虎牙)或 /d/<订单号>(微博)收集。
|
||||
* 虎牙先保存目标角色名、区服和 UID,再登录账号;UID 只做资料收集,不校验格式,
|
||||
* 也不参与绑定核验。
|
||||
* 虎牙先保存目标角色名、区服、游戏角色 UID 和游戏主页截图,再登录账号;
|
||||
* 游戏角色 UID 只做资料收集与纯数字格式校验,不参与绑定核验。
|
||||
*/
|
||||
export type CustomerProfileSaveInput = CustomerProfileInput & {
|
||||
homepageScreenshotObjectKey?: unknown
|
||||
}
|
||||
|
||||
export async function savePublicTaskProfile(
|
||||
orderNoInput: unknown,
|
||||
taskIdInput: unknown,
|
||||
payload: CustomerProfileInput = {},
|
||||
payload: CustomerProfileSaveInput = {},
|
||||
) {
|
||||
const orderNo = normalizeOrderNo(orderNoInput)
|
||||
const taskId = normalizeId(taskIdInput)
|
||||
@@ -163,6 +211,15 @@ export async function savePublicTaskProfile(
|
||||
})
|
||||
}
|
||||
const profile = normalizeCustomerProfile(payload)
|
||||
const homepageScreenshotObjectKey = String(payload.homepageScreenshotObjectKey ?? '')
|
||||
.trim()
|
||||
.slice(0, 512)
|
||||
if (!homepageScreenshotObjectKey) {
|
||||
throw createHttpError('请上传游戏主页截图', {
|
||||
statusCode: 400,
|
||||
errorCode: 'semi_auto_homepage_screenshot_required',
|
||||
})
|
||||
}
|
||||
await withTransaction(async (client) => {
|
||||
const current = await loadTaskForUpdateWithClient(client, task.id)
|
||||
if (current.execution_status === 'completed' || current.execution_status === 'cancelled') {
|
||||
@@ -177,6 +234,23 @@ export async function savePublicTaskProfile(
|
||||
errorCode: 'semi_auto_profile_locked',
|
||||
})
|
||||
}
|
||||
const asset = await getFileAssetByObjectKey(homepageScreenshotObjectKey, client)
|
||||
if (
|
||||
!asset ||
|
||||
asset.uploader_type !== SEMI_AUTO_HOMEPAGE_UPLOADER_TYPE ||
|
||||
asset.uploader_id !== semiAutoHomepageScreenshotUploaderId(current.id) ||
|
||||
asset.scene !== SEMI_AUTO_HOMEPAGE_SCREENSHOT_SCENE ||
|
||||
!ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES.has(String(asset.content_type || '').trim())
|
||||
) {
|
||||
throw createHttpError('主页截图无效,请重新上传', {
|
||||
statusCode: 400,
|
||||
errorCode: 'semi_auto_homepage_screenshot_invalid',
|
||||
})
|
||||
}
|
||||
const screenshotUrl = absoluteOrderSiteFileUrl(buildFileUrl(asset.object_key))
|
||||
const thumbnailUrl = absoluteOrderSiteFileUrl(
|
||||
buildFileUrl(asset.thumbnail_object_key || asset.object_key),
|
||||
)
|
||||
await convergeSemiAutoTaskState(client, current.id, {
|
||||
reason: 'customer_profile_saved',
|
||||
actor: 'customer',
|
||||
@@ -184,8 +258,16 @@ export async function savePublicTaskProfile(
|
||||
customerGameRoleName: profile.roleName,
|
||||
customerGameRoleId: profile.roleId,
|
||||
customerGameServerZone: profile.serverZone,
|
||||
customerHomepageScreenshotObjectKey: asset.object_key,
|
||||
customerHomepageScreenshotUrl: screenshotUrl,
|
||||
customerHomepageScreenshotThumbnailUrl: thumbnailUrl,
|
||||
customerHomepageScreenshotFilename: asset.original_filename,
|
||||
customerHomepageScreenshotUploadedAt: SEMI_AUTO_NOW,
|
||||
},
|
||||
event: {
|
||||
eventType: 'customer_profile_saved',
|
||||
detail: { ...profile, homepageScreenshotObjectKey: asset.object_key },
|
||||
},
|
||||
event: { eventType: 'customer_profile_saved', detail: profile },
|
||||
})
|
||||
})
|
||||
publishSemiAutoTaskRealtimeChange(task.id, task.order_id)
|
||||
@@ -200,6 +282,40 @@ export async function savePublicTaskProfile(
|
||||
return { task: mapTask(updated) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户上传游戏主页截图:文件先独立落库,保存资料时再用 objectKey 校验归属并写入任务。
|
||||
* 与服务端其它上传一致,必须走 file_assets 台账,不信任前端传入的 URL。
|
||||
*/
|
||||
export async function uploadPublicTaskHomepageScreenshot(
|
||||
orderNoInput: unknown,
|
||||
taskIdInput: unknown,
|
||||
file: Express.Multer.File | null | undefined,
|
||||
) {
|
||||
const orderNo = normalizeOrderNo(orderNoInput)
|
||||
const taskId = normalizeId(taskIdInput)
|
||||
const task = await loadTaskForOrder(orderNo, taskId)
|
||||
const bindingPolicy = getAccountBindingPolicy(task.platform)
|
||||
if (!bindingPolicy.requiresCustomerProfile) {
|
||||
throw createHttpError('当前平台不需要填写游戏角色', {
|
||||
statusCode: 409,
|
||||
errorCode: 'semi_auto_profile_not_supported',
|
||||
})
|
||||
}
|
||||
if (task.execution_status === 'completed' || task.execution_status === 'cancelled') {
|
||||
throw createHttpError('当前订单已结束,不能上传资料', {
|
||||
statusCode: 409,
|
||||
errorCode: 'semi_auto_task_closed',
|
||||
})
|
||||
}
|
||||
return uploadFileAsset({
|
||||
file,
|
||||
scene: SEMI_AUTO_HOMEPAGE_SCREENSHOT_SCENE,
|
||||
uploaderType: SEMI_AUTO_HOMEPAGE_UPLOADER_TYPE,
|
||||
uploaderId: semiAutoHomepageScreenshotUploaderId(task.id),
|
||||
allowedContentTypes: ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES,
|
||||
})
|
||||
}
|
||||
|
||||
function mapLoginUpdate(session: ConnectorLoginSession) {
|
||||
const statusMap: Record<ConnectorLoginSession['status'], LoginStatus> = {
|
||||
verification_pending: 'waiting_login',
|
||||
|
||||
@@ -153,6 +153,11 @@ export type TaskRow = {
|
||||
customer_game_role_name: string
|
||||
customer_game_role_id: string
|
||||
customer_game_server_zone: string
|
||||
customer_homepage_screenshot_object_key: string
|
||||
customer_homepage_screenshot_url: string
|
||||
customer_homepage_screenshot_thumbnail_url: string
|
||||
customer_homepage_screenshot_filename: string
|
||||
customer_homepage_screenshot_uploaded_at: string | null
|
||||
customer_game_id: string
|
||||
customer_game_role: string
|
||||
customer_server_zone: string
|
||||
@@ -559,6 +564,11 @@ export function mapTask(task: TaskRow) {
|
||||
customerGameRoleId: task.customer_game_id || '',
|
||||
customerGameRoleName: task.customer_game_role || '',
|
||||
customerServerZone: task.customer_server_zone || '',
|
||||
homepageScreenshotObjectKey: task.customer_homepage_screenshot_object_key || '',
|
||||
homepageScreenshotUrl: task.customer_homepage_screenshot_url || '',
|
||||
homepageScreenshotThumbnailUrl: task.customer_homepage_screenshot_thumbnail_url || '',
|
||||
homepageScreenshotFilename: task.customer_homepage_screenshot_filename || '',
|
||||
homepageScreenshotUploadedAt: task.customer_homepage_screenshot_uploaded_at || null,
|
||||
targetQuantity: Number(task.target_quantity || 1),
|
||||
completedQuantity: Number(task.completed_quantity || 0),
|
||||
assignedAdminUserId: task.assigned_admin_user_id ? Number(task.assigned_admin_user_id) : null,
|
||||
|
||||
@@ -118,6 +118,12 @@ export type SemiAutoTaskStatePatch = {
|
||||
customerGameRoleName?: string
|
||||
customerGameRoleId?: string
|
||||
customerGameServerZone?: string
|
||||
// 客户上传的游戏主页截图(客服核对绑定使用)
|
||||
customerHomepageScreenshotObjectKey?: string
|
||||
customerHomepageScreenshotUrl?: string
|
||||
customerHomepageScreenshotThumbnailUrl?: string
|
||||
customerHomepageScreenshotFilename?: string
|
||||
customerHomepageScreenshotUploadedAt?: SemiAutoTaskTimeValue
|
||||
// 登录时间
|
||||
authStartedAt?: SemiAutoTaskTimeValue
|
||||
authenticatedAt?: SemiAutoTaskTimeValue
|
||||
@@ -192,6 +198,23 @@ const PATCH_COLUMN_MAP: Record<string, PatchColumnMeta> = {
|
||||
customerGameRoleName: { column: 'customer_game_role_name', kind: 'value' },
|
||||
customerGameRoleId: { column: 'customer_game_role_id', kind: 'value' },
|
||||
customerGameServerZone: { column: 'customer_game_server_zone', kind: 'value' },
|
||||
customerHomepageScreenshotObjectKey: {
|
||||
column: 'customer_homepage_screenshot_object_key',
|
||||
kind: 'value',
|
||||
},
|
||||
customerHomepageScreenshotUrl: { column: 'customer_homepage_screenshot_url', kind: 'value' },
|
||||
customerHomepageScreenshotThumbnailUrl: {
|
||||
column: 'customer_homepage_screenshot_thumbnail_url',
|
||||
kind: 'value',
|
||||
},
|
||||
customerHomepageScreenshotFilename: {
|
||||
column: 'customer_homepage_screenshot_filename',
|
||||
kind: 'value',
|
||||
},
|
||||
customerHomepageScreenshotUploadedAt: {
|
||||
column: 'customer_homepage_screenshot_uploaded_at',
|
||||
kind: 'time',
|
||||
},
|
||||
authStartedAt: { column: 'auth_started_at', kind: 'time' },
|
||||
authenticatedAt: { column: 'authenticated_at', kind: 'time' },
|
||||
assignedAdminUserId: { column: 'assigned_admin_user_id', kind: 'value' },
|
||||
|
||||
@@ -18,6 +18,68 @@ async function expectErrorCode(fn: () => Promise<unknown>, errorCode: string) {
|
||||
})
|
||||
}
|
||||
|
||||
/** 1x1 PNG:集成测试只需要合法图片内容,不需要真实截图。 */
|
||||
const TEST_SCREENSHOT_PNG = Buffer.from(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==',
|
||||
'base64',
|
||||
)
|
||||
|
||||
/**
|
||||
* 造一张合法的客户游戏主页截图资产。
|
||||
*
|
||||
* 优先走生产同一条 `uploadFileAsset`;集成测试环境没有对象存储时,退化为直接写同一张
|
||||
* `file_assets` 台账行——被测路径是资料保存时的台账归属校验,不是对象存储可用性。
|
||||
*/
|
||||
async function createHomepageScreenshotAsset(
|
||||
taskId: number,
|
||||
options: { uploaderId?: string } = {},
|
||||
) {
|
||||
const { createFileAsset } = await import('../../repositories/file-asset-repo.js')
|
||||
const { ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES, buildFileUrl, uploadFileAsset } =
|
||||
await import('../file-storage/file-storage-service.js')
|
||||
const uploaderId = options.uploaderId || `semi-auto-task-${taskId}`
|
||||
const file = {
|
||||
buffer: TEST_SCREENSHOT_PNG,
|
||||
mimetype: 'image/png',
|
||||
originalname: 'game-home.png',
|
||||
size: TEST_SCREENSHOT_PNG.length,
|
||||
} as Express.Multer.File
|
||||
try {
|
||||
const uploaded = await uploadFileAsset({
|
||||
file,
|
||||
scene: 'semi-auto-homepage-screenshot',
|
||||
uploaderType: 'semi-auto-customer',
|
||||
uploaderId,
|
||||
allowedContentTypes: ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES,
|
||||
})
|
||||
return uploaded.file.objectKey
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'[semi-auto integration] 对象存储不可用,改为直接写 file_assets 台账行',
|
||||
error instanceof Error ? error.message : error,
|
||||
)
|
||||
const objectKey = `semi-auto-homepage-screenshot/${randomUUID()}.png`
|
||||
const now = new Date().toISOString()
|
||||
await createFileAsset({
|
||||
objectKey,
|
||||
scene: 'semi-auto-homepage-screenshot',
|
||||
originalFilename: 'game-home.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: TEST_SCREENSHOT_PNG.length,
|
||||
thumbnailObjectKey: '',
|
||||
mediumObjectKey: '',
|
||||
url: buildFileUrl(objectKey),
|
||||
thumbnailUrl: buildFileUrl(objectKey),
|
||||
mediumUrl: buildFileUrl(objectKey),
|
||||
uploaderType: 'semi-auto-customer',
|
||||
uploaderId,
|
||||
metadataJson: JSON.stringify({ source: 'integration-test' }),
|
||||
now,
|
||||
})
|
||||
return objectKey
|
||||
}
|
||||
}
|
||||
|
||||
test(
|
||||
'人工渠道半自动任务可由客户入口和后台列表幂等回填',
|
||||
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
|
||||
@@ -125,12 +187,17 @@ test(
|
||||
|
||||
const taskId = Number(tasks[0]?.id || 0)
|
||||
// 客户页流程固定为「填写资料 → 登录 → 绑定角色」:资料可先保存,绑定仍要求登录。
|
||||
const homepageScreenshotObjectKey = await createHomepageScreenshotAsset(taskId)
|
||||
const savedProfile = await savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '集成测试角色',
|
||||
roleId: '1192083858',
|
||||
serverZone: '安卓V区',
|
||||
homepageScreenshotObjectKey,
|
||||
})
|
||||
assert.equal(savedProfile.task.customerGameRoleName, '集成测试角色')
|
||||
assert.equal(savedProfile.task.homepageScreenshotFilename, 'game-home.png')
|
||||
assert.ok(savedProfile.task.homepageScreenshotUrl)
|
||||
assert.ok(savedProfile.task.homepageScreenshotUploadedAt)
|
||||
assert.equal(savedProfile.task.customerGameRoleId, '1192083858')
|
||||
assert.equal(savedProfile.task.customerServerZone, '安卓V区')
|
||||
await expectErrorCode(() => startPublicBinding(orderNo, taskId), 'semi_auto_login_required')
|
||||
@@ -1427,10 +1494,11 @@ test(
|
||||
)
|
||||
const saved = await savePublicTaskProfile(orderNo, result.taskId, {
|
||||
roleName: 'Mock虎牙角色',
|
||||
roleId: 'UID-not-number',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓V区',
|
||||
homepageScreenshotObjectKey: await createHomepageScreenshotAsset(result.taskId),
|
||||
})
|
||||
assert.equal(saved.task.customerGameRoleId, 'UID-not-number')
|
||||
assert.equal(saved.task.customerGameRoleId, '4212063544')
|
||||
assert.equal(saved.task.loginStatus, 'waiting_login')
|
||||
assert.equal(saved.task.displayStatus.label, '等待客户授权')
|
||||
|
||||
@@ -1459,7 +1527,7 @@ test(
|
||||
assert.equal(tasks[0]?.executionStatus, 'waiting_customer')
|
||||
assert.equal(tasks[0]?.displayStatus.label, '等待客户绑定角色')
|
||||
assert.equal(tasks[0]?.customerGameRoleName, 'Mock虎牙角色')
|
||||
assert.equal(tasks[0]?.customerGameRoleId, 'UID-not-number')
|
||||
assert.equal(tasks[0]?.customerGameRoleId, '4212063544')
|
||||
assert.equal(tasks[0]?.credentialSource, 'sms')
|
||||
assert.ok(tasks[0]?.huyaUid)
|
||||
assert.equal(tasks[0]?.platformNickname, 'Mock虎牙用户')
|
||||
@@ -1670,3 +1738,144 @@ test(
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
'虎牙客户资料必须带归属本人的游戏主页截图',
|
||||
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
|
||||
async () => {
|
||||
process.env.DATABASE_URL = TEST_DATABASE_URL
|
||||
process.env.ENABLE_DEV_MOCK = '1'
|
||||
const { closeDb, query } = await import('../../db/client.js')
|
||||
const { createSemiAutoMock } = await import('../dev-mock/dev-mock-service.js')
|
||||
const { resetMockSessions } = await import('../dev-mock/mock-semi-auto-connector.js')
|
||||
const { savePublicTaskProfile } = await import('./semi-auto-task-service.js')
|
||||
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1_000_000)}`
|
||||
const orderNo = `IT-HUYA-SCREENSHOT-${suffix}`
|
||||
let orderId = 0
|
||||
let configId = 0
|
||||
let taskId = 0
|
||||
try {
|
||||
const result = await createSemiAutoMock({
|
||||
orderNo,
|
||||
skuName: `虎牙主页截图-${suffix}`,
|
||||
quantity: 1,
|
||||
connectorMode: 'mock',
|
||||
})
|
||||
orderId = result.orderId
|
||||
configId = result.configId
|
||||
taskId = result.taskId
|
||||
|
||||
// 1. 合法截图资产 → 保存资料成功并落库。
|
||||
const objectKey = await createHomepageScreenshotAsset(taskId)
|
||||
const saved = await savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '截图测试角色',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
homepageScreenshotObjectKey: objectKey,
|
||||
})
|
||||
assert.equal(saved.task.customerGameRoleName, '截图测试角色')
|
||||
assert.equal(saved.task.customerGameRoleId, '4212063544')
|
||||
assert.equal(saved.task.customerServerZone, '安卓Q区')
|
||||
assert.ok(saved.task.homepageScreenshotUrl)
|
||||
assert.ok(saved.task.homepageScreenshotThumbnailUrl)
|
||||
assert.equal(saved.task.homepageScreenshotFilename, 'game-home.png')
|
||||
assert.ok(saved.task.homepageScreenshotUploadedAt)
|
||||
|
||||
const stored = await query<{
|
||||
object_key: string
|
||||
url: string
|
||||
thumbnail_url: string
|
||||
filename: string
|
||||
uploaded_at: string | null
|
||||
}>(
|
||||
`SELECT customer_homepage_screenshot_object_key AS object_key,
|
||||
customer_homepage_screenshot_url AS url,
|
||||
customer_homepage_screenshot_thumbnail_url AS thumbnail_url,
|
||||
customer_homepage_screenshot_filename AS filename,
|
||||
customer_homepage_screenshot_uploaded_at AS uploaded_at
|
||||
FROM semi_auto_tasks
|
||||
WHERE id = $1`,
|
||||
[taskId],
|
||||
)
|
||||
assert.equal(stored.rows[0]?.object_key, objectKey)
|
||||
assert.ok(stored.rows[0]?.url)
|
||||
assert.ok(stored.rows[0]?.thumbnail_url)
|
||||
assert.equal(stored.rows[0]?.filename, 'game-home.png')
|
||||
assert.ok(stored.rows[0]?.uploaded_at)
|
||||
|
||||
const event = await query<{ detail_json: { homepageScreenshotObjectKey?: string } }>(
|
||||
`SELECT detail_json
|
||||
FROM semi_auto_task_events
|
||||
WHERE task_id = $1 AND event_type = 'customer_profile_saved'
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`,
|
||||
[taskId],
|
||||
)
|
||||
assert.equal(event.rows[0]?.detail_json?.homepageScreenshotObjectKey, objectKey)
|
||||
|
||||
// 2. 缺少截图 → 明确要求先上传。
|
||||
await expectErrorCode(
|
||||
() =>
|
||||
savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '截图测试角色',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
}),
|
||||
'semi_auto_homepage_screenshot_required',
|
||||
)
|
||||
|
||||
// 3. 截图属于其它任务 → 归属校验失败。
|
||||
const foreignObjectKey = await createHomepageScreenshotAsset(taskId, {
|
||||
uploaderId: `semi-auto-task-${taskId + 999_999}`,
|
||||
})
|
||||
await expectErrorCode(
|
||||
() =>
|
||||
savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '截图测试角色',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
homepageScreenshotObjectKey: foreignObjectKey,
|
||||
}),
|
||||
'semi_auto_homepage_screenshot_invalid',
|
||||
)
|
||||
|
||||
// 4. 游戏角色 UID 非纯数字 → 资料校验失败。
|
||||
await expectErrorCode(
|
||||
() =>
|
||||
savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '截图测试角色',
|
||||
roleId: 'UID-not-number',
|
||||
serverZone: '安卓Q区',
|
||||
homepageScreenshotObjectKey: objectKey,
|
||||
}),
|
||||
'semi_auto_profile_role_id_invalid',
|
||||
)
|
||||
|
||||
// 5. 角色名混入 UID / 区服 → 资料校验失败。
|
||||
await expectErrorCode(
|
||||
() =>
|
||||
savePublicTaskProfile(orderNo, taskId, {
|
||||
roleName: '截图测试角色 4212063544',
|
||||
roleId: '4212063544',
|
||||
serverZone: '安卓Q区',
|
||||
homepageScreenshotObjectKey: objectKey,
|
||||
}),
|
||||
'semi_auto_profile_role_name_invalid',
|
||||
)
|
||||
} finally {
|
||||
if (taskId > 0) {
|
||||
await query('DELETE FROM file_assets WHERE uploader_id = $1', [`semi-auto-task-${taskId}`])
|
||||
await query('DELETE FROM file_assets WHERE uploader_id = $1', [
|
||||
`semi-auto-task-${taskId + 999_999}`,
|
||||
])
|
||||
}
|
||||
if (orderId > 0) await query('DELETE FROM orders WHERE id = $1', [orderId])
|
||||
if (configId > 0) {
|
||||
await query('DELETE FROM manual_fulfillment_configs WHERE id = $1', [configId])
|
||||
}
|
||||
resetMockSessions()
|
||||
delete process.env.ENABLE_DEV_MOCK
|
||||
await closeDb()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user