refactor(attachment): 头像与背景图上限并入前端图片上传限制
- 移除独立的「用户头像与资料卡图片」分组与 avatar_max_size 字段,
与参考主题保持一致:头像/资料卡背景图与投稿评论图片共用
upload_img_size 同一套用户类型 × 大小配置
- 5 处消费方(REST 头像/背景上传、后台头像字段、用户中心头像与
封面配置)全部改读 UploadLimits::limit_bytes('image'),提示语
改用 size_format 与实际上限对齐
- 附件配置仅剩上传大小/上传格式/上传行为三组;管理端 SPA 已重建,
421 项契约测试通过
This commit is contained in:
@@ -84,12 +84,13 @@ trait UserControllerProfileMediaOperations {
|
||||
return $this->error(__('头像文件上传失败,请重新选择', 'aksrt'), 400);
|
||||
}
|
||||
|
||||
$settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_all() : [];
|
||||
$max_size_mb = max(1, min(10, (int) ($settings['avatar_max_size'] ?? 2)));
|
||||
$max_size = $max_size_mb * MB_IN_BYTES;
|
||||
// 头像与资料卡背景图并入「前端图片上传限制」统一治理(参考主题同源)。
|
||||
$max_size = class_exists('\AKSRT\Attachment\UploadLimits')
|
||||
? \AKSRT\Attachment\UploadLimits::limit_bytes('image', $user_id)
|
||||
: (int) wp_max_upload_size();
|
||||
$actual_size = !empty($file['tmp_name']) && is_readable($file['tmp_name']) ? (int) filesize($file['tmp_name']) : 0;
|
||||
if ($actual_size <= 0 || $actual_size > $max_size) {
|
||||
return $this->error(sprintf(__('图片大小必须在 1 字节至 %dMB 之间', 'aksrt'), $max_size_mb), 413);
|
||||
return $this->error(sprintf(__('图片大小不能超过 %s。', 'aksrt'), size_format($max_size)), 413);
|
||||
}
|
||||
|
||||
$checked = wp_check_filetype_and_ext($file['tmp_name'], $file['name'], [
|
||||
|
||||
Reference in New Issue
Block a user