import 'dart:convert'; import 'dart:typed_data'; import 'package:starcitizen_doctor/common/conf/const_conf.dart'; import 'package:starcitizen_doctor/common/rust/api/http_api.dart' as rust_http; import 'package:starcitizen_doctor/common/rust/api/http_api.dart'; import 'package:starcitizen_doctor/common/rust/http_package.dart'; class RSHttp { static init() async { await rust_http.setDefaultHeader(headers: { "User-Agent": "SCToolBox/${ConstConf.appVersion} (${ConstConf.appVersionCode})${ConstConf.isMSE ? "" : " DEV"} RSHttp" }); } static Future get( String url, { Map? headers, String? withIpAddress, bool? withCustomDns, }) async { final r = await rust_http.fetch( method: MyMethod.gets, url: url, headers: headers, withIpAddress: withIpAddress, withCustomDns: withCustomDns, ); return r; } static Future getText( String url, { Map? headers, String? withIpAddress, bool? withCustomDns, }) async { final r = await get(url, headers: headers, withIpAddress: withIpAddress, withCustomDns: withCustomDns); if (r.data == null) return ""; final str = utf8.decode(r.data!); return str; } static Future postData( String url, { Map? headers, String? contentType, Uint8List? data, String? withIpAddress, bool? withCustomDns, }) async { if (contentType != null) { headers ??= {}; headers["Content-Type"] = contentType; } final r = await rust_http.fetch( method: MyMethod.post, url: url, headers: headers, inputData: data, withIpAddress: withIpAddress, withCustomDns: withCustomDns, ); return r; } static Future head( String url, { Map? headers, String? withIpAddress, bool? withCustomDns, }) async { final r = await rust_http.fetch( method: MyMethod.head, url: url, headers: headers, withIpAddress: withIpAddress, withCustomDns: withCustomDns, ); return r; } static Future> dnsLookupTxt(String host) async { return await rust_http.dnsLookupTxt(host: host); } static Future> dnsLookupIps(String host) async { return await rust_http.dnsLookupIps(host: host); } }