TF-761 Update repository/datasource/interactor of downloadImageAsBase64

This commit is contained in:
dab246
2022-07-28 14:34:28 +07:00
committed by Dat H. Pham
parent d8e119ee7c
commit 8e22bec3f1
6 changed files with 34 additions and 11 deletions
@@ -1,4 +1,6 @@
import 'package:model/upload/file_info.dart';
abstract class ComposerDataSource {
Future<String?> downloadImageAsBase64(String url);
Future<String?> downloadImageAsBase64(String url, String cid, FileInfo fileInfo, {double? maxWidth, bool? compress});
}
@@ -1,5 +1,6 @@
import 'package:core/core.dart';
import 'package:model/upload/file_info.dart';
import 'package:tmail_ui_user/features/composer/data/datasource/composer_datasource.dart';
class ComposerDataSourceImpl extends ComposerDataSource {
@@ -9,7 +10,14 @@ class ComposerDataSourceImpl extends ComposerDataSource {
ComposerDataSourceImpl(this.downloadClient);
@override
Future<String?> downloadImageAsBase64(String url) {
return downloadClient.downloadImageAsBase64(url);
Future<String?> downloadImageAsBase64(String url, String cid, FileInfo fileInfo, {double? maxWidth, bool? compress}) {
return downloadClient.downloadImageAsBase64(
url,
cid,
fileInfo.fileExtension,
fileInfo.fileName,
bytesData: fileInfo.bytes,
maxWidth: maxWidth,
compress: compress);
}
}
@@ -21,7 +21,7 @@ class ComposerRepositoryImpl extends ComposerRepository {
}
@override
Future<String?> downloadImageAsBase64(String url) {
return _composerDataSource.downloadImageAsBase64(url);
Future<String?> downloadImageAsBase64(String url, String cid, FileInfo fileInfo, {double? maxWidth, bool? compress}) {
return _composerDataSource.downloadImageAsBase64(url, cid, fileInfo, maxWidth: maxWidth, compress: compress);
}
}
@@ -5,5 +5,5 @@ import 'package:tmail_ui_user/features/upload/domain/model/upload_attachment.dar
abstract class ComposerRepository {
UploadAttachment uploadAttachment(FileInfo fileInfo, Uri uploadUri, {CancelToken? cancelToken});
Future<String?> downloadImageAsBase64(String url);
Future<String?> downloadImageAsBase64(String url, String cid, FileInfo fileInfo, {double? maxWidth, bool? compress});
}
@@ -13,14 +13,14 @@ class DownloadingImageAsBase64 extends UIState {
class DownloadImageAsBase64Success extends UIState {
final String imageAsBase64;
final String base64Uri;
final String cid;
final FileInfo fileInfo;
DownloadImageAsBase64Success(this.imageAsBase64, this.cid, this.fileInfo);
DownloadImageAsBase64Success(this.base64Uri, this.cid, this.fileInfo);
@override
List<Object?> get props => [imageAsBase64, cid, fileInfo];
List<Object?> get props => [base64Uri, cid, fileInfo];
}
class DownloadImageAsBase64Failure extends FeatureFailure {
@@ -9,10 +9,23 @@ class DownloadImageAsBase64Interactor {
DownloadImageAsBase64Interactor(this._composerRepository);
Stream<Either<Failure, Success>> execute(String url, String cid, FileInfo fileInfo) async* {
Stream<Either<Failure, Success>> execute(
String url,
String cid,
FileInfo fileInfo,
{
double? maxWidth,
bool? compress
}
) async* {
try {
yield Right<Failure, Success>(DownloadingImageAsBase64());
final result = await _composerRepository.downloadImageAsBase64(url);
final result = await _composerRepository.downloadImageAsBase64(
url,
cid,
fileInfo,
maxWidth: maxWidth,
compress: compress);
if (result?.isNotEmpty == true) {
yield Right<Failure, Success>(DownloadImageAsBase64Success(result!, cid, fileInfo));
} else {