separate download url from preview url

This commit is contained in:
or-else
2018-06-06 16:41:16 +03:00
parent 9c507ba631
commit 499bf1ee14
3 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -1714,7 +1714,7 @@ ul.tabbar li.active > a:after {
margin: 0.35rem; margin: 0.35rem;
width: 6rem; width: 6rem;
border-radius: 0.1rem; border-radius: 0.1rem;
background-color: silver; background-color: #cfd8dc;
} }
/* Colored uploader progress bar of variable length */ /* Colored uploader progress bar of variable length */
.uploader > div > span { .uploader > div > span {
+15 -3
View File
@@ -129,7 +129,8 @@ Sample JSON representation of the text above:
}, },
IM: { IM: {
open: function(data) { open: function(data) {
var previewUrl = data.val ? base64toObjectUrl(data.val, data.mime) : data.ref; // Don't use data.ref for preview: it's a security risk.
var previewUrl = base64toObjectUrl(data.val, data.mime);
var downloadUrl = data.ref ? data.ref : previewUrl; var downloadUrl = data.ref ? data.ref : previewUrl;
var res = (data.name ? '<a href="' + downloadUrl + '" download="' + data.name + '">' : '') + var res = (data.name ? '<a href="' + downloadUrl + '" download="' + data.name + '">' : '') +
'<img src="' + previewUrl + '"' + '<img src="' + previewUrl + '"' +
@@ -737,11 +738,22 @@ Sample JSON representation of the text above:
}, },
/** /**
* Get blob URL for a given entity. * Given the entity, get URL which can be used for downloading
* entity data.
* *
* @param {Object} entity to get the URl from. * @param {Object} entity to get the URl from.
*/ */
getBlobUrl: function(entity) { getDownloadUrl: function(entity) {
return entity.ref ? entity.ref : base64toObjectUrl(entity.val, entity.mime);
},
/**
* Given the entity, get URL which can be used for previewing
* the entity.
*
* @param {Object} entity to get the URl from.
*/
getPreviewUrl: function(entity) {
return base64toObjectUrl(entity.val, entity.mime); return base64toObjectUrl(entity.val, entity.mime);
}, },
+2 -2
View File
@@ -3176,7 +3176,7 @@
if (this.props.mimeType === Drafty.getContentType()) { if (this.props.mimeType === Drafty.getContentType()) {
Drafty.attachments(content, function(att, i) { Drafty.attachments(content, function(att, i) {
attachments.push(<Message.Attachment attachments.push(<Message.Attachment
filename={att.name} blobUrl={Drafty.getBlobUrl(att)} filename={att.name} downloadUrl={Drafty.getDownloadUrl(att)}
size={Drafty.getEntitySize(att)} key={i} />); size={Drafty.getEntitySize(att)} key={i} />);
}, this); }, this);
content = React.createElement('span', null, Drafty.format(content, formatter, this)); content = React.createElement('span', null, Drafty.format(content, formatter, this));
@@ -3283,7 +3283,7 @@
{this.props.uploader ? {this.props.uploader ?
<FileUploadProgress progress={this.props.progress} /> <FileUploadProgress progress={this.props.progress} />
: :
<div><a href={this.props.blobUrl} download={this.props.filename}> <div><a href={this.props.downloadUrl} download={this.props.filename}>
<i className="material-icons">file_download</i> save <i className="material-icons">file_download</i> save
</a></div> </a></div>
} }