Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions abstract/uploadEntrySchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export const uploadEntrySchema = Object.freeze({
value: null,
nullable: true,
},
isFailedToGenerateThumb: {
type: Boolean,
value: false,
},
silent: {
type: Boolean,
value: false,
Expand Down
2 changes: 1 addition & 1 deletion blocks/Config/initialConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const initialConfig = {
sourceList: 'local, url, camera, dropbox, gdrive',
cloudImageEditorTabs: serializeCsv(ALL_TABS),
maxLocalFileSizeBytes: 0,
thumbSize: 76,
thumbSize: 64,
showEmptyList: false,
useLocalImageEditor: false,
useCloudImageEditor: true,
Expand Down
42 changes: 24 additions & 18 deletions blocks/FileItem/FileItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,39 +129,45 @@ export class FileItem extends UploaderBlock {
if (!this._entry) {
return;
}
let entry = this._entry;

if (entry.getValue('fileInfo') && entry.getValue('isImage')) {
let size = this.cfg.thumbSize;
let thumbUrl = this.proxyUrl(
const entry = this._entry;

if (
entry.getValue('fileInfo') &&
entry.getValue('isImage') &&
(entry.getValue('cdnUrlModifiers') || entry.getValue('isFailedToGenerateThumb'))
) {
const size = this.cfg.thumbSize;
const cdnThumbUrl = 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');
if (currentThumbUrl !== thumbUrl) {
entry.setValue('thumbUrl', thumbUrl);
const currentThumbUrl = entry.getValue('thumbUrl');
if (currentThumbUrl !== cdnThumbUrl) {
entry.setValue('thumbUrl', cdnThumbUrl);
currentThumbUrl?.startsWith('blob:') && URL.revokeObjectURL(currentThumbUrl);
}
return;
}

if (!entry.getValue('isImage')) {
const iconColor = window.getComputedStyle(this).getPropertyValue('--clr-generic-file-icon');
entry.setValue('thumbUrl', fileCssBg(iconColor));
return;
}

if (entry.getValue('thumbUrl')) {
return;
}

if (entry.getValue('file')?.type.includes('image')) {
try {
let 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');
entry.setValue('thumbUrl', fileCssBg(color));
}
} else {
let color = window.getComputedStyle(this).getPropertyValue('--clr-generic-file-icon');
try {
const thumbUrl = await generateThumb(entry.getValue('file'), this.cfg.thumbSize);
entry.setValue('thumbUrl', thumbUrl);
} catch (err) {
const color = window.getComputedStyle(this).getPropertyValue('--clr-generic-file-icon');
entry.setValue('thumbUrl', fileCssBg(color));
entry.setValue('isFailedToGenerateThumb', true);
}
}

Expand Down