diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 2aaa35294..3b8024e33 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -41,7 +41,7 @@ class SystemController extends AbstractController * @apiParam {String} type * - get: 获取(默认) * - all: 获取所有(需要管理员权限) - * - save: 保存设置(参数:['reg', 'reg_identity', 'reg_invite', 'temp_account_alias', 'login_code', 'password_policy', 'project_invite', 'chat_information', 'anon_message', 'voice2text', 'translation', 'e2e_message', 'auto_archived', 'archived_day', 'task_visible', 'task_default_time', 'all_group_mute', 'all_group_autoin', 'user_private_chat_mute', 'user_group_chat_mute', 'system_alias', 'system_welcome', 'image_compress', 'image_quality', 'image_save_local', 'start_home']) + * - save: 保存设置(参数:['reg', 'reg_identity', 'reg_invite', 'temp_account_alias', 'login_code', 'password_policy', 'project_invite', 'chat_information', 'anon_message', 'voice2text', 'translation', 'convert_video', 'compress_video', 'e2e_message', 'auto_archived', 'archived_day', 'task_visible', 'task_default_time', 'all_group_mute', 'all_group_autoin', 'user_private_chat_mute', 'user_group_chat_mute', 'system_alias', 'system_welcome', 'image_compress', 'image_quality', 'image_save_local', 'start_home']) * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -70,6 +70,8 @@ class SystemController extends AbstractController 'anon_message', 'voice2text', 'translation', + 'convert_video', + 'compress_video', 'e2e_message', 'msg_rev_limit', 'msg_edit_limit', @@ -136,6 +138,8 @@ class SystemController extends AbstractController $setting['anon_message'] = $setting['anon_message'] ?: 'open'; $setting['voice2text'] = $setting['voice2text'] ?: 'close'; $setting['translation'] = $setting['translation'] ?: 'close'; + $setting['convert_video'] = $setting['convert_video'] ?: 'close'; + $setting['compress_video'] = $setting['compress_video'] ?: 'close'; $setting['e2e_message'] = $setting['e2e_message'] ?: 'close'; $setting['msg_rev_limit'] = $setting['msg_rev_limit'] ?: ''; $setting['msg_edit_limit'] = $setting['msg_edit_limit'] ?: ''; diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index 839cffa17..4348f9b9b 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -879,13 +879,15 @@ class WebSocketDialog extends AbstractModel Base::makeDir(public_path($path)); copy($filePath, public_path($path) . basename($filePath)); } else { + $setting = Base::setting("system"); $data = Base::upload([ "file" => $files, "type" => 'more', "path" => $path, "fileName" => $fileName, "quality" => true, - "convertVideo" => true + "convertVideo" => $setting['convert_video'] === 'open', + "compressVideo" => $setting['compress_video'] === 'open', ]); } // diff --git a/app/Module/Base.php b/app/Module/Base.php index d18526f10..b1f637ebe 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -2022,6 +2022,7 @@ class Base chmod=>权限(默认0644), quality=>压缩图片质量(默认:0不压缩), convertVideo=>转换视频格式(默认false) , + compressVideo=>压缩视频(默认false,如果转换就不压缩) , ] * @return array [ name=>原文件名, @@ -2179,6 +2180,7 @@ class Base } @shell_exec($command); if (file_exists($output) && filesize($output) > 0) { + // 压缩后的文件正常 @unlink($array['file']); $array = array_merge($array, [ "name" => Base::rightReplace($array['name'], ".{$array['ext']}", '.mp4'), @@ -2189,6 +2191,27 @@ class Base "ext" => 'mp4', ]); } + $param['compressVideo'] = false; // 如果转换就不压缩 + } + if ($param['compressVideo'] && $array['ext'] == 'mp4') { + // 压缩视频 + $output = $array['file'] . '_compress'; + $command = sprintf("ffmpeg -y -i %s -c:v libx264 -crf 28 -preset medium -c:a aac -b:a 96k %s 2>&1", escapeshellarg($array['file']), escapeshellarg($output)); + @shell_exec($command); + if (file_exists($output) && filesize($output) > 0) { + // 压缩后的文件正常 + if (filesize($output) < filesize($array['file'])) { + // 小于原文件 + @unlink($array['file']); + $array = array_merge($array, [ + "size" => Base::twoFloat(filesize($output) / 1024, true), + "file" => $output, + ]); + } else { + // 大于原文件 + @unlink($output); + } + } } if (in_array($array['ext'], ['mov', 'webm', 'mp4'])) { // 视频尺寸 diff --git a/resources/assets/js/pages/manage/setting/components/SystemSetting.vue b/resources/assets/js/pages/manage/setting/components/SystemSetting.vue index c5f7f49cb..ccabe4bd5 100644 --- a/resources/assets/js/pages/manage/setting/components/SystemSetting.vue +++ b/resources/assets/js/pages/manage/setting/components/SystemSetting.vue @@ -198,6 +198,22 @@
{{$L('长按文本消息可翻译成当前设置的语言。')}} ({{$L('需要在应用中开启 ChatGPT AI 机器人')}})
{{$L('关闭文本消息翻译功能。')}}
+ + + {{$L('开启')}} + {{$L('关闭')}} + +
{{$L('将MOV、WEBM格式的视频转换为MP4格式。')}}
+
{{$L('关闭视频格式转换功能。')}}
+
+ + + {{$L('开启')}} + {{$L('关闭')}} + +
{{$L('对MP4格式的视频进行压缩处理。')}}
+
{{$L('关闭视频压缩功能。')}}
+
{{$L('开启')}}