Support oss domain.

This commit is contained in:
Yang Luo 2021-04-27 19:00:34 +08:00
parent 3437885723
commit 6002395d12
2 changed files with 12 additions and 6 deletions

View File

@ -1,5 +1,6 @@
[provider] [provider]
endpoint = endpoint
accessId = id accessId = id
accessKey = key accessKey = key
bucket = bucket domain = domain
endpoint = endpoint bucket = bucket

View File

@ -16,6 +16,7 @@ package object
import ( import (
"bytes" "bytes"
"fmt"
awss3 "github.com/aws/aws-sdk-go/service/s3" awss3 "github.com/aws/aws-sdk-go/service/s3"
"github.com/qor/oss" "github.com/qor/oss"
@ -26,12 +27,14 @@ import (
) )
var storage oss.StorageInterface var storage oss.StorageInterface
var domain string
func AliyunInit(section *ini.Section) string { func AliyunInit(section *ini.Section) string {
endpoint := section.Key("endpoint").String()
accessId := section.Key("accessId").String() accessId := section.Key("accessId").String()
accessKey := section.Key("accessKey").String() accessKey := section.Key("accessKey").String()
domain = section.Key("domain").String()
bucket := section.Key("bucket").String() bucket := section.Key("bucket").String()
endpoint := section.Key("endpoint").String()
if accessId == "" || accessKey == "" || bucket == "" || endpoint == "" { if accessId == "" || accessKey == "" || bucket == "" || endpoint == "" {
return "Config oss.conf wrong" return "Config oss.conf wrong"
} }
@ -45,11 +48,12 @@ func AliyunInit(section *ini.Section) string {
} }
//func QiniuInit(section *ini.Section) string { //func QiniuInit(section *ini.Section) string {
// endpoint := section.Key("endpoint").String()
// accessId := section.Key("accessId").String() // accessId := section.Key("accessId").String()
// accessKey := section.Key("accessKey").String() // accessKey := section.Key("accessKey").String()
// domain = section.Key("domain").String()
// bucket := section.Key("bucket").String() // bucket := section.Key("bucket").String()
// region := section.Key("region").String() // region := section.Key("region").String()
// endpoint := section.Key("endpoint").String()
// if accessId == "" || accessKey == "" || bucket == "" || endpoint == "" || region == "" { // if accessId == "" || accessKey == "" || bucket == "" || endpoint == "" || region == "" {
// return "Config oss.conf wrong" // return "Config oss.conf wrong"
// } // }
@ -64,11 +68,12 @@ func AliyunInit(section *ini.Section) string {
//} //}
func Awss3Init(section *ini.Section) string { func Awss3Init(section *ini.Section) string {
endpoint := section.Key("endpoint").String()
accessId := section.Key("accessId").String() accessId := section.Key("accessId").String()
accessKey := section.Key("accessKey").String() accessKey := section.Key("accessKey").String()
domain = section.Key("domain").String()
bucket := section.Key("bucket").String() bucket := section.Key("bucket").String()
region := section.Key("region").String() region := section.Key("region").String()
endpoint := section.Key("endpoint").String()
if accessId == "" || accessKey == "" || bucket == "" || endpoint == "" || region == "" { if accessId == "" || accessKey == "" || bucket == "" || endpoint == "" || region == "" {
return "Config oss.conf wrong" return "Config oss.conf wrong"
} }
@ -120,5 +125,5 @@ func UploadAvatar(username string, avatar []byte) string {
} }
func GetAvatarPath() string { func GetAvatarPath() string {
return "https://" + storage.GetEndpoint() + "/casdoor/avatar/" return fmt.Sprintf("https://%s/casdoor/avatar/", domain)
} }