hn-hlw-service/README.md
2026-08-25 17:03:56 +08:00

39 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 腾讯 IM 图片本地归档
腾讯 IM 的图片消息在 `/IMCallBack` 入库后,会异步下载 `TIMImageElem`
中的 `Type=1` 原图并保存到服务器私有目录。归档状态保存在
`Internet-hospital.im-chat-msg.imageArchive`
可选环境变量:
```ini
# 建议在生产环境显式配置为代码目录之外、具备持久化和备份的绝对路径
CONFIG_IM_IMAGE_ROOT=/data/hn-private-files/im-chat
# 默认 30MB
CONFIG_IM_IMAGE_MAX_BYTES=31457280
# 逗号分隔的腾讯图片域名后缀
CONFIG_IM_IMAGE_ALLOWED_HOSTS=.my-imcloud.com,.im.qcloud.com,.myqcloud.com
```
未设置 `CONFIG_IM_IMAGE_ROOT` 时,路径规则与现有 `/upload` 一致:以服务入口
目录为基准,保存到 `../private-files/im-chat`。例如:
- 源码从 `hn-hlw-service/index.js` 运行时,保存到项目组目录下的
`private-files/im-chat`,与现有 `upload-files` 同级。
- bundle 位于 `/opt/apps/hnhlw/bundle_xx.js` 时,保存到
`/opt/apps/private-files/im-chat`,与 `/opt/apps/upload-files` 同级。
`private-files` 不会通过 Express 静态目录公开。该目录不能在发布时被清理;
Docker 部署时必须挂载持久化卷。
归档成功后可通过下面的接口读取图片:
```text
GET /im-chat/image/:msgId
```
当前接口按需求暂未启用 JWT但仅允许通过 `MsgId` 查询数据库中归档成功的受控路径。
生产使用前建议补充问诊订单权限验证。