Merge pull request #1325 from MarekBenjamin/fix_jsupload

Adjusted code use of shorthandnotation for image size upload limits
This commit is contained in:
Hypolite Petovan 2022-11-30 16:12:35 -05:00 committed by GitHub
commit d45004f44d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,7 +39,7 @@ function js_upload_form(App $a, array &$b)
'$cancel' => DI::l10n()->t('Cancel'), '$cancel' => DI::l10n()->t('Cancel'),
'$failed' => DI::l10n()->t('Failed'), '$failed' => DI::l10n()->t('Failed'),
'$post_url' => $b['post_url'], '$post_url' => $b['post_url'],
'$maximagesize' => intval(DI::config()->get('system', 'maximagesize')), '$maximagesize' => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')),
]); ]);
} }
@ -51,7 +51,7 @@ function js_upload_post_init(App $a, array &$b)
$allowedExtensions = ['jpeg', 'gif', 'png', 'jpg']; $allowedExtensions = ['jpeg', 'gif', 'png', 'jpg'];
// max file size in bytes // max file size in bytes
$sizeLimit = DI::config()->get('system', 'maximagesize'); $sizeLimit = Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit); $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
@ -200,21 +200,6 @@ class qqFileUploader
} }
private function toBytes($str)
{
$val = trim($str);
$last = strtolower($str[strlen($str) - 1]);
switch ($last) {
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
/** /**
* Returns array('success'=>true) or array('error'=>'error message') * Returns array('success'=>true) or array('error'=>'error message')
*/ */
@ -236,7 +221,7 @@ class qqFileUploader
// } // }
$maximagesize = DI::config()->get('system', 'maximagesize'); $maximagesize = Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
if (($maximagesize) && ($size > $maximagesize)) { if (($maximagesize) && ($size > $maximagesize)) {
return ['error' => DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize))]; return ['error' => DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize))];