perf: 聊天消息附件支持预览

This commit is contained in:
kuaifan
2022-01-27 00:44:49 +08:00
parent 08372facd7
commit 705d7f3da0
9 changed files with 268 additions and 13 deletions

View File

@@ -329,6 +329,56 @@ class DialogController extends AbstractController
return Base::retSuccess('success', $read ?: []);
}
/**
* @api {get} api/dialog/msg/detail 08. 消息详情
*
* @apiDescription 需要token身份
* @apiVersion 1.0.0
* @apiGroup dialog
* @apiName msg__detail
*
* @apiParam {Number} msg_id 消息ID
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function msg__detail()
{
User::auth();
//
$msg_id = intval(Request::input('msg_id'));
//
$dialogMsg = WebSocketDialogMsg::whereId($msg_id)->first();
if (empty($dialogMsg)) {
return Base::retError("文件不存在");
}
$data = $dialogMsg->toArray();
//
if ($data['type'] == 'file') {
$codeExt = ['txt'];
$fillExt = ['jpg', 'jpeg', 'png', 'gif'];
$msg = Base::json2array($dialogMsg->getRawOriginal('msg'));
$filePath = public_path($msg['path']);
if (in_array($msg['ext'], $codeExt) && $msg['size'] < 2 * 1024 * 1024) {
// 文本代码限制2M内的文件
$data['content'] = file_get_contents($filePath);
$data['file_mode'] = 1;
} else {
// 支持预览
if (in_array($msg['ext'], $fillExt)) {
$url = Base::fillUrl($msg['path']);
} else {
$url = 'http://' . env('APP_IPPR') . '.3/' . $msg['path'];
}
$data['url'] = base64_encode($url);
$data['file_mode'] = 2;
}
}
//
return Base::retSuccess("success", $data);
}
/**
* @api {get} api/dialog/msg/download 08. 文件下载
*