@@ -36,6 +36,53 @@ class HfModelDownloader {
3636
3737 // ── Public entry-point ──────────────────────────────────────────────
3838
39+ /// Validates whether [repoUrl] contains the files required by this
40+ /// downloader. Returns `null` if valid, otherwise a Chinese error message
41+ /// describing what is missing.
42+ static Future <String ?> validateRepoFiles (String repoUrl) async {
43+ final base = _parseBase (repoUrl);
44+ if (base == null ) return '无效的 HuggingFace 地址' ;
45+
46+ final (host, ownerRepo) = base ;
47+ final apiUrl = 'https://$host /api/models/$ownerRepo ' ;
48+
49+ try {
50+ final response = await Dio ().get (apiUrl);
51+ final data = response.data;
52+ if (data is ! Map <String , dynamic >) return '无法解析仓库信息' ;
53+
54+ final siblings = data['siblings' ] as List <dynamic >? ;
55+ if (siblings == null ) return '无法获取仓库文件列表' ;
56+
57+ final files = siblings
58+ .whereType <Map <String , dynamic >>()
59+ .map ((e) => e['rfilename' ] as String ? )
60+ .whereType <String >()
61+ .toSet ();
62+
63+ final hasTokenizer = _tokenizerPriority.any (files.contains) ||
64+ (files.contains ('vocab.json' ) && files.contains ('merges.txt' ));
65+ final hasVision = _visionPriority.any (files.contains);
66+ final hasText = _textPriority.any (files.contains);
67+
68+ if (hasTokenizer && hasVision && hasText) return null ;
69+
70+ final missing = < String > [];
71+ if (! hasTokenizer) missing.add ('tokenizer.json(或 vocab.json + merges.txt)' );
72+ if (! hasVision) missing.add ('vision_model.onnx/tflite 或 image_encoder.onnx/tflite' );
73+ if (! hasText) missing.add ('text_model.onnx/tflite 或 text_encoder.onnx/tflite' );
74+
75+ return '该仓库缺少必要文件:${missing .join ('、' )}' ;
76+ } on DioException catch (e) {
77+ if (e.response? .statusCode == 404 ) {
78+ return '仓库不存在或无法访问' ;
79+ }
80+ return '检查仓库文件失败:${e .message }' ;
81+ } catch (e) {
82+ return '检查仓库文件失败:$e ' ;
83+ }
84+ }
85+
3986 /// Download all required files from a HuggingFace repo.
4087 ///
4188 /// [repoUrl] can be any HuggingFace URL pattern:
0 commit comments