no message

This commit is contained in:
kuaifan 2023-04-03 12:57:32 +08:00
parent d0276e63c6
commit d2e04843a4
7 changed files with 39 additions and 13 deletions

View File

@ -15,7 +15,6 @@ use App\Models\WebSocketDialogMsgRead;
use App\Models\WebSocketDialogMsgTodo;
use App\Models\WebSocketDialogUser;
use App\Module\Base;
use App\Module\ImgCompress;
use App\Module\TimeRange;
use Carbon\Carbon;
use DB;
@ -854,7 +853,6 @@ class DialogController extends AbstractController
$fileData = $data['data'];
$fileData['thumb'] = Base::unFillUrl($fileData['thumb']);
$fileData['size'] *= 1024;
ImgCompress::compress($fileData['file']);
//
if ($dialog->type === 'group' && $dialog->group_type === 'task') { // 任务群组保存文件
if ($image_attachment || !in_array($fileData['ext'], File::imageExt)) { // 如果是图片不保存

View File

@ -612,7 +612,7 @@ class FileController extends AbstractController
$tmpPath = "uploads/file/document/" . date("Ym") . "/" . $id . "/attached/";
Base::makeDir(public_path($tmpPath));
$tmpPath .= md5($text) . "." . $matchs[1][$key];
if (file_put_contents(public_path($tmpPath), base64_decode($text))) {
if (Base::saveContentImage(public_path($tmpPath), base64_decode($text))) {
$paramet = getimagesize(public_path($tmpPath));
$data['content'] = str_replace($matchs[0][$key], '<img src="' . Base::fillUrl($tmpPath) . '" original-width="' . $paramet[0] . '" original-height="' . $paramet[1] . '"', $data['content']);
$isRep = true;

View File

@ -4,6 +4,7 @@ namespace App\Ldap;
use App\Models\User;
use App\Module\Base;
use App\Module\ImgCompress;
use LdapRecord\Configuration\ConfigurationException;
use LdapRecord\Container;
use LdapRecord\LdapRecordException;
@ -144,9 +145,11 @@ class LdapUser extends Model
$userimg = $row->getPhoto();
if ($userimg) {
$path = "uploads/user/ldap/";
$file = "{$path}{$user->userid}.jpeg";
Base::makeDir(public_path($path));
file_put_contents(public_path("{$path}{$user->userid}.jpeg"), $userimg);
$user->userimg = "{$path}{$user->userid}.jpeg";
if (Base::saveContentImage(public_path($file), $userimg)) {
$user->userimg = $file;
}
}
$user->nickname = $row->getDisplayName();
$user->save();

View File

@ -66,7 +66,7 @@ class ProjectTaskContent extends AbstractModel
$tmpPath = $path . 'attached/';
Base::makeDir(public_path($tmpPath));
$tmpPath .= md5($text) . "." . $matchs[1][$key];
if (file_put_contents(public_path($tmpPath), base64_decode($text))) {
if (Base::saveContentImage(public_path($tmpPath), base64_decode($text))) {
$paramet = getimagesize(public_path($tmpPath));
$content = str_replace($matchs[0][$key], '<img src="{{RemoteURL}}' . $tmpPath . '" original-width="' . $paramet[0] . '" original-height="' . $paramet[1] . '"', $content);
}

View File

@ -587,8 +587,7 @@ class WebSocketDialogMsg extends AbstractModel
$imagePath = "uploads/chat/" . date("Ym") . "/" . $dialog_id . "/";
Base::makeDir(public_path($imagePath));
$imagePath .= md5s($base64) . "." . $matchs[1][$key];
if (file_put_contents(public_path($imagePath), base64_decode($base64))) {
ImgCompress::compress(public_path($imagePath));
if (Base::saveContentImage(public_path($imagePath), base64_decode($base64))) {
$imageSize = getimagesize(public_path($imagePath));
if (Base::imgThumb(public_path($imagePath), public_path($imagePath) . "_thumb.jpg", 320, 0)) {
$imagePath .= "_thumb.jpg";
@ -662,8 +661,7 @@ class WebSocketDialogMsg extends AbstractModel
$image = file_get_contents($str);
if (empty($image)) {
$text = str_replace($matchs[0][$key], "[:IMAGE:browse:90:90:images/other/imgerr.jpg::]", $text);
} else if (file_put_contents(public_path($imagePath), $image)) {
ImgCompress::compress(public_path($imagePath));
} else if (Base::saveContentImage(public_path($imagePath), $image)) {
$imageSize = getimagesize(public_path($imagePath));
if (Base::imgThumb(public_path($imagePath), public_path($imagePath) . "_thumb.jpg", 320, 0)) {
$imagePath .= "_thumb.jpg";

View File

@ -2077,7 +2077,7 @@ class Base
/**
* image64图片保存
* @param array $param [ image64=带前缀的base64, path=>文件路径, fileName=>文件名称, scale=>[压缩原图宽,, 压缩方式], autoThumb=>false不要自动生成缩略图 ]
* @param array $param [ image64=带前缀的base64, path=>文件路径, fileName=>文件名称, scale=>[压缩原图宽,, 压缩方式], autoThumb=>false不要自动生成缩略图, 'compress'=>是否压缩图片(默认true) ]
* @return array [name=>文件名, size=>文件大小(单位KB),file=>绝对地址, path=>相对地址, url=>全路径地址, ext=>文件后缀名]
*/
public static function image64save($param)
@ -2156,6 +2156,11 @@ class Base
}
}
}
// 压缩图片
if ($param['compress'] !== false) {
ImgCompress::compress($array['file']);
$array['size'] = Base::twoFloat(filesize($array['file']) / 1024, true);
}
//生成缩略图
$array['thumb'] = $array['path'];
if ($extension === 'gif' && !isset($param['autoThumb'])) {
@ -2175,7 +2180,7 @@ class Base
/**
* 上传文件
* @param array $param [ type=[文件类型], file=>Request::file, path=>文件路径, fileName=>文件名称, scale=>[压缩原图宽,, 压缩方式], size=>限制大小KB, autoThumb=>false不要自动生成缩略图, chmod=>权限(默认0644) ]
* @param array $param [ type=[文件类型], file=>Request::file, path=>文件路径, fileName=>文件名称, scale=>[压缩原图宽,, 压缩方式], size=>限制大小KB, autoThumb=>false不要自动生成缩略图, chmod=>权限(默认0644), 'compress'=>是否压缩图片(默认true) ]
* @return array [name=>原文件名, size=>文件大小(单位KB),file=>绝对地址, path=>相对地址, url=>全路径地址, ext=>文件后缀名]
*/
public static function upload($param)
@ -2350,6 +2355,11 @@ class Base
}
$array['thumb'] = Base::fillUrl($array['thumb']);
}
// 压缩图片
if ($param['compress'] !== false) {
ImgCompress::compress($array['file']);
$array['size'] = Base::twoFloat(filesize($array['file']) / 1024, true);
}
//
return Base::retSuccess('success', $array);
} else {
@ -2961,4 +2971,21 @@ class Base
}
return Response::streamDownload($callback, $name);
}
/**
* 保存图片到文件(同时压缩)
* @param $path
* @param $content
* @param $compress
* @return bool
*/
public static function saveContentImage($path, $content, $compress = true) {
if (file_put_contents($path, $content)) {
if ($compress) {
ImgCompress::compress($path);
}
return true;
}
return false;
}
}

View File

@ -129,7 +129,7 @@ class ImgCompress
if (!file_exists($src)) {
return;
}
$allowImgs = ['.jpg', '.jpeg', '.png', '.bmp', '.wbmp', '.gif'];
$allowImgs = ['.jpg', '.jpeg', '.png', '.bmp', '.wbmp'];
if (!in_array(strrchr($src, "."), $allowImgs)) {
return;
}