45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
/** 数字人版本上传表单(任务 133):版本号/文件校验与 multipart 字段;纯逻辑。 */
|
|
|
|
export interface DigitalHumanUploadForm {
|
|
version: string
|
|
file: { name?: string; size?: number } | null
|
|
changelog?: string
|
|
minClientVersion?: string
|
|
createdBy?: string
|
|
}
|
|
|
|
export interface DigitalHumanUploadErrors {
|
|
version?: string
|
|
file?: string
|
|
}
|
|
|
|
/** 校验上传表单(版本号必填非空、文件已选且非空、仅支持 zip——对齐 admin.js:6520-6523)。 */
|
|
export function validateDigitalHumanUpload(form: DigitalHumanUploadForm): { valid: boolean; errors: DigitalHumanUploadErrors } {
|
|
const errors: DigitalHumanUploadErrors = {}
|
|
if (!(form.version || '').trim()) errors.version = '版本号不能为空'
|
|
const file = form.file
|
|
if (!file) errors.file = '请选择程序压缩包'
|
|
else if (typeof file.size === 'number' && file.size <= 0) errors.file = '压缩包为空或无效'
|
|
else if (file.name && !file.name.toLowerCase().endsWith('.zip')) errors.file = '仅支持 .zip 格式'
|
|
return { valid: Object.keys(errors).length === 0, errors }
|
|
}
|
|
|
|
/** 表单字段(multipart 文本部分;文件在 adapter 端追加),可选字段为空不下发。 */
|
|
export function buildDigitalHumanUploadFields(form: DigitalHumanUploadForm): {
|
|
version: string
|
|
changelog?: string
|
|
minClientVersion?: string
|
|
createdBy?: string
|
|
} {
|
|
const fields: { version: string; changelog?: string; minClientVersion?: string; createdBy?: string } = {
|
|
version: (form.version || '').trim(),
|
|
}
|
|
const changelog = (form.changelog || '').trim()
|
|
if (changelog) fields.changelog = changelog
|
|
const minClientVersion = (form.minClientVersion || '').trim()
|
|
if (minClientVersion) fields.minClientVersion = minClientVersion
|
|
const createdBy = (form.createdBy || '').trim()
|
|
if (createdBy) fields.createdBy = createdBy
|
|
return fields
|
|
}
|