调整(虎牙客户资料): 增加游戏主页截图、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,59 @@
|
||||
import { getGameRoleNameIssue, isValidGameRoleId } from './game-role-name.ts'
|
||||
|
||||
/** 虎牙客户资料区服枚举,与后端 `normalizeCustomerProfile` 的集合一致。 */
|
||||
export const CUSTOMER_SERVER_ZONE_OPTIONS = ['苹果Q区', '苹果V区', '安卓Q区', '安卓V区'] as const
|
||||
|
||||
/** 游戏角色 UID 输入框提示,与后端 `semi_auto_profile_role_id_invalid` 口径一致。 */
|
||||
export const GAME_ROLE_ID_PLACEHOLDER = '请输入游戏角色 UID,纯数字uid'
|
||||
export const GAME_ROLE_ID_INVALID_HINT = '游戏角色 UID 只能填写纯数字(1-20 位)'
|
||||
|
||||
/** 输入过程中的实时提示:为空不提示(提交时再统一拦截)。 */
|
||||
export function getGameRoleIdIssue(value: string): string | null {
|
||||
const roleId = String(value ?? '').trim()
|
||||
if (!roleId) return null
|
||||
return isValidGameRoleId(roleId) ? null : GAME_ROLE_ID_INVALID_HINT
|
||||
}
|
||||
|
||||
export type CustomerProfileSubmitField = 'serverZone' | 'roleId' | 'roleName' | 'homepageScreenshot'
|
||||
|
||||
export type CustomerProfileSubmitIssue = {
|
||||
field: CustomerProfileSubmitField
|
||||
message: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户提交虎牙资料前的纯函数校验,顺序与后端 `normalizeCustomerProfile` / `savePublicTaskProfile` 一致:
|
||||
* 必填 → 区服枚举 → UID 纯数字 → 角色名不混入 UID/区服/登录方式 → 主页截图必填。
|
||||
*/
|
||||
export function validateCustomerProfileSubmit(input: {
|
||||
serverZone: string
|
||||
roleId: string
|
||||
roleName: string
|
||||
homepageScreenshotObjectKey: string
|
||||
}): CustomerProfileSubmitIssue | null {
|
||||
const serverZone = String(input.serverZone ?? '').trim()
|
||||
const roleId = String(input.roleId ?? '').trim()
|
||||
const roleName = String(input.roleName ?? '').trim()
|
||||
const homepageScreenshotObjectKey = String(input.homepageScreenshotObjectKey ?? '').trim()
|
||||
|
||||
if (!serverZone || !roleId || !roleName) {
|
||||
return {
|
||||
field: !serverZone ? 'serverZone' : !roleId ? 'roleId' : 'roleName',
|
||||
message: '请完整填写区服、游戏角色 UID 和角色名',
|
||||
}
|
||||
}
|
||||
if (!(CUSTOMER_SERVER_ZONE_OPTIONS as readonly string[]).includes(serverZone)) {
|
||||
return { field: 'serverZone', message: '请选择区服' }
|
||||
}
|
||||
if (!isValidGameRoleId(roleId)) {
|
||||
return { field: 'roleId', message: GAME_ROLE_ID_INVALID_HINT }
|
||||
}
|
||||
const roleNameIssue = getGameRoleNameIssue(roleName)
|
||||
if (roleNameIssue) {
|
||||
return { field: 'roleName', message: roleNameIssue }
|
||||
}
|
||||
if (!homepageScreenshotObjectKey) {
|
||||
return { field: 'homepageScreenshot', message: '请上传游戏主页截图' }
|
||||
}
|
||||
return null
|
||||
}
|
||||
+22
-4
@@ -1,7 +1,7 @@
|
||||
export const DOUYU_ROLE_NAME_FORMAT_HINT =
|
||||
export const GAME_ROLE_NAME_FORMAT_HINT =
|
||||
'只填写游戏角色名,不要填写 UID、区服或微信/QQ;登录方式和设备系统请在上方选择。'
|
||||
|
||||
export const DOUYU_ROLE_NAME_MIXED_WARNING =
|
||||
export const GAME_ROLE_NAME_MIXED_WARNING =
|
||||
'这里只能填写游戏角色名。检测到 UID、区服或登录方式,请只保留角色名称,例如“花乔妖精”。'
|
||||
|
||||
const ROLE_NAME_SEPARATOR = /[\s,,、|/\\·::;;_-]+/u
|
||||
@@ -9,7 +9,11 @@ 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 function getDouyuRoleNameIssue(value: string): string | null {
|
||||
/** 游戏角色 UID 只接受 1..20 位纯数字,与后端校验保持一致。 */
|
||||
export const GAME_ROLE_ID_MAX_LENGTH = 20
|
||||
const GAME_ROLE_ID_PATTERN = /^\d+$/u
|
||||
|
||||
export function getGameRoleNameIssue(value: string): string | null {
|
||||
const roleName = String(value ?? '').trim()
|
||||
if (!roleName) return null
|
||||
|
||||
@@ -19,6 +23,20 @@ export function getDouyuRoleNameIssue(value: string): string | null {
|
||||
const hasStandaloneLoginOrSystem = tokens.some((token) => STANDALONE_LOGIN_OR_SYSTEM.test(token))
|
||||
|
||||
return hasStandaloneUid || hasLongNumber || hasStandaloneLoginOrSystem
|
||||
? DOUYU_ROLE_NAME_MIXED_WARNING
|
||||
? GAME_ROLE_NAME_MIXED_WARNING
|
||||
: null
|
||||
}
|
||||
|
||||
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)
|
||||
)
|
||||
}
|
||||
|
||||
/** 输入框只保留数字,避免把字母/空格带进 UID。 */
|
||||
export function sanitizeGameRoleIdInput(value: string) {
|
||||
return String(value ?? '').replace(/\D/g, '')
|
||||
}
|
||||
Reference in New Issue
Block a user