fix(storage): add S3 provider scheme support to frontend and backend allowlists
The S3 storage adapter (s3.go) was added in e309e0b but the provider
scheme integration was incomplete — ParseProviderScheme() and frontend
security.ts were not updated, causing s3:// URLs to fail in the /files
proxy, VLM image processing, and frontend rendering.
Additionally, S3-compatible services (MinIO, Ceph, etc.) require
path-style addressing (endpoint/bucket/key) but the SDK client only
used virtual-hosted style. The deprecated WithEndpointResolver API
is replaced with BaseEndpoint, and path-style is auto-enabled for
non-AWS endpoints (detected by amazonaws.com in the URL).
Changes:
- types/knowledgebase.go: add "s3" to ParseProviderScheme()
- file/s3.go: auto path-style for S3-compatible endpoints + replace
deprecated WithEndpointResolver with BaseEndpoint
- frontend/security.ts: add s3 to 5 provider scheme allowlists
- knowledgebase_test.go: add ParseProviderScheme + InferStorage tests
- s3_test.go: add path-style detection + parseS3FilePath tests
This commit is contained in:
@@ -264,7 +264,7 @@ func InferStorageFromFilePath(filePath string) string {
|
||||
// e.g. "minio://bucket/key" → "minio", "local://tenant/file.pdf" → "local"
|
||||
// Returns "" if the path does not use a known provider scheme.
|
||||
func ParseProviderScheme(filePath string) string {
|
||||
for _, provider := range []string{"local", "minio", "cos", "tos"} {
|
||||
for _, provider := range []string{"local", "minio", "cos", "tos", "s3"} {
|
||||
if strings.HasPrefix(filePath, provider+"://") {
|
||||
return provider
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package types
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseProviderScheme(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{"local://tenant/file.pdf", "local"},
|
||||
{"minio://bucket/key", "minio"},
|
||||
{"cos://bucket/key", "cos"},
|
||||
{"tos://bucket/key", "tos"},
|
||||
{"s3://bucket/key", "s3"},
|
||||
{"s3://my-bucket/weknora/123/exports/abc.png", "s3"},
|
||||
{"https://example.com/img.png", ""},
|
||||
{"http://localhost:9000/bucket/key", ""},
|
||||
{"/data/files/images/abc.png", ""},
|
||||
{"", ""},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
got := ParseProviderScheme(tt.input)
|
||||
if got != tt.want {
|
||||
t.Errorf("ParseProviderScheme(%q) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferStorageFromFilePath(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{"local://tenant/file.pdf", "local"},
|
||||
{"minio://bucket/key", "minio"},
|
||||
{"cos://bucket/key", "cos"},
|
||||
{"tos://bucket/key", "tos"},
|
||||
{"s3://bucket/key", "s3"},
|
||||
{"https://my-bucket.cos.ap-guangzhou.myqcloud.com/key", "cos"},
|
||||
{"https://example.com/img.png", ""},
|
||||
{"", ""},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
got := InferStorageFromFilePath(tt.input)
|
||||
if got != tt.want {
|
||||
t.Errorf("InferStorageFromFilePath(%q) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user