Merge remote-tracking branch 'upstream/main'

pull/592/head
BanTanger 2 years ago
commit 407892ad86

@ -26,12 +26,14 @@
## Open-IM-Server 是什么
Open-IM-Server 是一款即时通讯服务器,使用纯 Golang 开发,采用 JSON over WebSocket 传输协议。在 Open-IM-Server 中所有东西都是消息因此您可以轻松扩展自定义消息而无需修改服务器代码。使用微服务架构Open-IM-Server 可以使用集群进行部署。通过在客户端服务器上部署 Open-IM-Server开发人员可以免费快速地将即时通讯和实时网络功能集成到自己的应用程序中并确保业务数据的安全性和隐私性。
Open-IM-Server 是一款即时通讯服务器,使用纯 Golang 开发,采用 JSON over WebSocket 传输协议。在 Open-IM-Server 中所有东西都是消息因此您可以轻松扩展自定义消息而无需修改服务器代码。使用微服务架构Open-IM-Server 可以使用集群进行部署。通过在服务器上部署 Open-IM-Server开发人员可以快速地将即时通讯和实时网络功能集成到自己的应用程序中并确保业务数据的安全性和隐私性。
Open-IM-Server并不是一个独立的产品本身不包含账号的注册和登录服务。
为方便大家测试,我们开源了包括登录注册功能的 [chat 仓库](https://github.com/OpenIMSDK/chat)chat 业务服务端和 Open-IM-Server 一起部署,即可搭建一个聊天产品。
## 特点
+ 免费
+ 可扩展架构
+ 开源
+ 易于集成
+ 良好的可扩展性
+ 高性能
@ -40,137 +42,207 @@ Open-IM-Server 是一款即时通讯服务器,使用纯 Golang 开发,采用
## 社区
+ 访问中文官方网站:[Open-IM中文开发文档](https://doc.rentsoft.cn/)
+ 访问中文官方网站:[OpenIM中文开发文档](https://doc.rentsoft.cn/)
## 快速开始
### 安装Open-IM-Server
> Open-IM 依赖于五个开源高性能组件ETCD、MySQL、MongoDB、Redis 和 Kafka。在部署 Open-IM-Server 之前,请确保已安装上述五个组件。如果您的服务器没有上述组件,则必须首先安装缺失组件。如果您已经拥有上述组件,则建议直接使用它们。如果没有,则建议使用 Docker-compose无需安装依赖项一键部署更快更方便。
### 使用 Docker 部署
1. 安装 [Go 环境](https://golang.org/doc/install)。确保 Go 版本至少为 1.17。
2. 克隆 Open-IM 项目到您的服务器
### 使用 docker-compose 部署
`git clone <https://github.com/OpenIMSDK/Open-IM-Server.git> --recursive`
1. 克隆项目
3. 部署
```
git clone https://github.com/OpenIMSDK/Open-IM-Server
cd Open-IM-Server
git checkout release-v3.0 #or other release branch
```
1. 修改 env
2. 修改 .env
```
#cd Open-IM-server
USER=root
PASSWORD=openIM123 #密码至少8位数字不包括特殊字符
ENDPOINT=http://127.0.0.1:10005 #请用互联网IP替换127.0.0.1
DATA_DIR=./
此处主要修改相关组件密码
USER=root #不用修改
PASSWORD=openIM123 #8位以上的数字和字母组合密码密码对redis mysql mongo生效以及config/config.yaml中的accessSecret
ENDPOINT=http://127.0.0.1:10005 #minio对外服务的ip和端口或用域名storage.xx.xxapp要能访问到此ip和端口或域名
API_URL=http://127.0.0.1:10002/object/ #app要能访问到此ip和端口或域名
DATA_DIR=./ #指定大磁盘目录
```
2. 部署和启动
3. 部署和启动
注意:此命令只能执行一次,它会根据.env 中的 PASSWORD 变量修改 docker-compose 中组件密码,并修改 config/config.yaml 中的组件密码
如果.env 中的密码变了,需要先 docker-compose down ; rm components -rf 后再执行此命令。
```
chmod +x install_im_server.sh;
./install_im_server.sh;
```
3. 检查服务
4. 检查服务
```
cd scripts;
./docker_check_service.sh
./check_all.sh
```
![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Open-IM-Servers-on-System.png](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Open-IM-Servers-on-System.png)
![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/docker_build.png](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/docker_build.png)
### 使用源代码部署
### 使用源码编译
1. Go 1.17 或更高版本。
1. Go 1.18或更高版本。
2. 克隆
```
git clone <https://github.com/OpenIMSDK/Open-IM-Server.git> --recursive
cd cmd/openim-sdk-core
git checkout main
git clone https://github.com/OpenIMSDK/Open-IM-Server
cd Open-IM-Server
git checkout release-v3.0 #or other release branch
```
3. 设置可执行权限
3. 编译
```
cd ../../scripts/
cd Open-IM-server/scripts
chmod +x *.sh
./build_all_service.sh
```
4. 构建
所有服务已成功构建如图所示
![编译成功](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/build.png)
### 组件配置说明
config/config.yaml中针对存储组件有详细的配置说明
+ Zookeeper
+ 用于RPC 服务发现和注册,支持集群。
````
```
./batch_build_all_service.sh
zookeeper:
schema: openim #不建议修改
address: [ 127.0.0.1:2181 ] #地址
username: #用户名
password: #密码
```
````
所有服务已成功构建
### 配置说明
> Open-IM 配置分为基本组件配置和业务内部服务配置。当使用产品时,开发人员需要将每个组件的地址填写为其服务器组件的地址,并确保业务内部服务端口未被占用。
+ MySQL
+ 用于存储用户、关系链、群组,支持数据库主备。
```
mysql:
address: [ 127.0.0.1:13306 ] #地址
username: root #用户名
password: openIM123 #密码
database: openIM_v2 #不建议修改
maxOpenConn: 1000 #最大连接数
maxIdleConn: 100 #最大空闲连接数
maxLifeTime: 60 #连接可以重复使用的最长时间(秒)
logLevel: 4 #日志级别 1=slient 2=error 3=warn 4=info
slowThreshold: 500 #慢语句阈值 (毫秒)
```
### 基本组件配置说明
+ ETCD
+ Etcd 用于 RPC 服务的发现和注册Etcd Schema 是注册名称的前缀建议将其修改为公司名称Etcd 地址(ip+port)支持集群部署,可以填写多个 ETCD 地址,也可以只有一个 etcd 地址。
+ MySQL
+ MySQL 用于消息和用户关系的全存储,暂时不支持集群部署。修改地址、用户、密码和数据库名称。
+ Mongo
+ Mongo 用于消息的离线存储,默认存储 7 天。暂时不支持集群部署。只需修改地址和数据库名称即可。
+ 用于存储离线消息支持mongo分片集群。
```
mongo:
uri: #不为空则直接使用该值
address: [ 127.0.0.1:37017 ] #地址
database: openIM #mongo db 默认即可
username: root #用户名
password: openIM123 #密码
maxPoolSize: 100 #最大连接数
```
+ Redis
+ Redis 目前主要用于消息序列号存储和用户令牌信息存储。暂时不支持集群部署。只需修改相应的 Redis 地址和密码即可。
+ 用于存储消息序列号、最新消息、用户token及mysql缓存支持集群部署。
```
redis:
address: [ 127.0.0.1:16379 ] #地址
username: #用户名
password: openIM123 #密码
```
+ Kafka
+ Kafka 用作消息传输存储队列,支持集群部署,只需修改相应的地址。
+ 用于消息队列,用于消息解耦,支持集群部署
### 内部服务配置说明
```
kafka:
username: #用户名
password: #密码
addr: [ 127.0.0.1:9092 ] #地址
latestMsgToRedis:
topic: "latestMsgToRedis"
offlineMsgToMongo:
topic: "offlineMsgToMongoMysql"
msgToPush:
topic: "msqToPush"
msgToModify:
topic: "msgToModify"
consumerGroupID:
msgToRedis: redis
msgToMongo: mongo
msgToMySql: mysql
msgToPush: push
msgToModify: modify
```
+ credential&&push
+ Open-IM 需要使用三方离线推送功能。目前使用的是腾讯的三方推送,支持 IOS、Android 和 OSX 推送。这些信息是腾讯推送的一些注册信息,开发人员需要去腾讯云移动推送注册相应的信息。如果您没有填写相应的信息,则无法使用离线消息推送功能。
+ api&&rpcport&&longconnsvr&&rpcregistername
+ API 端口是 HTTP 接口longconnsvr 是 WebSocket 监听端口rpcport 是内部服务启动端口。两者都支持集群部署。请确保这些端口未被使用。如果要为单个服务打开多个服务请填写多个以逗号分隔的端口。rpcregistername 是每个服务在注册表 Etcd 中注册的服务名称,无需修改。
+ log&&modulename
+ 日志配置包括日志文件的存储路径,日志发送到 Elasticsearch 进行日志查看。目前不支持将日志发送到 Elasticsearch。暂时不需要修改配置。modulename 用于根据服务模块的名称拆分日志。默认配置可以。
### 启停服务
### 脚本说明
启动服务
> Open-IM 脚本提供服务编译、启动和停止脚本。有四个 Open-IM 脚本启动模块,一个是 http+rpc 服务启动模块,第二个是 WebSocket 服务启动模块,然后是 msg_transfer 模块,最后是 push 模块。
```
./start_all.sh;
```
+ path_info.sh&&style_info.sh&&
检查服务
functions.sh
```
./check_all.sh
```
+ 包含每个模块的路径信息包括源代码所在的路径、服务启动名称、shell 打印字体样式以及一些用于处理 shell 字符串的函数。
停止服务
+ build_all_service.sh
```
./stop_all.sh
```
+ 编译模块,将 Open-IM 的所有源代码编译为二进制文件并放入 bin 目录。
### 开放 IM 端口
+ start_rpc_api_service.sh&&msg_gateway_start.sh&&msg_transfer_start.sh&&push_start.sh
| TCP 端口 | 说明 | 操作 |
| --------- | ----------------------------------------------------- | --------------------------------------- |
| TCP:10001 | ws 协议,消息端口,如消息发送、推送等,用于客户端 SDK | 端口放行或 nginx 反向代理,并关闭防火墙 |
| TCP:10002 | api 端口,如用户、好友、群组、消息等接口。 | 端口放行或 nginx 反向代理,并关闭防火墙 |
| TCP:10005 | 选择 minio 存储时需要(openIM 默认使用 minio 存储) | 端口放行或 nginx 反向代理,并关闭防火墙 |
+ 独立脚本启动模块,后跟 API 和 RPC 模块、消息网关模块、消息传输模块和推送模块。
### 开放 Chat 端口
+ start_all.sh&&stop_all.sh
| TCP 端口 | 说明 | 操作 |
| --------- | ------------------------ | --------------------------------------- |
| TCP:10008 | 业务系统,如注册、登录等 | 端口放行或 nginx 反向代理,并关闭防火墙 |
| TCP:10009 | 管理后台,如统计、封号等 | 端口放行或 nginx 反向代理,并关闭防火墙 |
+ 总脚本,启动所有服务和关闭所有服务。
## APP和OpenIM关系
## 认证流程图
OpenIM 是开源的即时通讯组件它并不是一个独立的产品此图展示了AppServer、AppClient、Open-IM-Server以及Open-IM-SDK之间的关系
![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/open-im-server.png](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/open-im-server.png)
![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/open-im-server.png](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/open-im-server.png)
## 架构
## 整体架构
![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Architecture.jpg](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Architecture.jpg)
![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Architecture.jpg](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/Architecture.jpg)
## 开始开发 OpenIM
[社区存储库](https://github.com/OpenIMSDK/community)包含有关从源代码构建 Kubernetes、如何贡献代码和文档、有关什么的联系人等所有信息
[社区存储库](https://github.com/OpenIMSDK/community)包含有关从源代码构建 Kubernetes、如何贡献代码和文档。
## 贡献

@ -28,142 +28,215 @@
## What is Open-IM-Server
Instant messaging server. Backend in pure Golang, wire transport protocol is JSON over websocket.
Everything is a message in Open-IM-Server, so you can extend custom messages easily, there is no need to modify the server code.
Using microservice architectures, Open-IM-Server can be deployed using clusters.
By deployment of the Open-IM-Server on the customer's server, developers can integrate instant messaging and real-time network capabilities into their own applications free of charge and quickly, and ensure the security and privacy of business data.
Open-IM-Server is an instant messaging server developed using pure Golang, adopting JSON over WebSocket as the communication protocol. In Open-IM-Server, everything is a message, so you can easily extend custom messages without modifying the server code. With a microservice architecture, Open-IM-Server can be deployed using clusters. By deploying Open-IM-Server on a server, developers can quickly integrate instant messaging and real-time networking features into their applications, ensuring the security and privacy of business data.
Open-IM-Server is not a standalone product and does not include account registration and login services. For your convenience, we have open-sourced the [chat repository](https://github.com/OpenIMSDK/chat) which includes login and registration functionality. By deploying the chat business server alongside Open-IM-Server, a chat product can be set up.
## Features
- Everything in Free
- Scalable architecture
- Easy integration
- Good scalability
- Open source
- Easy to integrate
- Excellent scalability
- High performance
- Lightweight
- Supports multiple protocols
## Community
- Visit the Chinese official website here: [📚 Open-IM docs](https://www.openim.online/zh)
## Quick start
### Installing Open-IM-Server
- Visit the official website: [OpenIM Developer Documentation](https://www.openim.online/)
> Open-IM relies on five open source high-performance components: ETCD, MySQL, MongoDB, Redis, and Kafka. Privatization deployment Before Open-IM-Server, please make sure that the above five components have been installed. If your server does not have the above components, you must first install Missing components. If you have the above components, it is recommended to use them directly. If not, it is recommended to use Docker-compose, no To install dependencies, one-click deployment, faster and more convenient.
## Quick Start
#### Deploy using Docker
### Deploying with docker-compose
1. Install [Go environment](https://golang.org/doc/install). Make sure Go version is at least 1.17
2. Clone the Open-IM project to your server
1. Clone the project
```
git clone https://github.com/OpenIMSDK/Open-IM-Server.git --recursive
clone https://github.com/OpenIMSDK/Open-IM-Server
cd Open-IM-Server
git checkout release-v3.0 #or other release branch
```
3. Deploy
1. Modify env
1. Modify .env
```
#cd Open-IM-server
USER=root
PASSWORD=openIM123 #Password with more than 8 digits, excluding special characters
ENDPOINT=http://127.0.0.1:10005 #Replace 127.0.0.1 with Internet IP
DATA_DIR=./
USER=root #no need to modify
PASSWORD=openIM123 #A combination of 8 or more numbers and letters, this password applies to redis, mysql, mongo, as well as accessSecret in config/config.yaml
ENDPOINT=http://127.0.0.1:10005 #minio's external service IP and port, or use the domain name storage.xx.xx, the app must be able to access this IP and port or domain,
API_URL=http://127.0.0.1:10002/object/ #the app must be able to access this IP and port or domain,
DATA_DIR=./ #designate large disk directory
```
2. Deploy && Start
1. Deploy and start
Note: This command can only be executed once. It will modify the component passwords in docker-compose based on the PASSWORD variable in .env, and modify the component passwords in config/config.yaml. If the password in .env changes, you need to first execute docker-compose down; rm components -rf and then execute this command.
```
chmod +x install_im_server.sh;
./install_im_server.sh;
```
4. Check service
1. Check the service
```
cd scripts;
./docker_check_service.sh./check_all.sh
./docker_check_service.sh
```
![OpenIMServersonSystempng](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/Open-IM-Servers-on-System.png)
![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/docker_build.png](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/docker_build.png)
#### Deploy using source code
1. Go 1.17 or above.
### Compile from source
1. Go 1.18 or higher version.
2. Clone
```shell
git clone https://github.com/OpenIMSDK/Open-IM-Server.git --recursive
cd cmd/openim-sdk-core
git checkout main
```
git clone https://github.com/OpenIMSDK/Open-IM-Server
cd Open-IM-Server
git checkout release-v3.0 #or other release branch
```
1. Set executable permissions
3. Compile
```shell
cd ../../scripts/
```
cd Open-IM-server/scripts
chmod +x *.sh
./build_all_service.sh
```
1. build
All services have been successfully built as shown in the figure
```shell
./batch_build_all_service.sh
```
![Successful Compilation](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/build.png)
all services build success
### Component Configuration Instructions
### CONFIGURATION INSTRUCTIONS
The config/config.yaml file has detailed configuration instructions for the storage components.
> Open-IM configuration is divided into basic component configuration and business internal service configuration. Developers need to fill in the address of each component as the address of their server component when using the product, and ensure that the internal service port of the business is not occupied
- Zookeeper
#### Basic Component Configuration Instructions
- Used for RPC service discovery and registration, cluster support.
```
zookeeper:
schema: openim #Not recommended to modify
address: [ 127.0.0.1:2181 ] #address
username: #username
password: #password
```
- ETCD
- Etcd is used for the discovery and registration of rpc services, etcd Schema is the prefix of the registered name, it is recommended to modify it to your company name, etcd address (ip+port) supports clustered deployment, you can fill in multiple ETCD addresses separated by commas, and also only one etcd address.
- MySQL
- mysql is used for full storage of messages and user relationships. Cluster deployment is not supported for the time being. Modify addresses and users, passwords, and database names.
- Used for storing users, relationships, and groups, supports master-slave database.
```
mysql:
address: [ 127.0.0.1:13306 ] #address
username: root #username
password: openIM123 #password
database: openIM_v2 #Not recommended to modify
maxOpenConn: 1000 #maximum connection
maxIdleConn: 100 #maximum idle connection
maxLifeTime: 60 #maximum time a connection can be reused (seconds)
logLevel: 4 #log level 1=slient 2=error 3=warn 4=info
slowThreshold: 500 #slow statement threshold (milliseconds)
```
- Mongo
- Mongo is used for offline storage of messages. The default storage is 7 days. Cluster deployment is temporarily not supported. Just modify the address and database name.
- Used for storing offline messages, supports mongo sharded clusters.
```
mongo:
uri: #Use this value directly if not empty
address: [ 127.0.0.1:37017 ] #address
database: openIM #default mongo db
username: root #username
password: openIM123 #password
maxPoolSize: 100 #maximum connections
```
- Redis
- Redis is currently mainly used for message serial number storage and user token information storage. Cluster deployment is temporarily not supported. Just modify the corresponding redis address and password.
- Used for storing message sequence numbers, latest messages, user tokens, and mysql cache, supports cluster deployment.
```
redis:
address: [ 127.0.0.1:16379 ] #address
username: #username
password: openIM123 #password
```
- Kafka
- Kafka is used as a message transfer storage queue to support cluster deployment, just modify the corresponding address
#### Internal Service Configuration Instructions
- Used for message queues, for message decoupling, supports cluster deployment.
```
kafka:
username: #username
password: #password
addr: [ 127.0.0.1:9092 ] #address
latestMsgToRedis:
topic: "latestMsgToRedis"
offlineMsgToMongo:
topic: "offlineMsgToMongoMysql"
msgToPush:
topic: "msqToPush"
msgToModify:
topic: "msgToModify"
consumerGroupID:
msgToRedis: redis
msgToMongo: mongo
msgToMySql: mysql
msgToPush: push
msgToModify: modify
```
### Start and Stop Services
Start services
```
./start_all.sh;
```
Check services
```
./check_all.sh
```
Stop services
```
./stop_all.sh
```
### Open IM Ports
- credential&&push
- The Open-IM needs to use the three-party offline push function. Currently, Tencent's three-party push is used. It supports IOS, Android and OSX push. This information is some registration information pushed by Tencent. Developers need to go to Tencent Cloud Mobile Push to register the corresponding information. If you do not fill in the corresponding information, you cannot use the offline message push function
- api&&rpcport&&longconnsvr&&rpcregistername
- The api port is the http interface, longconnsvr is the websocket listening port, and rpcport is the internal service startup port. Both support cluster deployment. Make sure that these ports are not used. If you want to open multiple services for a single service, fill in multiple ports separated by commas. rpcregistername is the service name registered by each service to the registry etcd, no need to modify
- log&&modulename
- The log configuration includes the storage path of the log file, and the log is sent to elasticsearch for log viewing. Currently, the log is not supported to be sent to elasticsearch. The configuration does not need to be modified for the time being. The modulename is used to split the log according to the name of the service module. The default configuration is fine.
- multiloginpolicy&&tokenpolicy
- Open-IM supports multi-terminal login. Currently, there are three multi-terminal login policies. The PC terminal and the mobile terminal are online at the same time by default. When multiple policies are configured to be true, the first policy with true is used by default, and the token policy is the generated token policy. , The developer can customize the expiration time of the token
| TCP Port | Description | Operation |
| --------- | ------------------------------------------------------------ | ----------------------------------------------------- |
| TCP:10001 | ws protocol, message port such as message sending, pushing etc, used for client SDK | Port release or nginx reverse proxy, and firewall off |
| TCP:10002 | api port, such as user, friend, group, message interfaces. | Port release or nginx reverse proxy, and firewall off |
| TCP:10005 | Required when choosing minio storage (openIM uses minio storage by default) | Port release or nginx reverse proxy, and firewall off |
### scripts DESCRIPTION
### Open Chat Ports
> Open-IM scripts provides service compilation, start, and stop scripts. There are four Open-IM scripts start modules, one is the http+rpc service start module, the second is the websocket service start module, then the msg_transfer module, and the last is the push module
| TCP Port | Description | Operation |
| --------- | --------------------------------------------------- | ----------------------------------------------------- |
| TCP:10008 | Business system, such as registration, login etc | Port release or nginx reverse proxy, and firewall off |
| TCP:10009 | Management backend, such as statistics, banning etc | Port release or nginx reverse proxy, and firewall off |
- path_info.sh&&style_info.sh&&functions.sh
- Contains the path information of each module, including the path where the source code is located, the name of the service startup, the shell print font style, and some functions for processing shell strings
- build_all_service.sh
- Compile the module, compile all the source code of Open-IM into a binary file and put it into the bin directory
- start_rpc_api_service.sh&&msg_gateway_start.sh&&msg_transfer_start.sh&&push_start.sh
- Independent scripts startup module, followed by api and rpc modules, message gateway module, message transfer module, and push module
- start_all.sh&&stop_all.sh
- Total scripts, start all services and close all services
## Relationship Between APP and OpenIM
## Authentication Clow Chart
OpenIM is an open source instant messaging component, it is not an independent product. This image shows the relationship between AppServer, AppClient, Open-IM-Server and Open-IM-SDK.
![avatar](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/open-im-server.png)
![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/open-im-server.png](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/open-im-server.png)
## Architecture
## Overall Architecture
![avatar](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/Architecture.jpg)
![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Architecture.jpg](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/Architecture.jpg)
## To start developing OpenIM
The [community repository](https://github.com/OpenIMSDK/community) hosts all information about building Kubernetes from source, how to contribute code and documentation, who to contact about what, etc.

@ -74,7 +74,7 @@ api:
object:
enable: "minio" #使用minio
apiURL: "http://127.0.0.1:10002/object/"
apiURL: "http://127.0.0.1:10002/object/" #地址需要app能访问到
minio:
bucket: "openim" #不建议修改
endpoint: "http://127.0.0.1:10005" #minio对外服务的ip和端口app要能访问此ip和端口

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

@ -77,9 +77,7 @@ func (s *s3Database) AccessURL(ctx context.Context, name string, expire time.Dur
}
opt := &s3.AccessURLOption{
ContentType: obj.ContentType,
}
if filename := filepath.Base(obj.Name); filename != "" {
opt.ContentDisposition = `attachment; filename=` + filename
Filename: filepath.Base(obj.Name),
}
expireTime := time.Now().Add(expire)
rawURL, err := s.s3.AccessURL(ctx, obj.Key, expire, opt)

@ -248,21 +248,27 @@ func (c *Cos) ListUploadedParts(ctx context.Context, uploadID string, name strin
}
func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) {
//reqParams := make(url.Values)
//if opt != nil {
// if opt.ContentType != "" {
// reqParams.Set("Content-Type", opt.ContentType)
// }
// if opt.ContentDisposition != "" {
// reqParams.Set("Content-Disposition", opt.ContentDisposition)
// }
//}
var option *cos.PresignedURLOptions
if opt != nil {
query := make(url.Values)
if opt.ContentType != "" {
query.Set("response-content-type", opt.ContentType)
}
if opt.Filename != "" {
query.Set("response-content-disposition", `attachment; filename="`+opt.Filename+`"`)
}
if len(query) > 0 {
option = &cos.PresignedURLOptions{
Query: &query,
}
}
}
if expire <= 0 {
expire = time.Hour * 24 * 365 * 99 // 99 years
} else if expire < time.Second {
expire = time.Second
}
rawURL, err := c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, nil)
rawURL, err := c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, option)
if err != nil {
return "", err
}

@ -253,21 +253,21 @@ func (m *Minio) ListUploadedParts(ctx context.Context, uploadID string, name str
}
func (m *Minio) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) {
//reqParams := make(url.Values)
//if opt != nil {
// if opt.ContentType != "" {
// reqParams.Set("Content-Type", opt.ContentType)
// }
// if opt.ContentDisposition != "" {
// reqParams.Set("Content-Disposition", opt.ContentDisposition)
// }
//}
reqParams := make(url.Values)
if opt != nil {
if opt.ContentType != "" {
reqParams.Set("response-content-type", opt.ContentType)
}
if opt.Filename != "" {
reqParams.Set("response-content-disposition", `attachment; filename="`+opt.Filename+`"`)
}
}
if expire <= 0 {
expire = time.Hour * 24 * 365 * 99 // 99 years
} else if expire < time.Second {
expire = time.Second
}
u, err := m.core.Client.PresignedGetObject(ctx, m.bucket, name, expire, nil)
u, err := m.core.Client.PresignedGetObject(ctx, m.bucket, name, expire, reqParams)
if err != nil {
return "", err
}

@ -261,15 +261,15 @@ func (o *OSS) ListUploadedParts(ctx context.Context, uploadID string, name strin
}
func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) {
//var opts []oss.Option
//if opt != nil {
// if opt.ContentType != "" {
// opts = append(opts, oss.ContentType(opt.ContentType))
// }
// if opt.ContentDisposition != "" {
// opts = append(opts, oss.ContentDisposition(opt.ContentDisposition))
// }
//}
var opts []oss.Option
if opt != nil {
if opt.ContentType != "" {
opts = append(opts, oss.ResponseContentType(opt.ContentType))
}
if opt.Filename != "" {
opts = append(opts, oss.ResponseContentDisposition(`attachment; filename="`+opt.Filename+`"`))
}
}
if expire <= 0 {
expire = time.Hour * 24 * 365 * 99 // 99 years
} else if expire < time.Second {

@ -118,7 +118,7 @@ type ListUploadedPartsResult struct {
type AccessURLOption struct {
ContentType string `json:"contentType"`
ContentDisposition string `json:"contentDisposition"`
Filename string `json:"filename"`
}
type Interface interface {

Loading…
Cancel
Save