From e1108dc1a7dcb82d7cdb2f50a371359277196b62 Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Mon, 2 Oct 2023 23:56:38 +0330 Subject: [PATCH] Add retry for network ops --- lib/data/repository/profiles_repository_impl.dart | 15 +++++---------- pubspec.lock | 2 +- pubspec.yaml | 1 + 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/data/repository/profiles_repository_impl.dart b/lib/data/repository/profiles_repository_impl.dart index d9fef8fa..b414f448 100644 --- a/lib/data/repository/profiles_repository_impl.dart +++ b/lib/data/repository/profiles_repository_impl.dart @@ -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; - } - } } diff --git a/pubspec.lock b/pubspec.lock index 1e09afa8..530e2da7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1022,7 +1022,7 @@ packages: source: hosted version: "4.1.0" retry: - dependency: transitive + dependency: "direct main" description: name: retry sha256: "822e118d5b3aafed083109c72d5f484c6dc66707885e07c0fbcb8b986bba7efc" diff --git a/pubspec.yaml b/pubspec.yaml index 52540c59..ff441a94 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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