Browse Source

Merge pull request #823 from SliverHorn/sliver

feature: 集成华为云obs 对象存储
main
奇淼(piexlmax 3 years ago
committed by GitHub
parent
commit
2aed46bba3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      server/config.docker.yaml
  2. 10
      server/config.yaml
  3. 6
      server/config/config.go
  4. 32
      server/config/oss.go
  5. 10
      server/config/oss_aliyun.go
  6. 9
      server/config/oss_huawei.go
  7. 5
      server/config/oss_local.go
  8. 11
      server/config/oss_qiniu.go
  9. 10
      server/config/oss_tencent.go
  10. 1
      server/go.mod
  11. 2
      server/go.sum
  12. 65
      server/utils/upload/obs.go
  13. 20
      server/utils/upload/upload.go
  14. 2
      web/package.json
  15. 20
      web/src/view/systemTools/system/system.vue

10
server/config.docker.yaml

@ -94,7 +94,6 @@ qiniu:
secret-key: '' secret-key: ''
use-cdn-domains: false use-cdn-domains: false
# aliyun oss configuration # aliyun oss configuration
aliyun-oss: aliyun-oss:
endpoint: 'yourEndpoint' endpoint: 'yourEndpoint'
@ -112,11 +111,18 @@ tencent-cos:
base-url: 'https://gin.vue.admin' base-url: 'https://gin.vue.admin'
path-prefix: 'github.com/flipped-aurora/gin-vue-admin/server' path-prefix: 'github.com/flipped-aurora/gin-vue-admin/server'
# huawei obs configuration
hua-wei-obs:
path: 'you-path'
bucket: 'you-bucket'
endpoint: 'you-endpoint'
access-key: 'you-access-key'
secret-key: 'you-secret-key'
# excel configuration # excel configuration
excel: excel:
dir: './resource/excel/' dir: './resource/excel/'
# timer task db clear table # timer task db clear table
Timer: Timer:
start: true start: true

10
server/config.yaml

@ -115,7 +115,6 @@ qiniu:
secret-key: '' secret-key: ''
use-cdn-domains: false use-cdn-domains: false
# aliyun oss configuration # aliyun oss configuration
aliyun-oss: aliyun-oss:
endpoint: 'yourEndpoint' endpoint: 'yourEndpoint'
@ -134,11 +133,18 @@ tencent-cos:
base-url: 'https://gin.vue.admin' base-url: 'https://gin.vue.admin'
path-prefix: 'github.com/flipped-aurora/gin-vue-admin/server' path-prefix: 'github.com/flipped-aurora/gin-vue-admin/server'
# huawei obs configuration
hua-wei-obs:
path: 'you-path'
bucket: 'you-bucket'
endpoint: 'you-endpoint'
access-key: 'you-access-key'
secret-key: 'you-secret-key'
# excel configuration # excel configuration
excel: excel:
dir: './resource/excel/' dir: './resource/excel/'
# timer task db clear table # timer task db clear table
Timer: Timer:
start: true start: true

6
server/config/config.go

@ -17,7 +17,9 @@ type Server struct {
Local Local `mapstructure:"local" json:"local" yaml:"local"` Local Local `mapstructure:"local" json:"local" yaml:"local"`
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"` Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"` AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
HuaWeiObs HuaWeiObs `mapstructure:"hua-wei-obs" json:"huaWeiObs" yaml:"hua-wei-obs"`
TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"` TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"`
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
Timer Timer `mapstructure:"timer" json:"timer" yaml:"timer"`
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
Timer Timer `mapstructure:"timer" json:"timer" yaml:"timer"`
} }

32
server/config/oss.go

@ -1,32 +0,0 @@
package config
type Local struct {
Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件路径
}
type Qiniu struct {
Zone string `mapstructure:"zone" json:"zone" yaml:"zone"` // 存储区域
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` // 空间名称
ImgPath string `mapstructure:"img-path" json:"imgPath" yaml:"img-path"` // CDN加速域名
UseHTTPS bool `mapstructure:"use-https" json:"useHttps" yaml:"use-https"` // 是否使用https
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"` // 秘钥AK
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"` // 秘钥SK
UseCdnDomains bool `mapstructure:"use-cdn-domains" json:"useCdnDomains" yaml:"use-cdn-domains"` // 上传是否使用CDN上传加速
}
type AliyunOSS struct {
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"`
AccessKeyId string `mapstructure:"access-key-id" json:"accessKeyId" yaml:"access-key-id"`
AccessKeySecret string `mapstructure:"access-key-secret" json:"accessKeySecret" yaml:"access-key-secret"`
BucketName string `mapstructure:"bucket-name" json:"bucketName" yaml:"bucket-name"`
BucketUrl string `mapstructure:"bucket-url" json:"bucketUrl" yaml:"bucket-url"`
BasePath string `mapstructure:"base-path" json:"basePath" yaml:"base-path"`
}
type TencentCOS struct {
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
Region string `mapstructure:"region" json:"region" yaml:"region"`
SecretID string `mapstructure:"secret-id" json:"secretID" yaml:"secret-id"`
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
BaseURL string `mapstructure:"base-url" json:"baseURL" yaml:"base-url"`
PathPrefix string `mapstructure:"path-prefix" json:"pathPrefix" yaml:"path-prefix"`
}

10
server/config/oss_aliyun.go

@ -0,0 +1,10 @@
package config
type AliyunOSS struct {
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"`
AccessKeyId string `mapstructure:"access-key-id" json:"accessKeyId" yaml:"access-key-id"`
AccessKeySecret string `mapstructure:"access-key-secret" json:"accessKeySecret" yaml:"access-key-secret"`
BucketName string `mapstructure:"bucket-name" json:"bucketName" yaml:"bucket-name"`
BucketUrl string `mapstructure:"bucket-url" json:"bucketUrl" yaml:"bucket-url"`
BasePath string `mapstructure:"base-path" json:"basePath" yaml:"base-path"`
}

9
server/config/oss_huawei.go

@ -0,0 +1,9 @@
package config
type HuaWeiObs struct {
Path string `mapstructure:"path" json:"path" yaml:"path"`
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"`
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"`
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
}

5
server/config/oss_local.go

@ -0,0 +1,5 @@
package config
type Local struct {
Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件路径
}

11
server/config/oss_qiniu.go

@ -0,0 +1,11 @@
package config
type Qiniu struct {
Zone string `mapstructure:"zone" json:"zone" yaml:"zone"` // 存储区域
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` // 空间名称
ImgPath string `mapstructure:"img-path" json:"imgPath" yaml:"img-path"` // CDN加速域名
UseHTTPS bool `mapstructure:"use-https" json:"useHttps" yaml:"use-https"` // 是否使用https
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"` // 秘钥AK
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"` // 秘钥SK
UseCdnDomains bool `mapstructure:"use-cdn-domains" json:"useCdnDomains" yaml:"use-cdn-domains"` // 上传是否使用CDN上传加速
}

10
server/config/oss_tencent.go

@ -0,0 +1,10 @@
package config
type TencentCOS struct {
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
Region string `mapstructure:"region" json:"region" yaml:"region"`
SecretID string `mapstructure:"secret-id" json:"secretID" yaml:"secret-id"`
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
BaseURL string `mapstructure:"base-url" json:"baseURL" yaml:"base-url"`
PathPrefix string `mapstructure:"path-prefix" json:"pathPrefix" yaml:"path-prefix"`
}

1
server/go.mod

@ -16,6 +16,7 @@ require (
github.com/go-redis/redis/v8 v8.11.0 github.com/go-redis/redis/v8 v8.11.0
github.com/go-sql-driver/mysql v1.5.0 github.com/go-sql-driver/mysql v1.5.0
github.com/gookit/color v1.3.1 github.com/gookit/color v1.3.1
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.8+incompatible
github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84 github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84
github.com/mojocn/base64Captcha v1.3.1 github.com/mojocn/base64Captcha v1.3.1
github.com/natefinch/lumberjack v2.0.0+incompatible github.com/natefinch/lumberjack v2.0.0+incompatible

2
server/go.sum

@ -234,6 +234,8 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.8+incompatible h1:3kDd8PIWAdU+qGs/+0QUgsMI2ZSiJPt45Xn0su+x/Q0=
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.8+incompatible/go.mod h1:l7VUhRbTKCzdOacdT4oWCwATKyvZqUOlOqr0Ous3k4s=
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0= github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=

65
server/utils/upload/obs.go

@ -0,0 +1,65 @@
package upload
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
"github.com/pkg/errors"
"mime/multipart"
)
var HuaWeiObs = new(_obs)
type _obs struct{}
func NewHuaWeiObsClient() (client *obs.ObsClient, err error) {
return obs.New(global.GVA_CONFIG.HuaWeiObs.AccessKey, global.GVA_CONFIG.HuaWeiObs.SecretKey, global.GVA_CONFIG.HuaWeiObs.Endpoint)
}
func (o *_obs) UploadFile(file *multipart.FileHeader) (filename string, filepath string, err error) {
var open multipart.File
open, err = file.Open()
if err != nil {
return filename, filepath, err
}
filename = file.Filename
input := &obs.PutObjectInput{
PutObjectBasicInput: obs.PutObjectBasicInput{
ObjectOperationInput: obs.ObjectOperationInput{
Bucket: global.GVA_CONFIG.HuaWeiObs.Bucket,
Key: filename,
},
ContentType: file.Header.Get("content-type"),
},
Body: open,
}
var client *obs.ObsClient
client, err = NewHuaWeiObsClient()
if err != nil {
return filepath, filename, errors.Wrap(err, "获取华为对象存储对象失败!")
}
_, err = client.PutObject(input)
if err != nil {
return filepath, filename, errors.Wrap(err, "文件上传失败!")
}
filepath = global.GVA_CONFIG.HuaWeiObs.Path + "/" + filename
return filepath, filename, err
}
func (o *_obs) DeleteFile(key string) error {
client, err := NewHuaWeiObsClient()
if err != nil {
return errors.Wrap(err, "获取华为对象存储对象失败!")
}
input := &obs.DeleteObjectInput{
Bucket: global.GVA_CONFIG.HuaWeiObs.Bucket,
Key: key,
}
var output *obs.DeleteObjectOutput
output, err = client.DeleteObject(input)
if err != nil {
return errors.Wrapf(err, "删除对象(%s)失败!, output: %v", key, output)
}
return nil
}

20
server/utils/upload/upload.go

@ -6,23 +6,17 @@ import (
"github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/global"
) )
//@author: [ccfish86](https://github.com/ccfish86)
//@author: [SliverHorn](https://github.com/SliverHorn)
//@interface_name: OSS
//@description: OSS接口
// OSS 对象存储接口
// Author [SliverHorn](https://github.com/SliverHorn)
// Author [ccfish86](https://github.com/ccfish86)
type OSS interface { type OSS interface {
UploadFile(file *multipart.FileHeader) (string, string, error) UploadFile(file *multipart.FileHeader) (string, string, error)
DeleteFile(key string) error DeleteFile(key string) error
} }
//@author: [ccfish86](https://github.com/ccfish86)
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: NewOss
//@description: OSS接口
//@description: OSS的实例化方法
//@return: OSS
// NewOss OSS的实例化方法
// Author [SliverHorn](https://github.com/SliverHorn)
// Author [ccfish86](https://github.com/ccfish86)
func NewOss() OSS { func NewOss() OSS {
switch global.GVA_CONFIG.System.OssType { switch global.GVA_CONFIG.System.OssType {
case "local": case "local":
@ -33,6 +27,8 @@ func NewOss() OSS {
return &TencentCOS{} return &TencentCOS{}
case "aliyun-oss": case "aliyun-oss":
return &AliyunOSS{} return &AliyunOSS{}
case "huawei-obs":
return HuaWeiObs
default: default:
return &Local{} return &Local{}
} }

2
web/package.json

@ -50,4 +50,4 @@
"vite-plugin-banner": "^0.1.3", "vite-plugin-banner": "^0.1.3",
"vite-plugin-importer": "^0.2.5" "vite-plugin-importer": "^0.2.5"
} }
}
}

20
web/src/view/systemTools/system/system.vue

@ -22,6 +22,7 @@
<el-option value="qiniu" /> <el-option value="qiniu" />
<el-option value="tencent-cos" /> <el-option value="tencent-cos" />
<el-option value="aliyun-oss" /> <el-option value="aliyun-oss" />
<el-option value="huawei-obs" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="多点登录拦截"> <el-form-item label="多点登录拦截">
@ -258,6 +259,24 @@
<el-input v-model="config.aliyunOSS.bucketUrl" /> <el-input v-model="config.aliyunOSS.bucketUrl" />
</el-form-item> </el-form-item>
</template> </template>
<template v-if="config.system.ossType === 'huawei-obs'">
<h2>华为云Obs上传配置</h2>
<el-form-item label="path">
<el-input v-model="config.huaWeiObs.path" />
</el-form-item>
<el-form-item label="bucket">
<el-input v-model="config.huaWeiObs.bucket" />
</el-form-item>
<el-form-item label="endpoint">
<el-input v-model="config.huaWeiObs.endpoint" />
</el-form-item>
<el-form-item label="accessKey">
<el-input v-model="config.huaWeiObs.AccessKey" />
</el-form-item>
<el-form-item label="secretKey">
<el-input v-model="config.huaWeiObs.secretKey" />
</el-form-item>
</template>
</el-collapse-item> </el-collapse-item>
@ -352,6 +371,7 @@ export default {
qiniu: {}, qiniu: {},
tencentCOS: {}, tencentCOS: {},
aliyunOSS: {}, aliyunOSS: {},
huaWeiObs: {},
captcha: {}, captcha: {},
zap: {}, zap: {},
local: {}, local: {},

Loading…
Cancel
Save