mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-29 22:56:39 +08:00
### 新增环境变量 STORAGE_ALIOSS_ENDPOINT:Endpoint(地域节点),比如`oss-cn-beijing.aliyuncs.com` STORAGE_ALIOSS_BUCKET_NAME:Bucket名称,比如`zerodeng-superai` STORAGE_ALIOSS_ACCESS_KEY_ID:阿里授权KEY,在RAM获取 STORAGE_ALIOSS_ACCESS_KEY_SECRET:阿里授权SECRET,在RAM获取
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package storage
|
|
|
|
import (
|
|
"one-api/common/storage/drives"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Storage struct {
|
|
drives map[string]StorageDrive
|
|
}
|
|
|
|
func InitStorage() {
|
|
InitImgurStorage()
|
|
InitSMStorage()
|
|
InitALIOSSStorage()
|
|
}
|
|
|
|
func InitALIOSSStorage() {
|
|
endpoint := viper.GetString("storage.alioss.endpoint")
|
|
if endpoint == "" {
|
|
return
|
|
}
|
|
accessKeyId := viper.GetString("storage.alioss.accessKeyId")
|
|
if accessKeyId == "" {
|
|
return
|
|
}
|
|
accessKeySecret := viper.GetString("storage.alioss.accessKeySecret")
|
|
if accessKeySecret == "" {
|
|
return
|
|
}
|
|
bucketName := viper.GetString("storage.alioss.bucketName")
|
|
if bucketName == "" {
|
|
|
|
return
|
|
}
|
|
|
|
aliUpload := drives.NewAliOSSUpload(endpoint, accessKeyId, accessKeySecret, bucketName)
|
|
AddStorageDrive(aliUpload)
|
|
}
|
|
|
|
func InitSMStorage() {
|
|
smSecret := viper.GetString("storage.smms.secret")
|
|
if smSecret == "" {
|
|
return
|
|
}
|
|
|
|
smUpload := drives.NewSMUpload(smSecret)
|
|
AddStorageDrive(smUpload)
|
|
}
|
|
|
|
func InitImgurStorage() {
|
|
imgurClientId := viper.GetString("storage.imgur.client_id")
|
|
if imgurClientId == "" {
|
|
return
|
|
}
|
|
|
|
imgurUpload := drives.NewImgurUpload(imgurClientId)
|
|
AddStorageDrive(imgurUpload)
|
|
}
|