feat(app): 完善播放协议搜索与空状态
This commit is contained in:
1 parent
671e0ce143
commit
ef29fc5f15
85 files changed
+2976
-768
No files matched your search
@@ -0,0 +1,36 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../config/app_config.dart';
|
||||
|
||||
final RegExp _articlePattern = RegExp(
|
||||
'<article>([\\s\\S]*)</article>',
|
||||
caseSensitive: false,
|
||||
);
|
||||
|
||||
/// 从协议页里取出正文。没有 article 时退回整页。
|
||||
String legalArticle(String html) {
|
||||
final match = _articlePattern.firstMatch(html);
|
||||
final body = match?.group(1);
|
||||
if (body == null || body.trim().isEmpty) return html;
|
||||
return body.trim();
|
||||
}
|
||||
|
||||
/// 拉取协议页 HTML。不走业务 JSON 包装。
|
||||
Future<String> fetchLegalArticle(String url) async {
|
||||
final dio = Dio(
|
||||
BaseOptions(
|
||||
connectTimeout: AppConfig.requestTimeout,
|
||||
receiveTimeout: AppConfig.requestTimeout,
|
||||
responseType: ResponseType.plain,
|
||||
validateStatus: (code) => code != null && code >= 200 && code < 300,
|
||||
),
|
||||
);
|
||||
final response = await dio.get<String>(url);
|
||||
final body = response.data;
|
||||
if (body == null || body.trim().isEmpty) {
|
||||
throw StateError('empty legal page');
|
||||
}
|
||||
return legalArticle(body);
|
||||
}
|
||||
Reference in new issue
Block a user