* 验证闪卡数据结构 * @param data 闪卡数据 * @returns 验证结果
(data: unknown)
| 166 | * @returns 验证结果 |
| 167 | */ |
| 168 | static validateFlashcardData(data: unknown): { valid: boolean; errors: string[] } { |
| 169 | const errors: string[] = []; |
| 170 | |
| 171 | if (!this.isRecord(data)) { |
| 172 | errors.push('闪卡数据必须是对象'); |
| 173 | return { valid: false, errors }; |
| 174 | } |
| 175 | |
| 176 | // 验证版本 |
| 177 | if (!data.version || typeof data.version !== 'string') { |
| 178 | errors.push('缺少有效的版本信息'); |
| 179 | } |
| 180 | |
| 181 | // 验证cards对象 |
| 182 | if (data.cards && typeof data.cards !== 'object') { |
| 183 | errors.push('cards必须是对象'); |
| 184 | } |
| 185 | |
| 186 | // 验证globalStats |
| 187 | if (data.globalStats && typeof data.globalStats !== 'object') { |
| 188 | errors.push('globalStats必须是对象'); |
| 189 | } |
| 190 | |
| 191 | // 验证cardGroups |
| 192 | if (data.cardGroups && !Array.isArray(data.cardGroups)) { |
| 193 | errors.push('cardGroups必须是数组'); |
| 194 | } |
| 195 | |
| 196 | return { valid: errors.length === 0, errors }; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * 验证文件映射数据 |