Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
Merge branch 'main' into feat_oss
peterchan20208b9094f87c8b
diff --cc internal/handler/system.goindex 51590ecbe,e1dbd3238..91c2b1f31--- a/internal/handler/system.go+++ b/internal/handler/system.go@@@ -955,51 -960,26 +979,73 @@@ func (h *SystemHandler) checkS3(c *gin.c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: true, Message: fmt.Sprintf("连接成功,Bucket「%s」已确认存在", cfg.BucketName)}})}+func (h *SystemHandler) checkOSS(c *gin.Context, ctx context.Context, cfg *types.OSSEngineConfig) {+ if cfg == nil {+ c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: false, Message: "未提供 OSS 配置"}})+ return+ }++ endpoint, accessKey, secretKey := cfg.Endpoint, cfg.AccessKey, cfg.SecretKey+ if endpoint == "" || accessKey == "" || secretKey == "" || cfg.BucketName == "" {+ c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: false, Message: "Endpoint、Access Key、Secret Key、Bucket Name 不能为空"}})+ return+ }++ // Strip URL scheme before SSRF check — OSS endpoint may include http:// or https://+ ssrfEndpoint := strings.TrimPrefix(strings.TrimPrefix(endpoint, "https://"), "http://")+ if blocked, reason := isBlockedStorageEndpoint(ssrfEndpoint); blocked {+ logger.Warnf(ctx, "Storage check: OSS endpoint blocked by SSRF protection", "endpoint", endpoint)+ c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: false, Message: reason}})+ return+ }+ if !ossFieldPattern.MatchString(cfg.Region) {+ c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: false, Message: "Region 格式不正确,仅允许字母、数字、点、连字符"}})+ return+ }+ if !ossFieldPattern.MatchString(cfg.BucketName) {+ c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: false, Message: "Bucket 名称格式不正确,仅允许字母、数字、点、连字符"}})+ return+ }++ err := file.CheckOssConnectivity(ctx, endpoint, cfg.Region, accessKey, secretKey, cfg.BucketName)+ if err != nil {+ errMsg := err.Error()+ if strings.Contains(errMsg, "403") || strings.Contains(errMsg, "AccessDenied") {+ logger.Errorf(ctx, "Storage check: OSS auth failed", "endpoint", endpoint, "bucket", cfg.BucketName)+ c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: false, Message: "认证失败,请检查 Access Key / Secret Key 是否正确"}})+ return+ }+ if strings.Contains(errMsg, "404") || strings.Contains(errMsg, "NoSuchBucket") {+ logger.Errorf(ctx, "Storage check: OSS bucket not found", "bucket", cfg.BucketName)+ c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: false, Message: fmt.Sprintf("Bucket「%s」不存在", cfg.BucketName)}})+ return+ }+ logger.Errorf(ctx, "Storage check: OSS connectivity failed", "endpoint", endpoint, "bucket", cfg.BucketName, "error", err)+ c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: false, Message: fmt.Sprintf("OSS 连通性检测失败: %s", sanitizeStorageCheckError(err))}})+ return+ }++ c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: true, Message: fmt.Sprintf("连接成功,Bucket「%s」已确认存在", cfg.BucketName)}})+ func (h *SystemHandler) ResolveDocumentReader(ctx context.Context, addr string) interfaces.DocumentReader {+ if addr == "" {+ return h.documentReader+ }++ if service.IsWeKnoraCloudDocReaderAddr(addr) {+ creds := h.tenantSvc.GetDocreaderCredentials(ctx)+ if creds == nil {+ return nil+ }+ reader, err := docparser.NewWeKnoraCloudSignedDocumentReader(addr, creds.AppID, creds.APIKey)+ if err != nil {+ return nil+ }+ return reader+ }++ reader, err := docparser.NewHTTPDocumentReader(addr)+ if err != nil || reader == nil {+ return reader+ }+ return reader}