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