2021-02-03 19:51:07 +00:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
|
|
|
|
|
|
|
class BackblazeApi extends ApiMap {
|
2021-03-15 15:39:44 +00:00
|
|
|
BackblazeApi([String? token]) {
|
2021-02-03 19:51:07 +00:00
|
|
|
if (token != null) {
|
|
|
|
loggedClient.options = BaseOptions(
|
|
|
|
headers: {'Authorization': 'Basic $token'},
|
2021-03-15 15:39:44 +00:00
|
|
|
baseUrl: rootAddress!,
|
2021-02-03 19:51:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2021-03-15 15:39:44 +00:00
|
|
|
String? rootAddress =
|
2021-02-03 19:51:07 +00:00
|
|
|
'https://api.backblazeb2.com/b2api/v2/b2_authorize_account';
|
|
|
|
|
|
|
|
Future<bool> isValid(String token) async {
|
|
|
|
var options = Options(
|
|
|
|
headers: {'Authorization': 'Basic $token'},
|
|
|
|
validateStatus: (status) {
|
|
|
|
return status == HttpStatus.ok || status == HttpStatus.unauthorized;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-03-15 15:39:44 +00:00
|
|
|
Response response = await loggedClient.get(rootAddress!, options: options);
|
2021-02-03 19:51:07 +00:00
|
|
|
|
|
|
|
if (response.statusCode == HttpStatus.ok) {
|
|
|
|
return true;
|
|
|
|
} else if (response.statusCode == HttpStatus.unauthorized) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
throw Exception('code: ${response.statusCode}');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|