0
0
Fork 0

Fix WebUI allowing to upload more items than the limit (#12300)

Until this patch, drag'n'drop and copy-paste allowed to start uploading as
long as the number of *finished* uploads was below the limit.
This commit is contained in:
ThibG 2019-11-07 08:07:03 +01:00 committed by Eugen Rochko
parent 7cdb8c10e9
commit 66684c489c
3 changed files with 10 additions and 6 deletions

View file

@ -61,6 +61,7 @@ const initialState = ImmutableMap({
is_uploading: false,
progress: 0,
media_attachments: ImmutableList(),
pending_media_attachments: 0,
poll: null,
suggestion_token: null,
suggestions: ImmutableList(),
@ -114,6 +115,7 @@ function appendMedia(state, media, file) {
map.set('is_uploading', false);
map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
map.set('idempotencyKey', uuid());
map.update('pending_media_attachments', n => n - 1);
if (prevSize === 0 && (state.get('default_sensitive') || state.get('spoiler'))) {
map.set('sensitive', true);
@ -322,11 +324,11 @@ export default function compose(state = initialState, action) {
case COMPOSE_UPLOAD_CHANGE_FAIL:
return state.set('is_changing_upload', false);
case COMPOSE_UPLOAD_REQUEST:
return state.set('is_uploading', true);
return state.set('is_uploading', true).update('pending_media_attachments', n => n + 1);
case COMPOSE_UPLOAD_SUCCESS:
return appendMedia(state, fromJS(action.media), action.file);
case COMPOSE_UPLOAD_FAIL:
return state.set('is_uploading', false);
return state.set('is_uploading', false).update('pending_media_attachments', n => action.decrement ? n - 1 : n);
case COMPOSE_UPLOAD_UNDO:
return removeMedia(state, action.media_id);
case COMPOSE_UPLOAD_PROGRESS: