selfprivacy.org.app/lib/logic/api_maps/server.dart

47 lines
1 KiB
Dart
Raw Normal View History

2021-03-25 23:30:34 +00:00
import 'dart:async';
2021-01-21 21:01:42 +00:00
import 'dart:io';
2021-01-21 07:35:38 +00:00
import 'package:dio/dio.dart';
2021-03-25 23:30:34 +00:00
import 'package:selfprivacy/config/get_it_config.dart';
2021-01-21 07:35:38 +00:00
import 'api_map.dart';
2021-03-25 23:30:34 +00:00
class ServerApi extends ApiMap {
bool hasLoger;
bool isWithToken;
ServerApi({this.hasLoger = false, this.isWithToken = true});
BaseOptions get options {
var options = BaseOptions();
if (isWithToken) {
var cloudFlareDomain = getIt<ApiConfigModel>().cloudFlareDomain;
var domainName = cloudFlareDomain!.domainName;
assert(domainName != null);
options = BaseOptions(baseUrl: 'https://api.$domainName');
}
return options;
2021-01-21 21:01:42 +00:00
}
Future<bool> isHttpServerWorking() async {
bool res;
Response response;
2021-03-25 23:30:34 +00:00
var client = await getClient();
2021-01-21 21:01:42 +00:00
try {
2021-03-25 23:30:34 +00:00
response = await client.get('/serviceStatus');
2021-01-21 21:01:42 +00:00
res = response.statusCode == HttpStatus.ok;
} catch (e) {
res = false;
2021-01-21 07:35:38 +00:00
}
2021-03-25 23:30:34 +00:00
client.close();
2021-01-21 21:01:42 +00:00
return res;
2021-01-21 07:35:38 +00:00
}
2021-01-21 21:01:42 +00:00
2021-03-25 23:30:34 +00:00
String get rootAddress =>
throw UnimplementedError('not used in with implementation');
2021-01-21 21:01:42 +00:00
}