mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-29 22:56:39 +08:00
35 lines
714 B
Go
35 lines
714 B
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"one-api/common"
|
|
)
|
|
|
|
func (s *Storage) Upload(ctx context.Context, data []byte, fileName string) string {
|
|
if ctx == nil {
|
|
ctx = context.Background()
|
|
}
|
|
|
|
for driveName, drive := range s.drives {
|
|
if drive == nil {
|
|
continue
|
|
}
|
|
url, err := drive.Upload(data, fileName)
|
|
if err != nil {
|
|
common.LogError(ctx, fmt.Sprintf("%s err: %s", driveName, err.Error()))
|
|
} else {
|
|
return url
|
|
}
|
|
}
|
|
|
|
return ""
|
|
}
|
|
|
|
func Upload(data []byte, fileName string) string {
|
|
//lint:ignore SA1029 reason: 需要使用该类型作为错误处理
|
|
ctx := context.WithValue(context.Background(), common.RequestIdKey, "Upload")
|
|
|
|
return storageDrives.Upload(ctx, data, fileName)
|
|
}
|