2023-10-09 09:32:07 +08:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2024-11-03 16:42:39 +08:00
|
|
|
import 'package:hive/hive.dart';
|
2024-01-29 20:44:00 +08:00
|
|
|
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
2024-02-07 19:32:36 +08:00
|
|
|
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
2023-10-09 09:32:07 +08:00
|
|
|
import 'package:starcitizen_doctor/data/app_placard_data.dart';
|
2024-02-24 18:18:35 +08:00
|
|
|
import 'package:starcitizen_doctor/data/app_torrent_data.dart';
|
2023-10-09 09:32:07 +08:00
|
|
|
import 'package:starcitizen_doctor/data/app_version_data.dart';
|
2023-11-03 00:18:45 +08:00
|
|
|
import 'package:starcitizen_doctor/data/countdown_festival_item_data.dart';
|
2024-11-05 20:42:02 +08:00
|
|
|
import 'package:starcitizen_doctor/data/input_method_api_data.dart';
|
2023-10-09 09:32:07 +08:00
|
|
|
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
|
|
|
|
|
|
|
class Api {
|
|
|
|
static Future<AppVersionData> getAppVersion() async {
|
|
|
|
return AppVersionData.fromJson(
|
|
|
|
await getRepoJson("sc_doctor", "version.json"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<AppPlacardData> getAppPlacard() async {
|
|
|
|
return AppPlacardData.fromJson(
|
|
|
|
await getRepoJson("sc_doctor", "placard.json"));
|
|
|
|
}
|
|
|
|
|
2023-11-03 00:18:45 +08:00
|
|
|
static Future<List<CountdownFestivalItemData>>
|
|
|
|
getFestivalCountdownList() async {
|
|
|
|
List<CountdownFestivalItemData> l = [];
|
|
|
|
final r = json.decode(await getRepoData("sc_doctor", "countdown.json"));
|
|
|
|
if (r is List) {
|
|
|
|
for (var element in r) {
|
|
|
|
l.add(CountdownFestivalItemData.fromJson(element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l.sort((a, b) => (a.time ?? 0) - (b.time ?? 0));
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2023-10-09 09:32:07 +08:00
|
|
|
static Future<Map<String, dynamic>> getAppReleaseDataByVersionName(
|
|
|
|
String version) async {
|
2024-02-07 19:32:36 +08:00
|
|
|
final r = await RSHttp.getText(
|
2024-02-07 23:26:14 +08:00
|
|
|
"${URLConf.gitlabApiPath}repos/SCToolBox/Release/releases/tags/$version");
|
2024-02-07 00:20:06 +08:00
|
|
|
return json.decode(r);
|
2023-10-09 09:32:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static Future<List<ScLocalizationData>> getScLocalizationData(
|
|
|
|
String lang) async {
|
|
|
|
final data = json.decode(await getRepoData("localizations", "$lang.json"));
|
|
|
|
List<ScLocalizationData> l = [];
|
|
|
|
if (data is List) {
|
|
|
|
for (var element in data) {
|
|
|
|
l.add(ScLocalizationData.fromJson(element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2024-11-05 20:42:02 +08:00
|
|
|
static Future<InputMethodApiData> getCommunityInputMethodIndexData() async {
|
|
|
|
final data = await getCommunityInputMethodData("index.json");
|
|
|
|
return InputMethodApiData.fromJson(json.decode(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<String> getCommunityInputMethodData(String file) async {
|
|
|
|
return getRepoData("input_method", file);
|
|
|
|
}
|
|
|
|
|
2024-02-24 18:18:35 +08:00
|
|
|
static Future<List<AppTorrentData>> getAppTorrentDataList() async {
|
|
|
|
final data = await getRepoData("sc_doctor", "torrent.json");
|
|
|
|
final dataJson = json.decode(data);
|
|
|
|
List<AppTorrentData> l = [];
|
|
|
|
if (dataJson is List) {
|
|
|
|
for (var value in dataJson) {
|
|
|
|
l.add(AppTorrentData.fromJson(value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2024-02-24 21:48:29 +08:00
|
|
|
static Future<String> getTorrentTrackerList() async {
|
|
|
|
final data = await getRepoData("sc_doctor", "tracker.list");
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2023-10-16 23:24:10 +08:00
|
|
|
static Future<List> getScServerStatus() async {
|
2024-02-07 19:32:36 +08:00
|
|
|
final r = await RSHttp.getText(
|
|
|
|
"https://status.robertsspaceindustries.com/index.json");
|
2024-02-07 00:20:06 +08:00
|
|
|
final map = json.decode(r);
|
|
|
|
return map["systems"];
|
2023-10-16 23:24:10 +08:00
|
|
|
}
|
|
|
|
|
2023-10-09 09:32:07 +08:00
|
|
|
static Future<Map<String, dynamic>> getRepoJson(
|
|
|
|
String dir, String name) async {
|
|
|
|
final data = await getRepoData(dir, name);
|
|
|
|
return json.decode(data);
|
|
|
|
}
|
|
|
|
|
2024-02-07 00:20:06 +08:00
|
|
|
static Future<String> getRepoData(String dir, String name) async {
|
2024-11-05 20:42:02 +08:00
|
|
|
final r = await RSHttp.getText("${URLConf.apiRepoPath}/$dir/$name",
|
|
|
|
withCustomDns: await isUseInternalDNS());
|
2024-02-07 00:20:06 +08:00
|
|
|
return r;
|
2023-10-09 09:32:07 +08:00
|
|
|
}
|
2024-11-03 16:42:39 +08:00
|
|
|
|
|
|
|
static Future<bool> isUseInternalDNS() async {
|
|
|
|
final userBox = await Hive.openBox("app_conf");
|
2024-11-05 20:42:02 +08:00
|
|
|
final isUseInternalDNS =
|
|
|
|
userBox.get("isUseInternalDNS", defaultValue: false);
|
2024-11-03 16:42:39 +08:00
|
|
|
return isUseInternalDNS;
|
|
|
|
}
|
2023-10-09 09:32:07 +08:00
|
|
|
}
|