about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/actions/compose.js
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-05-25 11:26:37 +0200
committerThibG <thib@sitedethib.com>2018-05-27 11:02:54 +0200
commitc2e528916cae422baee3d72a3b4409a23c476b3f (patch)
tree8b7e10d97abd6c058444654cb8e56ce7e08af8c6 /app/javascript/flavours/glitch/actions/compose.js
parentd253449ff0e691963bcf14590831aa071b778734 (diff)
Implement client-size image resizing from upstream
Diffstat (limited to 'app/javascript/flavours/glitch/actions/compose.js')
-rw-r--r--app/javascript/flavours/glitch/actions/compose.js19
1 files changed, 8 insertions, 11 deletions
diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js
index 39381faa8..199a79e7f 100644
--- a/app/javascript/flavours/glitch/actions/compose.js
+++ b/app/javascript/flavours/glitch/actions/compose.js
@@ -3,6 +3,7 @@ import { CancelToken } from 'axios';
 import { throttle } from 'lodash';
 import { search as emojiSearch } from 'flavours/glitch/util/emoji/emoji_mart_search_light';
 import { useEmoji } from './emojis';
+import resizeImage from 'flavours/glitch/util/resize_image';
 
 import {
   updateTimeline,
@@ -207,18 +208,14 @@ export function uploadCompose(files) {
 
     dispatch(uploadComposeRequest());
 
-    let data = new FormData();
-    data.append('file', files[0]);
+    resizeImage(files[0]).then(file => {
+      const data = new FormData();
+      data.append('file', file);
 
-    api(getState).post('/api/v1/media', data, {
-      onUploadProgress: function (e) {
-        dispatch(uploadComposeProgress(e.loaded, e.total));
-      },
-    }).then(function (response) {
-      dispatch(uploadComposeSuccess(response.data));
-    }).catch(function (error) {
-      dispatch(uploadComposeFail(error));
-    });
+      return api(getState).post('/api/v1/media', data, {
+        onUploadProgress: ({ loaded, total }) => dispatch(uploadComposeProgress(loaded, total)),
+      }).then(({ data }) => dispatch(uploadComposeSuccess(data)));
+    }).catch(error => dispatch(uploadComposeFail(error)));
   };
 };