Skip to content

Commit

Permalink
Merge pull request Suwayomi#110 from DattatreyaReddy:backup-cleanup
Browse files Browse the repository at this point in the history
clean up
  • Loading branch information
DattatreyaReddy authored Feb 2, 2023
2 parents 66b66e5 + c7257aa commit f84c2f1
Showing 1 changed file with 25 additions and 44 deletions.
69 changes: 25 additions & 44 deletions lib/src/features/settings/data/backup/backup_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,32 @@ class BackupRepository {
final DioClient dioClient;

Future<BackupMissing?> restoreBackup(PlatformFile? file) async {
if (kIsWeb == false) {
if ((file?.path).isBlank) {
throw LocaleKeys.error_filePick.tr();
}
if (!(file!.name.endsWith('.proto.gz'))) {
throw LocaleKeys.error_filePickUnknownExtension
.tr(namedArgs: {"extensionName": ".proto.gz"});
}
return (file.path).isNotBlank
? (await dioClient.post<BackupMissing, BackupMissing?>(
BackupUrl.import,
data: FormData.fromMap({
'backup.proto.gz': MultipartFile.fromFileSync(
file.path!,
filename: "backup.proto.gz",
)
}),
decoder: (e) =>
e is Map<String, dynamic> ? BackupMissing.fromJson(e) : null,
))
.data
: null;
} else {
if ((file?.bytes).isBlank) {
throw LocaleKeys.error_filePick.tr();
}
if (!(file!.name.endsWith('.proto.gz'))) {
throw LocaleKeys.error_filePickUnknownExtension
.tr(namedArgs: {"extensionName": ".proto.gz"});
}
return (file.bytes).isNotBlank
? (await dioClient.post<BackupMissing, BackupMissing?>(
BackupUrl.import,
data: FormData.fromMap({
'backup.proto.gz': MultipartFile.fromBytes(
file.bytes as List<int>,
filename: "backup.proto.gz",
)
}),
decoder: (e) =>
e is Map<String, dynamic> ? BackupMissing.fromJson(e) : null,
))
.data
: null;
if ((file?.name).isBlank ||
(kIsWeb && (file?.bytes).isBlank ||
(!kIsWeb && (file?.path).isBlank))) {
throw LocaleKeys.error_filePick.tr();
}
if (!(file!.name.endsWith('.proto.gz'))) {
throw LocaleKeys.error_filePickUnknownExtension
.tr(namedArgs: {"extensionName": ".proto.gz"});
}
return (await dioClient.post<BackupMissing, BackupMissing?>(
BackupUrl.import,
data: FormData.fromMap({
'backup.proto.gz': kIsWeb
? MultipartFile.fromBytes(
file.bytes!,
filename: "backup.proto.gz",
)
: MultipartFile.fromFileSync(
file.path!,
filename: "backup.proto.gz",
)
}),
decoder: (e) =>
e is Map<String, dynamic> ? BackupMissing.fromJson(e) : null,
))
.data;
}
}

Expand Down

0 comments on commit f84c2f1

Please sign in to comment.