Remove redundant upload limit variable and check number of attached files only once

This commit is contained in:
Rens Groothuijsen 2024-09-29 21:50:04 +02:00
parent 34e3869006
commit a9f9357ae4

View file

@ -298,7 +298,6 @@ export function submitComposeFail(error) {
export function uploadCompose(files) { export function uploadCompose(files) {
return function (dispatch, getState) { return function (dispatch, getState) {
const uploadLimit = getState().getIn(['server', 'server', 'configuration', 'statuses', 'max_media_attachments']);
const media = getState().getIn(['compose', 'media_attachments']); const media = getState().getIn(['compose', 'media_attachments']);
const pending = getState().getIn(['compose', 'pending_media_attachments']); const pending = getState().getIn(['compose', 'pending_media_attachments']);
const serverConfiguration = getState().getIn(['server', 'server', 'configuration']); const serverConfiguration = getState().getIn(['server', 'server', 'configuration']);
@ -308,10 +307,11 @@ export function uploadCompose(files) {
const filesArray = Array.from(files); const filesArray = Array.from(files);
const progress = new Array(files.length).fill(0); const progress = new Array(files.length).fill(0);
let total = filesArray.reduce((a, v) => a + v.size, 0); let total = filesArray.reduce((a, v) => a + v.size, 0);
if ( if (files.length + media.size + pending > maxMediaAttachments
filesArray.some(file => (file.type.match(/video\/.*/) && file.size > videoSizeLimit) || filesArray.some(file => (
|| (file.type.match(/image\/.*/) && file.size > imageSizeLimit) file.type.match(/video\/.*/) && file.size > videoSizeLimit)
|| (files.length + media.size + pending > maxMediaAttachments))) { || (file.type.match(/image\/.*/) && file.size > imageSizeLimit)))
{
dispatch(showAlert({ message: messages.uploadErrorLimit })); dispatch(showAlert({ message: messages.uploadErrorLimit }));
return; return;
} }
@ -324,7 +324,7 @@ export function uploadCompose(files) {
dispatch(uploadComposeRequest()); dispatch(uploadComposeRequest());
for (const [i, file] of Array.from(files).entries()) { for (const [i, file] of Array.from(files).entries()) {
if (media.size + i > (uploadLimit - 1)) break; if (media.size + i > (maxMediaAttachments - 1)) break;
const data = new FormData(); const data = new FormData();
data.append('file', file); data.append('file', file);