diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 9c4027076..e44a05021 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -38,7 +38,7 @@ class SystemController extends AbstractController * @apiParam {String} type * - get: 获取(默认) * - all: 获取所有(需要管理员权限) - * - save: 保存设置(参数:['reg', 'reg_identity', 'reg_invite', 'login_code', 'password_policy', 'project_invite', 'chat_information', 'anon_message', 'auto_archived', 'archived_day', 'all_group_mute', 'all_group_autoin', 'start_home', 'home_footer']) + * - save: 保存设置(参数:['reg', 'reg_identity', 'reg_invite', 'login_code', 'password_policy', 'project_invite', 'chat_information', 'anon_message', 'auto_archived', 'archived_day', 'all_group_mute', 'all_group_autoin', 'image_compress', 'image_save_local', 'start_home', 'home_footer']) * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -67,6 +67,8 @@ class SystemController extends AbstractController 'archived_day', 'all_group_mute', 'all_group_autoin', + 'image_compress', + 'image_save_local', 'start_home', 'home_footer' ])) { @@ -104,6 +106,8 @@ class SystemController extends AbstractController $setting['archived_day'] = floatval($setting['archived_day']) ?: 7; $setting['all_group_mute'] = $setting['all_group_mute'] ?: 'open'; $setting['all_group_autoin'] = $setting['all_group_autoin'] ?: 'yes'; + $setting['image_compress'] = $setting['image_compress'] ?: 'open'; + $setting['image_save_local'] = $setting['image_save_local'] ?: 'open'; $setting['start_home'] = $setting['start_home'] ?: 'close'; // return Base::retSuccess('success', $setting ?: json_decode('{}')); diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index 7b1481c6b..2c390095a 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -641,8 +641,18 @@ class WebSocketDialogMsg extends AbstractModel } } // 其他网络图片 + $imageSaveLocal = Base::settingFind("system", "image_save_local"); preg_match_all("/]*?src=([\"'])(.*?\.(png|jpg|jpeg|gif))\\1[^>]*?>/is", $text, $matchs); foreach ($matchs[2] as $key => $str) { + if ($imageSaveLocal === 'close') { + $imageSize = getimagesize($str); + if ($imageSize === false) { + $imageSize = ["auto", "auto"]; + } + $imagePath = "base64-" . base64_encode($str); + $text = str_replace($matchs[0][$key], "[:IMAGE:browse:{$imageSize[0]}:{$imageSize[1]}:{$imagePath}::]", $text); + continue; + } if (str_starts_with($str, "{{RemoteURL}}")) { $imagePath = Base::leftDelete($str, "{{RemoteURL}}"); $imagePath = Base::rightDelete($imagePath, "_thumb.jpg"); @@ -742,10 +752,14 @@ class WebSocketDialogMsg extends AbstractModel // 过滤标签 $text = strip_tags($text, '
 
    • '); $text = preg_replace("/\<(blockquote|strong|pre|ol|ul|li|em|p|s|u).*?\>/is", "<$1>", $text); // 不用去除a标签,上面已经处理过了 - $text = preg_replace_callback("/\[:LINK:(.*?):(.*?):\]/i", function (array $match) { + $text = preg_replace_callback("/\[:LINK:(.*?):(.*?):\]/i", function (array $match) { return "" . base64_decode($match[2]) . ""; }, $text); - $text = preg_replace("/\[:IMAGE:(.*?):(.*?):(.*?):(.*?):(.*?):\]/i", "\"$5\"/", $text); + $text = preg_replace_callback("/\[:IMAGE:(.*?):(.*?):(.*?):(.*?):(.*?):\]/i", function (array $match) { + $wh = $match[2] === 'auto' ? "" : " width=\"{$match[2]}\" height=\"{$match[3]}\""; + $src = str_starts_with($match[4], "base64-") ? base64_decode(substr($match[4], 7)) : "{{RemoteURL}}{$match[4]}"; + return "\"{$match[5]}\"/"; + }, $text); $text = preg_replace("/\[:@:(.*?):(.*?):\]/i", "@$2", $text); $text = preg_replace("/\[:#:(.*?):(.*?):\]/i", "#$2", $text); $text = preg_replace("/\[:~:(.*?):(.*?):\]/i", "~$2", $text); diff --git a/app/Module/ImgCompress.php b/app/Module/ImgCompress.php index d1ef6e489..41a7c5db0 100644 --- a/app/Module/ImgCompress.php +++ b/app/Module/ImgCompress.php @@ -124,8 +124,11 @@ class ImgCompress * @param float $minSize 最小压缩大小,小于这个不压缩,单位KB * @return void */ - public static function compress(string $src, float $percent = 1, float $minSize = 100): void + public static function compress(string $src, float $percent = 1, float $minSize = 10): void { + if (Base::settingFind("system", "image_compress") === 'close') { + return; + } if (!file_exists($src)) { return; } diff --git a/resources/assets/js/pages/manage/setting/components/SystemSetting.vue b/resources/assets/js/pages/manage/setting/components/SystemSetting.vue index 239cc42ca..f3435d8ed 100644 --- a/resources/assets/js/pages/manage/setting/components/SystemSetting.vue +++ b/resources/assets/js/pages/manage/setting/components/SystemSetting.vue @@ -119,10 +119,24 @@ -

      +

      {{ $L('其他设置') }}

      - + + + {{$L('开启')}} + {{$L('关闭')}} + +
      {{$L('数码相机4M的图片,优化后仅有700KB左右,而且肉眼基本看不出区别。')}}
      +
      + + + {{$L('开启')}} + {{$L('关闭')}} + +
      {{$L('是否将消息中的网络图片保存到本地服务器。')}}
      +
      + {{$L('开启')}} {{$L('关闭')}}