mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/app.git
synced 2025-06-28 12:34:45 +08:00
改用 rust 实现的 http client
This commit is contained in:
@ -1,17 +1,19 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/api/http_api.dart' as rust_http;
|
||||
|
||||
class AnalyticsApi {
|
||||
static final Dio _dio = Dio();
|
||||
|
||||
static touch(String key) async {
|
||||
// debug 不统计
|
||||
if (kDebugMode) return;
|
||||
dPrint("AnalyticsApi.touch === $key start");
|
||||
try {
|
||||
await _dio.post("${URLConf.xkeycApiHome}/analytics/$key");
|
||||
await rust_http.postJsonString(
|
||||
url: "${URLConf.xkeycApiHome}/analytics/$key",
|
||||
jsonData: json.encode({"test": "a"}));
|
||||
dPrint("AnalyticsApi.touch === $key over");
|
||||
} catch (e) {
|
||||
dPrint("AnalyticsApi.touch === $key Error:$e");
|
||||
|
@ -1,16 +1,13 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/api/http_api.dart' as rust_http;
|
||||
import 'package:starcitizen_doctor/data/app_placard_data.dart';
|
||||
import 'package:starcitizen_doctor/data/app_version_data.dart';
|
||||
import 'package:starcitizen_doctor/data/countdown_festival_item_data.dart';
|
||||
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
||||
|
||||
class Api {
|
||||
static final dio =
|
||||
Dio(BaseOptions(connectTimeout: const Duration(seconds: 10)));
|
||||
|
||||
static Future<AppVersionData> getAppVersion() async {
|
||||
return AppVersionData.fromJson(
|
||||
await getRepoJson("sc_doctor", "version.json"));
|
||||
@ -36,9 +33,10 @@ class Api {
|
||||
|
||||
static Future<Map<String, dynamic>> getAppReleaseDataByVersionName(
|
||||
String version) async {
|
||||
final r = await dio.get(
|
||||
"${URLConf.gitlabApiPath}/repos/SCToolBox/Release/releases/tags/$version");
|
||||
return r.data;
|
||||
final r = await rust_http.getString(
|
||||
url:
|
||||
"${URLConf.gitlabApiPath}/repos/SCToolBox/Release/releases/tags/$version");
|
||||
return json.decode(r);
|
||||
}
|
||||
|
||||
static Future<List<ScLocalizationData>> getScLocalizationData(
|
||||
@ -54,9 +52,10 @@ class Api {
|
||||
}
|
||||
|
||||
static Future<List> getScServerStatus() async {
|
||||
final r =
|
||||
await dio.get("https://status.robertsspaceindustries.com/index.json");
|
||||
return r.data["systems"];
|
||||
final r = await rust_http.getString(
|
||||
url: "https://status.robertsspaceindustries.com/index.json");
|
||||
final map = json.decode(r);
|
||||
return map["systems"];
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> getRepoJson(
|
||||
@ -65,8 +64,9 @@ class Api {
|
||||
return json.decode(data);
|
||||
}
|
||||
|
||||
static Future getRepoData(String dir, String name) async {
|
||||
final r = await dio.get("${URLConf.apiRepoPath}/$dir/$name");
|
||||
return r.data;
|
||||
static Future<String> getRepoData(String dir, String name) async {
|
||||
final r =
|
||||
await rust_http.getString(url: "${URLConf.apiRepoPath}/$dir/$name");
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,21 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dart_rss/dart_rss.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/api/http_api.dart' as rust_http;
|
||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
||||
|
||||
class RSSApi {
|
||||
static final _dio = Dio(BaseOptions(
|
||||
connectTimeout: const Duration(seconds: 10),
|
||||
responseType: ResponseType.plain));
|
||||
|
||||
static Future<List<RssItem>> getRssVideo() async {
|
||||
final r = await _dio.get(URLConf.rssVideoUrl);
|
||||
final f = RssFeed.parse(r.data);
|
||||
final r = await rust_http.getString(url: URLConf.rssVideoUrl);
|
||||
final f = RssFeed.parse(r);
|
||||
return f.items.sublist(0, 8);
|
||||
}
|
||||
|
||||
static Future<List<RssItem>> getRssText() async {
|
||||
final r1 = await _dio.get(URLConf.rssTextUrl1);
|
||||
final r1f = RssFeed.parse(r1.data);
|
||||
final r2 = await _dio.get(URLConf.rssTextUrl2);
|
||||
final r2f = RssFeed.parse(r2.data);
|
||||
final r1 = await rust_http.getString(url: URLConf.rssTextUrl1);
|
||||
final r1f = RssFeed.parse(r1);
|
||||
final r2 = await rust_http.getString(url: URLConf.rssTextUrl2);
|
||||
final r2f = RssFeed.parse(r2);
|
||||
final items = r1f.items..addAll(r2f.items);
|
||||
items.sort((a, b) {
|
||||
final aDate = HttpDate.parse(a.pubDate ?? "").millisecondsSinceEpoch;
|
||||
|
Reference in New Issue
Block a user