mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:35:50 +00:00
perf: 系统设置新增图片优化、是否保存网络图片功能
This commit is contained in:
parent
4a198ccd8f
commit
1cef313689
@ -38,7 +38,7 @@ class SystemController extends AbstractController
|
|||||||
* @apiParam {String} type
|
* @apiParam {String} type
|
||||||
* - get: 获取(默认)
|
* - get: 获取(默认)
|
||||||
* - all: 获取所有(需要管理员权限)
|
* - 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 {Number} ret 返回状态码(1正确、0错误)
|
||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
@ -67,6 +67,8 @@ class SystemController extends AbstractController
|
|||||||
'archived_day',
|
'archived_day',
|
||||||
'all_group_mute',
|
'all_group_mute',
|
||||||
'all_group_autoin',
|
'all_group_autoin',
|
||||||
|
'image_compress',
|
||||||
|
'image_save_local',
|
||||||
'start_home',
|
'start_home',
|
||||||
'home_footer'
|
'home_footer'
|
||||||
])) {
|
])) {
|
||||||
@ -104,6 +106,8 @@ class SystemController extends AbstractController
|
|||||||
$setting['archived_day'] = floatval($setting['archived_day']) ?: 7;
|
$setting['archived_day'] = floatval($setting['archived_day']) ?: 7;
|
||||||
$setting['all_group_mute'] = $setting['all_group_mute'] ?: 'open';
|
$setting['all_group_mute'] = $setting['all_group_mute'] ?: 'open';
|
||||||
$setting['all_group_autoin'] = $setting['all_group_autoin'] ?: 'yes';
|
$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';
|
$setting['start_home'] = $setting['start_home'] ?: 'close';
|
||||||
//
|
//
|
||||||
return Base::retSuccess('success', $setting ?: json_decode('{}'));
|
return Base::retSuccess('success', $setting ?: json_decode('{}'));
|
||||||
|
|||||||
@ -641,8 +641,18 @@ class WebSocketDialogMsg extends AbstractModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 其他网络图片
|
// 其他网络图片
|
||||||
|
$imageSaveLocal = Base::settingFind("system", "image_save_local");
|
||||||
preg_match_all("/<img[^>]*?src=([\"'])(.*?\.(png|jpg|jpeg|gif))\\1[^>]*?>/is", $text, $matchs);
|
preg_match_all("/<img[^>]*?src=([\"'])(.*?\.(png|jpg|jpeg|gif))\\1[^>]*?>/is", $text, $matchs);
|
||||||
foreach ($matchs[2] as $key => $str) {
|
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}}")) {
|
if (str_starts_with($str, "{{RemoteURL}}")) {
|
||||||
$imagePath = Base::leftDelete($str, "{{RemoteURL}}");
|
$imagePath = Base::leftDelete($str, "{{RemoteURL}}");
|
||||||
$imagePath = Base::rightDelete($imagePath, "_thumb.jpg");
|
$imagePath = Base::rightDelete($imagePath, "_thumb.jpg");
|
||||||
@ -745,7 +755,11 @@ class WebSocketDialogMsg extends AbstractModel
|
|||||||
$text = preg_replace_callback("/\[:LINK:(.*?):(.*?):\]/i", function (array $match) {
|
$text = preg_replace_callback("/\[:LINK:(.*?):(.*?):\]/i", function (array $match) {
|
||||||
return "<a href=\"" . base64_decode($match[1]) . "\" target=\"_blank\">" . base64_decode($match[2]) . "</a>";
|
return "<a href=\"" . base64_decode($match[1]) . "\" target=\"_blank\">" . base64_decode($match[2]) . "</a>";
|
||||||
}, $text);
|
}, $text);
|
||||||
$text = preg_replace("/\[:IMAGE:(.*?):(.*?):(.*?):(.*?):(.*?):\]/i", "<img class=\"$1\" width=\"$2\" height=\"$3\" src=\"{{RemoteURL}}$4\" alt=\"$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 "<img class=\"{$match[1]}\"{$wh} src=\"{$src}\" alt=\"{$match[5]}\"/>";
|
||||||
|
}, $text);
|
||||||
$text = preg_replace("/\[:@:(.*?):(.*?):\]/i", "<span class=\"mention user\" data-id=\"$1\">@$2</span>", $text);
|
$text = preg_replace("/\[:@:(.*?):(.*?):\]/i", "<span class=\"mention user\" data-id=\"$1\">@$2</span>", $text);
|
||||||
$text = preg_replace("/\[:#:(.*?):(.*?):\]/i", "<span class=\"mention task\" data-id=\"$1\">#$2</span>", $text);
|
$text = preg_replace("/\[:#:(.*?):(.*?):\]/i", "<span class=\"mention task\" data-id=\"$1\">#$2</span>", $text);
|
||||||
$text = preg_replace("/\[:~:(.*?):(.*?):\]/i", "<a class=\"mention file\" href=\"{{RemoteURL}}single/file/$1\" target=\"_blank\">~$2</a>", $text);
|
$text = preg_replace("/\[:~:(.*?):(.*?):\]/i", "<a class=\"mention file\" href=\"{{RemoteURL}}single/file/$1\" target=\"_blank\">~$2</a>", $text);
|
||||||
|
|||||||
@ -124,8 +124,11 @@ class ImgCompress
|
|||||||
* @param float $minSize 最小压缩大小,小于这个不压缩,单位KB
|
* @param float $minSize 最小压缩大小,小于这个不压缩,单位KB
|
||||||
* @return void
|
* @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)) {
|
if (!file_exists($src)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -119,10 +119,24 @@
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="$A.isDooServer()" class="block-setting-box">
|
<div class="block-setting-box">
|
||||||
<h3>{{ $L('其他设置') }}</h3>
|
<h3>{{ $L('其他设置') }}</h3>
|
||||||
<div class="form-box">
|
<div class="form-box">
|
||||||
<FormItem :label="$L('是否启动首页')" prop="startHome">
|
<FormItem :label="$L('图片优化')" prop="image_compress">
|
||||||
|
<RadioGroup v-model="formDatum.image_compress">
|
||||||
|
<Radio label="open">{{$L('开启')}}</Radio>
|
||||||
|
<Radio label="close">{{$L('关闭')}}</Radio>
|
||||||
|
</RadioGroup>
|
||||||
|
<div class="form-tip">{{$L('数码相机4M的图片,优化后仅有700KB左右,而且肉眼基本看不出区别。')}}</div>
|
||||||
|
</FormItem>
|
||||||
|
<FormItem :label="$L('保存网络图片')" prop="image_save_local">
|
||||||
|
<RadioGroup v-model="formDatum.image_save_local">
|
||||||
|
<Radio label="open">{{$L('开启')}}</Radio>
|
||||||
|
<Radio label="close">{{$L('关闭')}}</Radio>
|
||||||
|
</RadioGroup>
|
||||||
|
<div class="form-tip">{{$L('是否将消息中的网络图片保存到本地服务器。')}}</div>
|
||||||
|
</FormItem>
|
||||||
|
<FormItem v-if="$A.isDooServer()" :label="$L('是否启动首页')" prop="startHome">
|
||||||
<RadioGroup v-model="formDatum.start_home">
|
<RadioGroup v-model="formDatum.start_home">
|
||||||
<Radio label="open">{{$L('开启')}}</Radio>
|
<Radio label="open">{{$L('开启')}}</Radio>
|
||||||
<Radio label="close">{{$L('关闭')}}</Radio>
|
<Radio label="close">{{$L('关闭')}}</Radio>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user