Added utility function to get a file attachment's url
Этот коммит содержится в:
@@ -71,16 +71,8 @@ module.exports = React.createClass({
|
||||
var filename = filenames[this.props.index];
|
||||
|
||||
var fileInfo = utils.splitFileLocation(filename);
|
||||
if (Object.keys(fileInfo).length === 0) return null;
|
||||
|
||||
var type = utils.getFileType(fileInfo.ext);
|
||||
|
||||
// This is a temporary patch to fix issue with old files using absolute paths
|
||||
if (fileInfo.path.indexOf("/api/v1/files/get") != -1) {
|
||||
fileInfo.path = fileInfo.path.split("/api/v1/files/get")[1];
|
||||
}
|
||||
fileInfo.path = utils.getWindowLocationOrigin() + "/api/v1/files/get" + fileInfo.path;
|
||||
|
||||
var thumbnail;
|
||||
if (type === "image") {
|
||||
thumbnail = <div ref={filename} className="post__load" style={{backgroundImage: 'url(/static/images/load.gif)'}}/>;
|
||||
@@ -92,7 +84,7 @@ module.exports = React.createClass({
|
||||
var self = this;
|
||||
|
||||
// asynchronously request the size of the file so that we can display it next to the thumbnail
|
||||
utils.getFileSize(fileInfo.path + "." + fileInfo.ext, function(fileSize) {
|
||||
utils.getFileSize(utils.getFileUrl(filename), function(fileSize) {
|
||||
self.setState({fileSize: fileSize});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -894,3 +894,16 @@ module.exports.fileSizeToString = function(bytes) {
|
||||
return bytes + "B";
|
||||
}
|
||||
};
|
||||
|
||||
// Converts a filename (like those attached to Post objects) to a url that can be used to retrieve attachments from the server.
|
||||
module.exports.getFileUrl = function(filename) {
|
||||
var url = filename;
|
||||
|
||||
// This is a temporary patch to fix issue with old files using absolute paths
|
||||
if (url.indexOf("/api/v1/files/get") != -1) {
|
||||
url = filename.split("/api/v1/files/get")[1];
|
||||
}
|
||||
url = module.exports.getWindowLocationOrigin() + "/api/v1/files/get" + url;
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
Ссылка в новой задаче
Block a user