TF-940 Fix can not download attachment

This commit is contained in:
dab246
2022-09-22 00:07:23 +07:00
committed by Dat H. Pham
parent 6bbc63cc2e
commit 3354461e1f
3 changed files with 61 additions and 68 deletions
@@ -41,41 +41,39 @@ class DownloadAttachmentForWebInteractor {
onReceiveController.add(Right(StartDownloadAttachmentForWeb(taskId, attachment)));
final currentAccount = await _accountRepository.getCurrentAccount();
AccountRequest? accountRequest;
final bytesDownloaded = await Future.wait([
if (currentAccount.authenticationType == AuthenticationType.oidc)
_authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id)
else
credentialRepository.getAuthenticationInfoStored()
], eagerError: true).then((List responses) async {
AccountRequest accountRequest;
if (currentAccount.authenticationType == AuthenticationType.oidc) {
final tokenOidc = responses.first as TokenOIDC;
if (currentAccount.authenticationType == AuthenticationType.oidc) {
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
accountRequest = AccountRequest(
token: tokenOidc.toToken(),
authenticationType: AuthenticationType.oidc);
} else {
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
if (authenticationInfoCache != null) {
accountRequest = AccountRequest(
token: tokenOidc.toToken(),
authenticationType: AuthenticationType.oidc);
} else {
accountRequest = AccountRequest(
userName: responses.first as UserName,
password: responses.last as Password,
userName: UserName(authenticationInfoCache.username),
password: Password(authenticationInfoCache.password),
authenticationType: AuthenticationType.basic);
}
}
return await emailRepository.downloadAttachmentForWeb(
if (accountRequest != null) {
final bytesDownloaded = await emailRepository.downloadAttachmentForWeb(
taskId,
attachment,
accountId,
baseDownloadUrl,
accountRequest,
onReceiveController
);
});
onReceiveController);
yield Right<Failure, Success>(DownloadAttachmentForWebSuccess(
taskId,
attachment,
bytesDownloaded));
yield Right<Failure, Success>(DownloadAttachmentForWebSuccess(
taskId,
attachment,
bytesDownloaded));
} else {
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(taskId, null));
}
} catch (exception) {
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(
taskId,
@@ -32,39 +32,36 @@ class DownloadAttachmentsInteractor {
String baseDownloadUrl
) async* {
try {
final account = await _accountRepository.getCurrentAccount();
final currentAccount = await _accountRepository.getCurrentAccount();
log('ExportAttachmentInteractor::execute(): account: $account');
AccountRequest? accountRequest;
final taskIds = await Future.wait([
if (account.authenticationType == AuthenticationType.oidc)
_authenticationOIDCRepository.getStoredTokenOIDC(account.id)
else
credentialRepository.getAuthenticationInfoStored()
], eagerError: true
).then((List responses) async {
AccountRequest accountRequest;
if (account.authenticationType == AuthenticationType.oidc) {
final tokenOidc = responses.first as TokenOIDC;
if (currentAccount.authenticationType == AuthenticationType.oidc) {
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
accountRequest = AccountRequest(
token: tokenOidc.toToken(),
authenticationType: AuthenticationType.oidc);
} else {
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
if (authenticationInfoCache != null) {
accountRequest = AccountRequest(
token: tokenOidc.toToken(),
authenticationType: AuthenticationType.oidc);
} else {
accountRequest = AccountRequest(
userName: responses.first as UserName,
password: responses.last as Password,
userName: UserName(authenticationInfoCache.username),
password: Password(authenticationInfoCache.password),
authenticationType: AuthenticationType.basic);
}
}
return await emailRepository.downloadAttachments(
if (accountRequest != null) {
final taskIds = await emailRepository.downloadAttachments(
attachments,
accountId,
baseDownloadUrl,
accountRequest);
});
yield Right<Failure, Success>(DownloadAttachmentsSuccess(taskIds));
yield Right<Failure, Success>(DownloadAttachmentsSuccess(taskIds));
} else {
yield Left<Failure, Success>(DownloadAttachmentsFailure(null));
}
} catch (exception) {
log('DownloadAttachmentsInteractor::execute(): $exception');
if (exception is DownloadAttachmentHasTokenExpiredException) {
@@ -31,39 +31,37 @@ class ExportAttachmentInteractor {
CancelToken cancelToken
) async* {
try {
final account = await _accountRepository.getCurrentAccount();
final currentAccount = await _accountRepository.getCurrentAccount();
log('ExportAttachmentInteractor::execute(): account: $account');
AccountRequest? accountRequest;
final downloadedResponse = await Future.wait([
if (account.authenticationType == AuthenticationType.oidc)
_authenticationOIDCRepository.getStoredTokenOIDC(account.id)
else
credentialRepository.getAuthenticationInfoStored()
], eagerError: true
).then((List responses) async {
AccountRequest accountRequest;
if (account.authenticationType == AuthenticationType.oidc) {
final tokenOidc = responses.first as TokenOIDC;
if (currentAccount.authenticationType == AuthenticationType.oidc) {
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
accountRequest = AccountRequest(
token: tokenOidc.toToken(),
authenticationType: AuthenticationType.oidc);
} else {
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
if (authenticationInfoCache != null) {
accountRequest = AccountRequest(
token: tokenOidc.toToken(),
authenticationType: AuthenticationType.oidc);
} else {
accountRequest = AccountRequest(
userName: responses.first as UserName,
password: responses.last as Password,
userName: UserName(authenticationInfoCache.username),
password: Password(authenticationInfoCache.password),
authenticationType: AuthenticationType.basic);
}
}
return await emailRepository.exportAttachment(
if (accountRequest != null) {
final downloadedResponse = await emailRepository.exportAttachment(
attachment,
accountId,
baseDownloadUrl,
accountRequest,
cancelToken);
});
yield Right<Failure, Success>(ExportAttachmentSuccess(downloadedResponse));
yield Right<Failure, Success>(ExportAttachmentSuccess(downloadedResponse));
} else {
yield Left<Failure, Success>(ExportAttachmentFailure(null));
}
} catch (exception) {
log('ExportAttachmentInteractor::execute(): exception: $exception');
yield Left<Failure, Success>(ExportAttachmentFailure(exception));