diff --git a/js/components/ascribe_detail/media_container.js b/js/components/ascribe_detail/media_container.js index cb86e558..00ca9164 100644 --- a/js/components/ascribe_detail/media_container.js +++ b/js/components/ascribe_detail/media_container.js @@ -65,7 +65,16 @@ let MediaContainer = React.createClass({ // We also force uniqueness of usernames, so this check is safe to dtermine if the // content was registered by the current user. const didUserRegisterContent = currentUser && (currentUser.username === content.user_registered); - const fileExtension = extractFileExtensionFromString(content.digital_work.url); + + // We want to show the file's extension as a label of the download button. + // We can however not only use `extractFileExtensionFromString` on the url for that + // as files might be saved on S3 without a file extension which leads + // `extractFileExtensionFromString` to extract everything starting from the top level + // domain: e.g. '.net/live/'. + // Therefore, we extract the file's name (last part of url, separated with a slash) + // and try to extract the file extension from there. + const fileName = content.digital_work.url.split('/').pop(); + const fileExtension = extractFileExtensionFromString(fileName); let thumbnail = content.thumbnail.thumbnail_sizes && content.thumbnail.thumbnail_sizes['600x600'] ? content.thumbnail.thumbnail_sizes['600x600'] : content.thumbnail.url_safe; @@ -123,7 +132,11 @@ let MediaContainer = React.createClass({ className="ascribe-margin-1px" href={content.digital_work.url} target="_blank"> - {getLangText('Download')} .{fileExtension} + {/* + If it turns out that `fileExtension` is an empty string, we're just + using the label 'file'. + */} + {getLangText('Download')} .{fileExtension || 'file'} {embed}