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-06-08 18:52:44 +00:00
|
|
|
import 'package:selfprivacy/logic/models/user.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;
|
|
|
|
|
|
|
|
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-26 13:38:39 +00:00
|
|
|
close(client);
|
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-06-08 18:52:44 +00:00
|
|
|
Future<bool> createUser(User user) async {
|
|
|
|
bool res;
|
|
|
|
Response response;
|
|
|
|
|
|
|
|
var client = await getClient();
|
|
|
|
try {
|
|
|
|
response = await client.get('/createUser');
|
|
|
|
res = response.statusCode == HttpStatus.ok;
|
|
|
|
} catch (e) {
|
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
close(client);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|