TF-761 Update repository/datasource/interactor of downloadImageAsBase64
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
import 'package:model/upload/file_info.dart';
|
||||||
|
|
||||||
abstract class ComposerDataSource {
|
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:core/core.dart';
|
||||||
|
import 'package:model/upload/file_info.dart';
|
||||||
import 'package:tmail_ui_user/features/composer/data/datasource/composer_datasource.dart';
|
import 'package:tmail_ui_user/features/composer/data/datasource/composer_datasource.dart';
|
||||||
|
|
||||||
class ComposerDataSourceImpl extends ComposerDataSource {
|
class ComposerDataSourceImpl extends ComposerDataSource {
|
||||||
@@ -9,7 +10,14 @@ class ComposerDataSourceImpl extends ComposerDataSource {
|
|||||||
ComposerDataSourceImpl(this.downloadClient);
|
ComposerDataSourceImpl(this.downloadClient);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String?> downloadImageAsBase64(String url) {
|
Future<String?> downloadImageAsBase64(String url, String cid, FileInfo fileInfo, {double? maxWidth, bool? compress}) {
|
||||||
return downloadClient.downloadImageAsBase64(url);
|
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
|
@override
|
||||||
Future<String?> downloadImageAsBase64(String url) {
|
Future<String?> downloadImageAsBase64(String url, String cid, FileInfo fileInfo, {double? maxWidth, bool? compress}) {
|
||||||
return _composerDataSource.downloadImageAsBase64(url);
|
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 {
|
abstract class ComposerRepository {
|
||||||
UploadAttachment uploadAttachment(FileInfo fileInfo, Uri uploadUri, {CancelToken? cancelToken});
|
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 {
|
class DownloadImageAsBase64Success extends UIState {
|
||||||
|
|
||||||
final String imageAsBase64;
|
final String base64Uri;
|
||||||
final String cid;
|
final String cid;
|
||||||
final FileInfo fileInfo;
|
final FileInfo fileInfo;
|
||||||
|
|
||||||
DownloadImageAsBase64Success(this.imageAsBase64, this.cid, this.fileInfo);
|
DownloadImageAsBase64Success(this.base64Uri, this.cid, this.fileInfo);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [imageAsBase64, cid, fileInfo];
|
List<Object?> get props => [base64Uri, cid, fileInfo];
|
||||||
}
|
}
|
||||||
|
|
||||||
class DownloadImageAsBase64Failure extends FeatureFailure {
|
class DownloadImageAsBase64Failure extends FeatureFailure {
|
||||||
|
|||||||
@@ -9,10 +9,23 @@ class DownloadImageAsBase64Interactor {
|
|||||||
|
|
||||||
DownloadImageAsBase64Interactor(this._composerRepository);
|
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 {
|
try {
|
||||||
yield Right<Failure, Success>(DownloadingImageAsBase64());
|
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) {
|
if (result?.isNotEmpty == true) {
|
||||||
yield Right<Failure, Success>(DownloadImageAsBase64Success(result!, cid, fileInfo));
|
yield Right<Failure, Success>(DownloadImageAsBase64Success(result!, cid, fileInfo));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user