summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/react/components/file_attachment.jsx15
-rw-r--r--web/react/components/view_image.jsx17
-rw-r--r--web/react/utils/client.jsx14
-rw-r--r--web/react/utils/utils.jsx17
4 files changed, 35 insertions, 28 deletions
diff --git a/web/react/components/file_attachment.jsx b/web/react/components/file_attachment.jsx
index c36c908d2..ab550d500 100644
--- a/web/react/components/file_attachment.jsx
+++ b/web/react/components/file_attachment.jsx
@@ -2,6 +2,7 @@
// See License.txt for license information.
var utils = require('../utils/utils.jsx');
+var Client = require('../utils/client.jsx');
var Constants = require('../utils/constants.jsx');
module.exports = React.createClass({
@@ -103,12 +104,16 @@ module.exports = React.createClass({
if (this.state.fileSize < 0) {
var self = this;
- // asynchronously request the size of the file so that we can display it next to the thumbnail
- utils.getFileSize(utils.getFileUrl(filename), function(fileSize) {
- if (self.canSetState) {
- self.setState({fileSize: fileSize});
+ Client.getFileInfo(
+ filename,
+ function(data) {
+ if (self.canSetState) {
+ self.setState({fileSize: parseInt(data["size"], 10)});
+ }
+ },
+ function(err) {
}
- });
+ );
} else {
fileSizeString = utils.fileSizeToString(this.state.fileSize);
}
diff --git a/web/react/components/view_image.jsx b/web/react/components/view_image.jsx
index 6077c4ebc..fefd8d57d 100644
--- a/web/react/components/view_image.jsx
+++ b/web/react/components/view_image.jsx
@@ -229,13 +229,18 @@ module.exports = React.createClass({
if (!(filename in this.state.fileSizes)) {
var self = this;
- utils.getFileSize(utils.getFileUrl(filename), function fileSizeOp(fileSize) {
- if (self.canSetState) {
- var fileSizes = self.state.fileSizes;
- fileSizes[filename] = fileSize;
- self.setState(fileSizes);
+ Client.getFileInfo(
+ filename,
+ function(data) {
+ if (self.canSetState) {
+ var fileSizes = self.state.fileSizes;
+ fileSizes[filename] = parseInt(data["size"], 10);
+ self.setState(fileSizes);
+ }
+ },
+ function(err) {
}
- });
+ );
}
}
} else {
diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx
index 754843697..13d6c3f54 100644
--- a/web/react/utils/client.jsx
+++ b/web/react/utils/client.jsx
@@ -831,6 +831,20 @@ module.exports.uploadFile = function(formData, success, error) {
return request;
};
+module.exports.getFileInfo = function(filename, success, error) {
+ $.ajax({
+ url: '/api/v1/files/get_info' + filename,
+ dataType: 'json',
+ contentType: 'application/json',
+ type: 'GET',
+ success: success,
+ error: function onError(xhr, status, err) {
+ var e = handleError('getFileInfo', xhr, status, err);
+ error(e);
+ }
+ });
+};
+
module.exports.getPublicLink = function(data, success, error) {
$.ajax({
url: '/api/v1/files/get_public_link',
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index 4571312bb..1a4db5954 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -604,23 +604,6 @@ module.exports.splitFileLocation = function(fileLocation) {
return {ext: ext, name: filename, path: filePath};
};
-// Asynchronously gets the size of a file by requesting its headers. If successful, it calls the
-// provided callback with the file size in bytes as the argument.
-module.exports.getFileSize = function(url, callback) {
- var request = new XMLHttpRequest();
-
- request.open('HEAD', url, true);
- request.onreadystatechange = function onReadyStateChange() {
- if (request.readyState === 4 && request.status === 200) {
- if (callback) {
- callback(parseInt(request.getResponseHeader('content-length'), 10));
- }
- }
- };
-
- request.send();
-};
-
module.exports.toTitleCase = function(str) {
function doTitleCase(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();