TF-764 Fix inline images are not saved and shown successfully in Draft

This commit is contained in:
dab246
2022-08-02 14:30:39 +07:00
committed by Dat H. Pham
parent e08429d42c
commit fc83cae62b
6 changed files with 49 additions and 82 deletions
@@ -112,7 +112,7 @@ class DownloadClient {
if (fileName.contains('.')) {
fileName = fileName.split('.').first;
}
final base64Uri = '<img src="data:$mimeType;base64,$base64Data" alt="$fileName" id="$cid" style="max-width: 100%" />';
final base64Uri = '<img src="data:$mimeType;base64,$base64Data" alt="$fileName" id="cid:$cid" style="max-width: 100%" />';
return base64Uri;
}
}
@@ -21,26 +21,22 @@ class ImageTransformer extends DomTransformer {
}
) async {
final compressFileUtils = CompressFileUtils();
final imageElements = document.getElementsByTagName('img');
final imageElements = document.querySelectorAll('img[src^="cid:"]');
log('ImageTransformer::process(): imageElements: ${imageElements.length}');
await Future.wait(imageElements.map((imageElement) async {
imageElement.attributes['style'] = 'display: inline;max-width: 100%;height: auto;';
final src = imageElement.attributes['src'];
if (src != null
&& src.isNotEmpty
&& src.startsWith('cid:')
&& mapUrlDownloadCID != null
) {
final cid = src.replaceFirst('cid:', '').trim();
final cidUrlDownload = mapUrlDownloadCID[cid];
if (cidUrlDownload != null && cidUrlDownload.isNotEmpty && dioClient != null) {
final imgBase64Uri = await loadAsyncNetworkImageToBase64(
dioClient,
compressFileUtils,
cidUrlDownload);
if (imgBase64Uri.isNotEmpty) {
imageElement.attributes['src'] = imgBase64Uri;
}
log('ImageTransformer::process(): src: $src');
final cid = src?.replaceFirst('cid:', '').trim();
final urlDownloadCid = mapUrlDownloadCID?[cid];
log('ImageTransformer::process(): urlDownloadCid: $urlDownloadCid');
if (urlDownloadCid?.isNotEmpty == true && dioClient != null) {
final imgBase64Uri = await loadAsyncNetworkImageToBase64(
dioClient,
compressFileUtils,
urlDownloadCid!);
if (imgBase64Uri.isNotEmpty) {
imageElement.attributes['src'] = imgBase64Uri;
}
}
}));