奇淼(piexlmax
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 162 additions and 51 deletions
-
10server/config.docker.yaml
-
10server/config.yaml
-
2server/config/config.go
-
32server/config/oss.go
-
10server/config/oss_aliyun.go
-
9server/config/oss_huawei.go
-
5server/config/oss_local.go
-
11server/config/oss_qiniu.go
-
10server/config/oss_tencent.go
-
1server/go.mod
-
2server/go.sum
-
65server/utils/upload/obs.go
-
20server/utils/upload/upload.go
-
20web/src/view/systemTools/system/system.vue
@ -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"` |
|||
} |
@ -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"` |
|||
} |
@ -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"` |
|||
} |
@ -0,0 +1,5 @@ |
|||
package config |
|||
|
|||
type Local struct { |
|||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件路径
|
|||
} |
@ -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上传加速
|
|||
} |
@ -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"` |
|||
} |
@ -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 |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue