TF-296 Fix download file on browser

This commit is contained in:
dab246
2022-03-03 13:54:23 +07:00
committed by Dat H. Pham
parent a24a4a2bfd
commit 7beebfebc8
19 changed files with 221 additions and 32 deletions
@@ -27,6 +27,13 @@ abstract class EmailRepository {
CancelToken cancelToken
);
Future<bool> downloadAttachmentForWeb(
Attachment attachment,
AccountId accountId,
String baseDownloadUrl,
AccountRequest accountRequest,
);
Future<List<EmailId>> moveToMailbox(AccountId accountId, MoveRequest moveRequest);
Future<List<Email>> markAsStar(
@@ -0,0 +1,18 @@
import 'package:core/core.dart';
class DownloadAttachmentForWebSuccess extends UIState {
DownloadAttachmentForWebSuccess();
@override
List<Object> get props => [];
}
class DownloadAttachmentForWebFailure extends FeatureFailure {
final exception;
DownloadAttachmentForWebFailure(this.exception);
@override
List<Object> get props => [exception];
}
@@ -0,0 +1,39 @@
import 'dart:async';
import 'package:core/core.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:model/model.dart';
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
class DownloadAttachmentForWebInteractor {
final EmailRepository emailRepository;
final CredentialRepository credentialRepository;
DownloadAttachmentForWebInteractor(this.emailRepository, this.credentialRepository);
Stream<Either<Failure, Success>> execute(Attachment attachment, AccountId accountId, String baseDownloadUrl,) async* {
try {
final result = await Future.wait(
[credentialRepository.getUserName(), credentialRepository.getPassword()],
eagerError: true
).then((List responses) async {
final accountRequest = AccountRequest(responses.first, responses.last);
return await emailRepository.downloadAttachmentForWeb(
attachment,
accountId,
baseDownloadUrl,
accountRequest);
});
if (result) {
yield Right<Failure, Success>(DownloadAttachmentForWebSuccess());
} else {
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(null));
}
} catch (exception) {
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(exception));
}
}
}