Commit 16d23702 authored by Haelwenn's avatar Haelwenn

Revert: Resize images before upload in web UI to reduce bandwidth

Closes: pleroma/mastofe#22

(Can also fix an issue with canvas and the Tor Browser)
parent 733538a9
......@@ -5,7 +5,6 @@ import { search as emojiSearch } from 'flavours/glitch/util/emoji/emoji_mart_sea
import { useEmoji } from './emojis';
import { tagHistory } from 'flavours/glitch/util/settings';
import { recoverHashtags } from 'flavours/glitch/util/hashtag';
import resizeImage from 'flavours/glitch/util/resize_image';
import { importFetchedAccounts } from './importer';
import { updateTimeline } from './timelines';
import { showAlertForError } from './alerts';
......@@ -236,21 +235,42 @@ export function uploadCompose(files) {
dispatch(uploadComposeRequest());
for (const [i, f] of Array.from(files).entries()) {
if (media.size + i > 3) break;
resizeImage(f).then(file => {
const data = new FormData();
data.append('file', file);
return api(getState).post('/api/v1/media', data, {
onUploadProgress: function({ loaded }){
progress[i] = loaded;
dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total));
},
}).then(({ data }) => dispatch(uploadComposeSuccess(data)));
}).catch(error => dispatch(uploadComposeFail(error)));
for (const [i, file] of Array.from(files).entries()) {
// Looks useless or should reuse uploadLimit
// if (media.size + i > 3) break;
const data = new FormData();
data.append('file', file);
api(getState).post('/api/v1/media', data, {
onUploadProgress: function({ loaded }){
progress[i] = loaded;
dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total));
},
}).then(function (response) {
dispatch(uploadComposeSuccess(response.data));
}).catch(function (error) {
dispatch(uploadComposeFail(error));
});
};
/*
* Previous pre-multiple upload code
*
* a372436a8... Revert: Resize images before upload in web UI to reduce bandwidth
*
* let data = new FormData();
* data.append('file', files[0]);
* 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));
* });
*/
};
};
......
......@@ -4,7 +4,6 @@ import { throttle } from 'lodash';
import { search as emojiSearch } from '../features/emoji/emoji_mart_search_light';
import { tagHistory } from '../settings';
import { useEmoji } from './emojis';
import resizeImage from '../utils/resize_image';
import { importFetchedAccounts } from './importer';
import { updateTimeline } from './timelines';
import { showAlertForError } from './alerts';
......@@ -218,20 +217,24 @@ export function uploadCompose(files) {
dispatch(uploadComposeRequest());
for (const [i, f] of Array.from(files).entries()) {
if (media.size + i > 3) break;
resizeImage(f).then(file => {
const data = new FormData();
data.append('file', file);
return api(getState).post('/api/v1/media', data, {
onUploadProgress: function({ loaded }){
progress[i] = loaded;
dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total));
},
}).then(({ data }) => dispatch(uploadComposeSuccess(data)));
}).catch(error => dispatch(uploadComposeFail(error)));
for (const [i, file] of Array.from(files).entries()) {
// Looks useless or should reuse uploadLimit
// if (media.size + i > 3) break;
let data = new FormData();
data.append('file', file);
api(getState).post('/api/v1/media', data, {
onUploadProgress: function(e) {
// progress[i] = loaded;
// dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total));
dispatch(uploadComposeProgress(e.loaded, e.total));
},
}).then(function (response) {
dispatch(uploadComposeSuccess(response.data));
}).catch(function (error) {
dispatch(uploadComposeFail(error));
});
};
};
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment