Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
74 changes: 46 additions & 28 deletions src/js/fileselector.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,37 +358,43 @@ export default class FileSelector {
if(me.isDownloading)
return false;
me.isDownloading = true;
me.api.get('file/' + me.file.id + '/downloads/0', function(o) {
me.api.get('file/' + me.file.id + '/downloads/0', function(o) {
me.isDownloading = false;
var downloadURL = o[0].downloadURL;
if (me.config.permanentURL && (me.isValidFileType(me.file))){
downloadURL += '&permalink=true';
var xhr = new XMLHttpRequest();
xhr.open('GET', downloadURL);
xhr.onload = function() {
if (xhr.readyState === 4) {
if(xhr.status === 200 || xhr.status === 201) {
try {
var o = JSON.parse(xhr.responseText);
me.config.success({
url: o.url,
name:me.file.name,
filename:me.file.filename,
mediaId: me.file.mediaId,
id: me.file.id,
folderId: me.selectedFolderId,
basetype: me.file.type.type,
filetype: me.file.type.extension,
width: me.file.width,
height: me.file.width,
photographer: me.file.photographer,
altText: me.config.autosetAltText !== false ? me.file.alttext : ""
});
} catch(e) {
alert('Ett fel inträffade vid nerladdning av fil');
}
if (xhr.readyState === 4) {
if(xhr.status === 200 || xhr.status === 201) {
try {
var o = JSON.parse(xhr.responseText);
me.config.success({
url: o.url,
name:me.file.name,
filename:me.file.filename,
mediaId: me.file.mediaId,
id: me.file.id,
folderId: me.selectedFolderId,
basetype: me.file.type.type,
filetype: me.file.type.extension,
width: me.file.width,
height: me.file.width,
photographer: me.file.photographer,
altText: me.config.autosetAltText !== false ? me.file.alttext : "",
// Extra metadata:
additionalInfo: me.file.additionalInfo,
customFields: me.file.customFields,
description: me.file.description,
instructions: me.file.instructions,
keywords: me.file.keywords
});
} catch(e) {
alert(me.lang.translate('CROPPER_DOWNLOAD_FAILED'));
}
}
}
}
}
xhr.send();
} else {
Expand All @@ -405,13 +411,19 @@ export default class FileSelector {
width:me.file.width,
height:me.file.width,
photographer:me.file.photographer,
altText: me.config.autosetAltText !== false ? me.file.alttext : ""
});
altText: me.config.autosetAltText !== false ? me.file.alttext : "",
// Extra metadata:
additionalInfo: me.file.additionalInfo,
customFields: me.file.customFields,
description: me.file.description,
instructions: me.file.instructions,
keywords: me.file.keywords
});
}, 5);
}
}, function(o) {
alert('Ett fel inträffade vid nerladdning av fil');
me.isDownloading = false;
}, function(o) {
alert(me.lang.translate('CROPPER_DOWNLOAD_FAILED'));
me.isDownloading = false;
});
} else {
if(me.cropperviewVisible) {
Expand All @@ -431,6 +443,12 @@ export default class FileSelector {
basetype:me.file.type.type,
filetype:me.file.type.extension,
folderId: me.selectedFolderId,
// Extra metadata:
additionalInfo: me.file.additionalInfo,
customFields: me.file.customFields,
description: me.file.description,
instructions: me.file.instructions,
keywords: me.file.keywords
});}, 5);
return true;
}
Expand Down
7 changes: 5 additions & 2 deletions src/js/modules/cropperview.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,6 @@ export default {
let ww, hh;

const altText = me.altInput.value;
const description = me.fileDescription.value;
const fileName = me.filenameInput.value;

const selectedFormatValue = parseInt(me.formatSelector[me.formatSelector.selectedIndex].value, 10);
Expand Down Expand Up @@ -855,8 +854,12 @@ export default {
filetype: fileType,
width: ww,
height: hh,
description: description,
additionalInfo: me.file.additionalInfo,
customFields: me.file.customFields,
description: me.fileDescription.value,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description value read lazily unlike other input fields

Low Severity

The removal of const description = me.fileDescription.value at the top of doDownload means description is now read from the DOM inside the async XHR callback + setTimeout, while altText and fileName are still captured eagerly at function entry. If the textarea value changes during the XHR round-trip (e.g., view teardown or user interaction), description could be stale or incorrect, unlike the other user-editable fields that are safely snapshotted upfront.

Additional Locations (1)
Fix in Cursor Fix in Web

photographer: me.file.photographer,
instructions: me.file.instructions,
keywords: me.file.keywords,
altText: altText,
canvasWidth: safeCanvasWidth,
canvasHeight: safeCanvasHeight,
Expand Down
4 changes: 4 additions & 0 deletions src/js/modules/fileinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export default {

me.api.get('file/' + me.files[idx].id + '?fields=any&locale=' + me.lang.locale(), function (o) {
me.file = o[0];

if (me.file.customFields) {
me.file.customFields = me.file.customFields.filter((cf) => cf.value !== "" && cf.value != null);
}

me.api.get('file/' + me.files[idx].id + '/checkpermissions', function (permissions) {
me.file.permissions = permissions[0];
Expand Down