Solian/lib/services.dart

63 lines
2.2 KiB
Dart
Raw Permalink Normal View History

2024-09-16 03:57:16 +00:00
import 'package:device_info_plus/device_info_plus.dart';
import 'package:get/get.dart';
2024-09-16 03:57:16 +00:00
import 'package:package_info_plus/package_info_plus.dart';
import 'package:solian/platform.dart';
2024-05-18 10:17:16 +00:00
abstract class ServiceFinder {
2024-09-16 03:57:16 +00:00
static const bool devFlag = false;
2024-05-18 10:17:16 +00:00
static const String dealerUrl =
devFlag ? 'http://localhost:8442' : 'https://api.sn.solsynth.dev';
static String buildUrl(String serviceName, String? append) {
append ??= '';
if (serviceName == 'dealer') {
return '$dealerUrl$append';
}
2024-07-26 17:39:20 +00:00
return '$dealerUrl/cgi/$serviceName$append';
}
2024-09-16 03:57:16 +00:00
static Future<String> getUserAgent() async {
final String platformInfo;
if (PlatformInfo.isAndroid) {
final deviceInfo = await DeviceInfoPlugin().androidInfo;
platformInfo =
'Android; ${deviceInfo.brand} ${deviceInfo.model}; ${deviceInfo.id}';
} else if (PlatformInfo.isIOS) {
final deviceInfo = await DeviceInfoPlugin().iosInfo;
platformInfo = 'iOS; ${deviceInfo.model}; ${deviceInfo.name}';
} else if (PlatformInfo.isMacOS) {
final deviceInfo = await DeviceInfoPlugin().macOsInfo;
platformInfo = 'MacOS; ${deviceInfo.model}; ${deviceInfo.hostName}';
} else if (PlatformInfo.isWindows) {
final deviceInfo = await DeviceInfoPlugin().windowsInfo;
platformInfo =
'Windows NT; ${deviceInfo.productName}; ${deviceInfo.computerName}';
} else if (PlatformInfo.isLinux) {
final deviceInfo = await DeviceInfoPlugin().linuxInfo;
platformInfo = 'Linux; ${deviceInfo.prettyName}';
} else if (PlatformInfo.isWeb) {
final deviceInfo = await DeviceInfoPlugin().webBrowserInfo;
platformInfo = 'Web; ${deviceInfo.vendor}';
} else {
platformInfo = 'Unknown';
}
final packageInfo = await PackageInfo.fromPlatform();
return 'Solian/${packageInfo.version}+${packageInfo.buildNumber} ($platformInfo)';
}
static Future<GetConnect> configureClient(String serviceName,
{timeout = const Duration(seconds: 5)}) async {
2024-06-08 13:35:50 +00:00
final client = GetConnect(
timeout: timeout,
2024-09-16 03:57:16 +00:00
userAgent: await getUserAgent(),
sendUserAgent: true,
2024-06-08 13:35:50 +00:00
);
client.httpClient.baseUrl = buildUrl(serviceName, null);
return client;
}
2024-05-25 16:11:00 +00:00
}