fix: alot
This commit is contained in:
@@ -19,22 +19,34 @@ abstract class ExportService {
|
||||
/// failed backup is logged but never interrupts the bar.
|
||||
class DefaultExportService implements ExportService {
|
||||
final BarTabService barTabService;
|
||||
final Future<String?> Function()? authToken;
|
||||
final http.Client _client;
|
||||
|
||||
DefaultExportService({required this.barTabService, http.Client? client})
|
||||
: _client = client ?? http.Client();
|
||||
DefaultExportService({
|
||||
required this.barTabService,
|
||||
this.authToken,
|
||||
http.Client? client,
|
||||
}) : _client = client ?? http.Client();
|
||||
|
||||
static const _timeout = Duration(seconds: 30);
|
||||
|
||||
@override
|
||||
Future<void> uploadToServer() async {
|
||||
try {
|
||||
final closedTabs = await barTabService.getClosedTabs();
|
||||
final appVersion = (await PackageInfo.fromPlatform()).version;
|
||||
final token = await authToken?.call();
|
||||
|
||||
final response = await _client.post(
|
||||
Uri.parse(kExportServerUrl),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode(_buildPayload(closedTabs, appVersion: appVersion)),
|
||||
);
|
||||
final response = await _client
|
||||
.post(
|
||||
Uri.parse(kExportServerUrl),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
if (token != null) 'Authorization': 'Bearer $token',
|
||||
},
|
||||
body: jsonEncode(_buildPayload(closedTabs, appVersion: appVersion)),
|
||||
)
|
||||
.timeout(_timeout);
|
||||
|
||||
if (response.statusCode != 200 && response.statusCode != 201) {
|
||||
unawaited(
|
||||
|
||||
Reference in New Issue
Block a user