TF-629 Download file and get the contentType to open file in Android/iOS

This commit is contained in:
Dat PHAM HOANG
2022-06-08 22:25:00 +07:00
committed by Dat H. Pham
parent 40a470dc21
commit ee692d52a2
14 changed files with 179 additions and 114 deletions
@@ -1,3 +1,4 @@
import 'package:core/core.dart';
import 'package:dio/dio.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
@@ -19,7 +20,7 @@ abstract class EmailRepository {
AccountRequest accountRequest
);
Future<String> exportAttachment(
Future<DownloadedResponse> exportAttachment(
Attachment attachment,
AccountId accountId,
String baseDownloadUrl,
@@ -1,16 +1,16 @@
import 'package:core/core.dart';
class ExportAttachmentSuccess extends UIState {
final String filePath;
final DownloadedResponse downloadedResponse;
ExportAttachmentSuccess(this.filePath);
ExportAttachmentSuccess(this.downloadedResponse);
@override
List<Object> get props => [filePath];
List<Object> get props => [downloadedResponse];
}
class ExportAttachmentFailure extends FeatureFailure {
final exception;
final dynamic exception;
ExportAttachmentFailure(this.exception);
@@ -35,7 +35,7 @@ class ExportAttachmentInteractor {
log('ExportAttachmentInteractor::execute(): account: $account');
final filePath = await Future.wait([
final downloadedResponse = await Future.wait([
if (account.authenticationType == AuthenticationType.oidc)
_authenticationOIDCRepository.getStoredTokenOIDC(account.id)
else
@@ -66,7 +66,7 @@ class ExportAttachmentInteractor {
accountRequest,
cancelToken);
});
yield Right<Failure, Success>(ExportAttachmentSuccess(filePath));
yield Right<Failure, Success>(ExportAttachmentSuccess(downloadedResponse));
} catch (exception) {
log('ExportAttachmentInteractor::execute(): exception: $exception');
yield Left<Failure, Success>(ExportAttachmentFailure(exception));