(name: string)
| 334 | * 创建存储验证器 |
| 335 | */ |
| 336 | export function validateStorageName(name: string): AppError | null { |
| 337 | if (!name || typeof name !== 'string') { |
| 338 | return AppError.validation('存储名称不能为空', { name }) |
| 339 | } |
| 340 | |
| 341 | if (name.trim().length === 0) { |
| 342 | return AppError.validation('存储名称不能为空', { name }) |
| 343 | } |
| 344 | |
| 345 | if (name.length > STORAGE_CONSTANTS.STORAGE_NAME_MAX_LENGTH) { |
| 346 | return AppError.validation( |
| 347 | `存储名称长度不能超过 ${STORAGE_CONSTANTS.STORAGE_NAME_MAX_LENGTH} 字符`, |
| 348 | { name, maxLength: STORAGE_CONSTANTS.STORAGE_NAME_MAX_LENGTH } |
| 349 | ) |
| 350 | } |
| 351 | |
| 352 | // 检查非法字符 |
| 353 | const invalidChars = STORAGE_CONSTANTS.INVALID_STORAGE_CHARS.filter(char => name.includes(char)) |
| 354 | |
| 355 | if (invalidChars.length > 0) { |
| 356 | return AppError.validation('存储名称包含非法字符', { |
| 357 | name, |
| 358 | invalidChars, |
| 359 | }) |
| 360 | } |
| 361 | |
| 362 | return null |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * 创建安全的存储添加函数 |
no test coverage detected