From 24acc89709889dee183d844a63acaea9a5b7ef9b Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 14 Oct 2022 14:59:26 +0800 Subject: [PATCH] feat(web/super_manage/image_hosting): change user images total size limit --- web/app/controllers/super_manage.php | 40 ++++++++++++++++++++++++++++ web/app/libs/uoj-validate-lib.php | 4 +-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/web/app/controllers/super_manage.php b/web/app/controllers/super_manage.php index 19fdb92..d1e9956 100644 --- a/web/app/controllers/super_manage.php +++ b/web/app/controllers/super_manage.php @@ -634,6 +634,9 @@ EOD; }; $image_deleter = new UOJForm('image_deleter'); + $image_deleter->submit_button_config['align'] = 'compressed'; + $image_deleter->submit_button_config['text'] = '删除'; + $image_deleter->submit_button_config['class_str'] = 'btn btn-danger'; $image_deleter->addInput('image_deleter_id', 'text', '图片 ID', '', function ($x, &$vdata) { if (!validateUInt($x)) { @@ -655,6 +658,39 @@ EOD; }; $image_deleter->runAtServer(); + $change_user_image_total_size_limit_form = new UOJForm('change_user_image_total_size_limit'); + $change_user_image_total_size_limit_form->submit_button_config['align'] = 'compressed'; + $change_user_image_total_size_limit_form->addInput('change_user_image_total_size_limit_username', 'text', '用户名', '', + function ($x, &$vdata) { + if (!validateUsername($x)) { + return '用户名不合法'; + } + if (!queryUser($x)) { + return '用户不存在'; + } + $vdata['username'] = $x; + return ''; + }, + null + ); + $change_user_image_total_size_limit_form->addInput('change_user_image_total_size_limit_limit', 'text', '存储限制(单位:Byte)', '104857600', + function ($x, &$vdata) { + if (!validateUInt($x, 10)) { + return '限制不合法'; + } + if (intval($x) > 2147483648) { + return '限制不能大于 2 GB'; + } + $vdata['limit'] = $x; + return ''; + }, + null + ); + $change_user_image_total_size_limit_form->handle = function(&$vdata) { + DB::update("UPDATE user_info SET images_size_limit = {$vdata['limit']} WHERE username = '{$vdata['username']}'"); + }; + $change_user_image_total_size_limit_form->runAtServer(); + $tabs_info = array( 'users' => array( 'name' => '用户管理', @@ -821,6 +857,10 @@ EOD;

删除图片

printHTML() ?> +
+

修改用户存储上限

+ printHTML() ?> +
diff --git a/web/app/libs/uoj-validate-lib.php b/web/app/libs/uoj-validate-lib.php index a685868..2ba27fb 100644 --- a/web/app/libs/uoj-validate-lib.php +++ b/web/app/libs/uoj-validate-lib.php @@ -20,14 +20,14 @@ function validateMotto($motto) { return is_string($motto) && ($len = mb_strlen($motto, 'UTF-8')) !== false && $len <= 1024; } -function validateUInt($x) { // [0, 1000000000) +function validateUInt($x, $len = 8) { // [0, 1000000000) if (!is_string($x)) { return false; } if ($x === '0') { return true; } - return preg_match('/^[1-9][0-9]{0,8}$/', $x); + return preg_match('/^[1-9][0-9]{0,'.$len.'}$/', $x); } function validateInt($x) {