Add retry for network ops
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
@@ -11,6 +10,7 @@ import 'package:hiddify/domain/singbox/singbox.dart';
|
||||
import 'package:hiddify/services/files_editor_service.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:retry/retry.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class ProfilesRepositoryImpl
|
||||
@@ -258,7 +258,10 @@ class ProfilesRepositoryImpl
|
||||
final tempPath = filesEditor.tempConfigPath(fileName);
|
||||
final path = filesEditor.configPath(fileName);
|
||||
try {
|
||||
final response = await dio.download(url.trim(), tempPath);
|
||||
final response = await retry(
|
||||
() async => dio.download(url.trim(), tempPath),
|
||||
maxAttempts: 3,
|
||||
);
|
||||
final headers =
|
||||
await _populateHeaders(response.headers.map, tempPath);
|
||||
final parseResult =
|
||||
@@ -317,12 +320,4 @@ class ProfilesRepositoryImpl
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
String safeDecodeBase64(String str) {
|
||||
try {
|
||||
return utf8.decode(base64.decode(str));
|
||||
} catch (e) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1022,7 +1022,7 @@ packages:
|
||||
source: hosted
|
||||
version: "4.1.0"
|
||||
retry:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: retry
|
||||
sha256: "822e118d5b3aafed083109c72d5f484c6dc66707885e07c0fbcb8b986bba7efc"
|
||||
|
||||
@@ -72,6 +72,7 @@ dependencies:
|
||||
tint: ^2.0.1
|
||||
accessibility_tools: ^1.0.0
|
||||
neat_periodic_task: ^2.0.1
|
||||
retry: ^3.1.2
|
||||
|
||||
# widgets
|
||||
go_router: ^11.1.2
|
||||
|
||||
Reference in New Issue
Block a user