app/lib/common/conf/url_conf.dart

90 lines
2.6 KiB
Dart
Raw Normal View History

2024-02-03 12:28:15 +08:00
import 'package:dio/dio.dart';
import 'package:starcitizen_doctor/base/ui_model.dart';
2024-01-29 20:44:00 +08:00
class URLConf {
2024-02-03 12:28:15 +08:00
/// HOME API
static String gitApiHome = "https://git.sctoolbox.sccsgo.com";
static String rssApiHome = "https://rss.sctoolbox.sccsgo.com";
static const String xkeycApiHome = "https://sctoolbox.xkeyc.com";
2024-01-29 20:44:00 +08:00
2024-02-03 12:28:15 +08:00
static bool isUsingFallback = false;
2024-01-29 20:44:00 +08:00
2024-02-03 12:28:15 +08:00
/// URLS
static String giteaAttachmentsUrl = "$gitApiHome/SCToolBox/Release";
static String gitlabLocalizationUrl =
"$gitApiHome/SCToolBox/LocalizationData";
static String apiRepoPath = "$gitApiHome/SCToolBox/api/raw/branch/main/";
2024-01-29 20:44:00 +08:00
2024-02-03 12:28:15 +08:00
static String gitlabApiPath = "https://$gitApiHome/api/v1/";
2024-01-29 20:44:00 +08:00
2024-02-03 12:28:15 +08:00
static String webTranslateHomeUrl =
"$gitApiHome/SCToolBox/ScWeb_Chinese_Translate/raw/branch/main/json/locales";
2024-01-29 20:44:00 +08:00
2024-02-03 12:28:15 +08:00
static String rssVideoUrl =
"$rssApiHome/bilibili/user/channel/27976358/290653";
2024-01-29 20:44:00 +08:00
2024-02-03 12:28:15 +08:00
static String rssTextUrl1 = "$rssApiHome/bilibili/user/article/40102960";
static String rssTextUrl2 =
"$rssApiHome/baidu/tieba/user/%E7%81%AC%E7%81%ACG%E7%81%AC%E7%81%AC&";
static const feedbackUrl = "https://txc.qq.com/products/614843";
2024-02-03 12:28:15 +08:00
static const devReleaseUrl =
"https://git.sctoolbox.sccsgo.com/SCToolBox/Release/releases";
static const _gitApiList = [
"https://git.sctoolbox.sccsgo.com",
"https://sctb-git.xkeyc.com"
];
static const _rssApiList = [
"https://rss.sctoolbox.sccsgo.com",
"https://rss.42kit.com"
];
static checkHost() async {
final dio = Dio(BaseOptions(connectTimeout: const Duration(seconds: 5)));
bool hasAvailable = false;
// 寻找可用的 git API
for (var value in _gitApiList) {
try {
final resp = await dio.head(value);
if (resp.statusCode == 200) {
dPrint("[URLConf].checkHost passed $value");
gitApiHome = value;
hasAvailable = true;
break;
}
isUsingFallback = true;
continue;
} catch (e) {
dPrint("[URLConf].checkHost $value Error= $e");
isUsingFallback = true;
continue;
}
}
// 寻找可用的 RSS API
for (var value in _rssApiList) {
try {
final resp = await dio.head(value);
if (resp.statusCode == 200) {
rssApiHome = value;
hasAvailable = true;
dPrint("[URLConf].checkHost passed $value");
break;
}
isUsingFallback = true;
continue;
} catch (e) {
dPrint("[URLConf].checkHost $value Error= $e");
isUsingFallback = true;
continue;
}
}
if (!hasAvailable) {
isUsingFallback = false;
}
}
2024-01-29 20:44:00 +08:00
}