fix(infra): support configuring the HTTP schema of storage upload in … (#450)
This commit is contained in:
parent
6f305e33aa
commit
568819b8e5
|
|
@ -20,9 +20,10 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
|
||||||
"github.com/getkin/kin-openapi/openapi3"
|
"github.com/getkin/kin-openapi/openapi3"
|
||||||
|
|
||||||
|
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||||
|
|
||||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||||
common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop_common"
|
common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop_common"
|
||||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
|
|
@ -33,9 +35,7 @@ import (
|
||||||
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
||||||
"github.com/coze-dev/coze-studio/backend/infra/impl/storage/proxy"
|
"github.com/coze-dev/coze-studio/backend/infra/impl/storage/proxy"
|
||||||
"github.com/coze-dev/coze-studio/backend/pkg/ctxcache"
|
"github.com/coze-dev/coze-studio/backend/pkg/ctxcache"
|
||||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
|
||||||
"github.com/coze-dev/coze-studio/backend/types/consts"
|
"github.com/coze-dev/coze-studio/backend/types/consts"
|
||||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type minioClient struct {
|
type minioClient struct {
|
||||||
|
|
@ -231,9 +231,9 @@ func (m *minioClient) GetServerID() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *minioClient) GetUploadAuth(ctx context.Context, opt ...imagex.UploadAuthOpt) (*imagex.SecurityToken, error) {
|
func (m *minioClient) GetUploadAuth(ctx context.Context, opt ...imagex.UploadAuthOpt) (*imagex.SecurityToken, error) {
|
||||||
scheme, ok := ctxcache.Get[string](ctx, consts.RequestSchemeKeyInCtx)
|
scheme := strings.ToLower(os.Getenv(consts.StorageUploadHTTPScheme))
|
||||||
if !ok {
|
if scheme == "" {
|
||||||
return nil, errorx.New(errno.ErrUploadHostSchemaNotExistCode)
|
scheme = "http"
|
||||||
}
|
}
|
||||||
return &imagex.SecurityToken{
|
return &imagex.SecurityToken{
|
||||||
AccessKeyID: "",
|
AccessKeyID: "",
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/volcengine/ve-tos-golang-sdk/v2/tos"
|
"github.com/volcengine/ve-tos-golang-sdk/v2/tos"
|
||||||
|
|
@ -31,11 +33,9 @@ import (
|
||||||
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
||||||
"github.com/coze-dev/coze-studio/backend/infra/impl/storage/proxy"
|
"github.com/coze-dev/coze-studio/backend/infra/impl/storage/proxy"
|
||||||
"github.com/coze-dev/coze-studio/backend/pkg/ctxcache"
|
"github.com/coze-dev/coze-studio/backend/pkg/ctxcache"
|
||||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
|
||||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
|
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
|
||||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||||
"github.com/coze-dev/coze-studio/backend/types/consts"
|
"github.com/coze-dev/coze-studio/backend/types/consts"
|
||||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type tosClient struct {
|
type tosClient struct {
|
||||||
|
|
@ -232,9 +232,9 @@ func (t *tosClient) GetServerID() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tosClient) GetUploadAuth(ctx context.Context, opt ...imagex.UploadAuthOpt) (*imagex.SecurityToken, error) {
|
func (t *tosClient) GetUploadAuth(ctx context.Context, opt ...imagex.UploadAuthOpt) (*imagex.SecurityToken, error) {
|
||||||
scheme, ok := ctxcache.Get[string](ctx, consts.RequestSchemeKeyInCtx)
|
scheme := strings.ToLower(os.Getenv(consts.StorageUploadHTTPScheme))
|
||||||
if !ok {
|
if scheme == "" {
|
||||||
return nil, errorx.New(errno.ErrUploadHostSchemaNotExistCode)
|
scheme = "http"
|
||||||
}
|
}
|
||||||
return &imagex.SecurityToken{
|
return &imagex.SecurityToken{
|
||||||
AccessKeyID: "",
|
AccessKeyID: "",
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ const (
|
||||||
FileUploadComponentType = "FILE_UPLOAD_COMPONENT_TYPE"
|
FileUploadComponentType = "FILE_UPLOAD_COMPONENT_TYPE"
|
||||||
FileUploadComponentTypeImagex = "imagex"
|
FileUploadComponentTypeImagex = "imagex"
|
||||||
FileUploadComponentTypeStorage = "storage"
|
FileUploadComponentTypeStorage = "storage"
|
||||||
|
StorageUploadHTTPScheme = "STORAGE_UPLOAD_HTTP_SCHEME"
|
||||||
|
|
||||||
StorageType = "STORAGE_TYPE"
|
StorageType = "STORAGE_TYPE"
|
||||||
MinIOAK = "MINIO_AK"
|
MinIOAK = "MINIO_AK"
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ export REDIS_PASSWORD=""
|
||||||
# if imagex, you must finish the configuration of <VolcEngine ImageX>
|
# if imagex, you must finish the configuration of <VolcEngine ImageX>
|
||||||
export FILE_UPLOAD_COMPONENT_TYPE="storage"
|
export FILE_UPLOAD_COMPONENT_TYPE="storage"
|
||||||
|
|
||||||
|
|
||||||
# VolcEngine ImageX
|
# VolcEngine ImageX
|
||||||
export VE_IMAGEX_AK=""
|
export VE_IMAGEX_AK=""
|
||||||
export VE_IMAGEX_SK=""
|
export VE_IMAGEX_SK=""
|
||||||
|
|
@ -40,6 +41,7 @@ export VE_IMAGEX_UPLOAD_HOST="https://imagex.volcengineapi.com"
|
||||||
|
|
||||||
# Storage component
|
# Storage component
|
||||||
export STORAGE_TYPE="minio" # minio / tos / s3
|
export STORAGE_TYPE="minio" # minio / tos / s3
|
||||||
|
export STORAGE_UPLOAD_HTTP_SCHEME="http" # http / https. If coze studio website is https, you must set it to https
|
||||||
export STORAGE_BUCKET="opencoze"
|
export STORAGE_BUCKET="opencoze"
|
||||||
# MiniIO
|
# MiniIO
|
||||||
export MINIO_ROOT_USER=minioadmin
|
export MINIO_ROOT_USER=minioadmin
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ export REDIS_PASSWORD=""
|
||||||
# if imagex, you must finish the configuration of <VolcEngine ImageX>
|
# if imagex, you must finish the configuration of <VolcEngine ImageX>
|
||||||
export FILE_UPLOAD_COMPONENT_TYPE="storage"
|
export FILE_UPLOAD_COMPONENT_TYPE="storage"
|
||||||
|
|
||||||
|
|
||||||
# VolcEngine ImageX
|
# VolcEngine ImageX
|
||||||
export VE_IMAGEX_AK=""
|
export VE_IMAGEX_AK=""
|
||||||
export VE_IMAGEX_SK=""
|
export VE_IMAGEX_SK=""
|
||||||
|
|
@ -40,6 +41,7 @@ export VE_IMAGEX_UPLOAD_HOST="https://imagex.volcengineapi.com"
|
||||||
|
|
||||||
# Storage component
|
# Storage component
|
||||||
export STORAGE_TYPE="minio" # minio / tos / s3
|
export STORAGE_TYPE="minio" # minio / tos / s3
|
||||||
|
export STORAGE_UPLOAD_HTTP_SCHEME="http" # http / https. If coze studio website is https, you must set it to https
|
||||||
export STORAGE_BUCKET="opencoze"
|
export STORAGE_BUCKET="opencoze"
|
||||||
# MiniIO
|
# MiniIO
|
||||||
export MINIO_ROOT_USER=minioadmin
|
export MINIO_ROOT_USER=minioadmin
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue