Skip to content

Commit

Permalink
fix(upload-details): render preview image with format/auto and `pre…
Browse files Browse the repository at this point in the history
…view` operations
  • Loading branch information
nd0ut committed May 30, 2022
1 parent 3d6c677 commit 7c30d29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
1 change: 1 addition & 0 deletions blocks/FileItem/FileItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export class FileItem extends Block {
isImage: fileInfo.isImage,
mimeType: fileInfo.mimeType,
uuid: fileInfo.uuid,
cdnUrl: fileInfo.cdnUrl,
});
} catch (error) {
this.entry.setValue('isUploading', false);
Expand Down
28 changes: 10 additions & 18 deletions blocks/UploadDetails/UploadDetails.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Block } from '../../abstract/Block.js';
import { createOriginalUrl } from '../../utils/cdn-utils.js';
import { createCdnUrl, createCdnUrlModifiers, createOriginalUrl } from '../../utils/cdn-utils.js';
import { fileCssBg } from '../svg-backgrounds/svg-backgrounds.js';

/**
Expand Down Expand Up @@ -121,18 +121,6 @@ export class UploadDetails extends Block {
tmpSub('fileSize', (size) => {
this.$.fileSize = Number.isFinite(size) ? this.fileSizeFmt(size) : this.l10n('file-size-unknown');
});
tmpSub('uuid', (uuid) => {
if (uuid) {
this.eCanvas.clear();
this.set$({
cdnUrl: createOriginalUrl(this.$['*--cfg-cdn-cname'], uuid),
cloudEditBtnHidden: !this.entry.getValue('isImage') || !this.$['*--cfg-use-cloud-image-editor'],
});
this.entry.getValue('isImage') && this.eCanvas.setImageUrl(this.$.cdnUrl);
} else {
this.$.cdnUrl = '';
}
});
tmpSub('uploadError', (error) => {
this.$.errorTxt = error?.message;
});
Expand All @@ -145,12 +133,16 @@ export class UploadDetails extends Block {
this.showNonImageThumb();
}
});
tmpSub('cdnUrl', (url) => {
if (!url) {
return;
}
tmpSub('cdnUrl', (cdnUrl) => {
this.set$({
cdnUrl,
cloudEditBtnHidden: !this.entry.getValue('isImage') || !this.$['*--cfg-use-cloud-image-editor'],
});

if (this.entry.getValue('isImage')) {
this.eCanvas.setImageUrl(url);
// TODO: need to resize image to fit the canvas size
let imageUrl = createCdnUrl(cdnUrl, createCdnUrlModifiers('format/auto', 'preview'));
this.eCanvas.setImageUrl(imageUrl);
}
});
});
Expand Down

0 comments on commit 7c30d29

Please sign in to comment.