Skip to content

Commit

Permalink
fix: do not load preview image from cdn if no cdn modifiers applied
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Mar 5, 2024
1 parent 77a70eb commit 60b871c
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions blocks/FileItem/FileItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ export class FileItem extends UploaderBlock {
if (!this._entry) {
return;
}
let entry = this._entry;
const entry = this._entry;

if (entry.getValue('fileInfo') && entry.getValue('isImage')) {
let size = this.cfg.thumbSize;
let thumbUrl = this.proxyUrl(
if (entry.getValue('fileInfo') && entry.getValue('isImage') && entry.getValue('cdnUrlModifiers')) {
const size = this.cfg.thumbSize;
const thumbUrl = this.proxyUrl(
createCdnUrl(
createOriginalUrl(this.cfg.cdnCname, this._entry.getValue('uuid')),
createCdnUrlModifiers(entry.getValue('cdnUrlModifiers'), `scale_crop/${size}x${size}/center`),
),
);
let currentThumbUrl = entry.getValue('thumbUrl');
const currentThumbUrl = entry.getValue('thumbUrl');
if (currentThumbUrl !== thumbUrl) {
entry.setValue('thumbUrl', thumbUrl);
currentThumbUrl?.startsWith('blob:') && URL.revokeObjectURL(currentThumbUrl);
Expand All @@ -151,16 +151,16 @@ export class FileItem extends UploaderBlock {
return;
}

if (entry.getValue('file')?.type.includes('image')) {
if (entry.getValue('isImage')) {
try {
let thumbUrl = await generateThumb(entry.getValue('file'), this.cfg.thumbSize);
const thumbUrl = await generateThumb(entry.getValue('file'), this.cfg.thumbSize);
entry.setValue('thumbUrl', thumbUrl);
} catch (err) {
let color = window.getComputedStyle(this).getPropertyValue('--clr-generic-file-icon');
const color = window.getComputedStyle(this).getPropertyValue('--clr-generic-file-icon');
entry.setValue('thumbUrl', fileCssBg(color));
}
} else {
let color = window.getComputedStyle(this).getPropertyValue('--clr-generic-file-icon');
const color = window.getComputedStyle(this).getPropertyValue('--clr-generic-file-icon');
entry.setValue('thumbUrl', fileCssBg(color));
}
}
Expand Down Expand Up @@ -210,11 +210,8 @@ export class FileItem extends UploaderBlock {
this.$.itemName = entry.getValue('fileName') || externalUrl || this.l10n('file-no-name');
});

this._subEntry('fileInfo', (fileInfo) => {
this._subEntry('fileInfo', () => {
this._debouncedCalculateState();
if (fileInfo && this._isIntersecting) {
this._debouncedGenerateThumb();
}
});

this._subEntry('cdnUrlModifiers', () => {
Expand Down

0 comments on commit 60b871c

Please sign in to comment.