fix(datasource): harden RSS connector and editor UX after review

Scope auth headers to feed fetches, use feed-scoped external IDs and
content-based incremental fingerprints, tolerate partial feed failures,
store feed URLs in settings, and fix credential configured detection.
This commit is contained in:
wizardchen
2026-06-23 15:45:47 +08:00
committed by lyingbug
parent e40ad802d7
commit 3cb0e906a7
12 changed files with 430 additions and 96 deletions
+36
View File
@@ -3,6 +3,7 @@ package types
import (
"encoding/json"
"log"
"strings"
"time"
"github.com/Tencent/WeKnora/internal/utils"
@@ -223,6 +224,41 @@ func (d DataSourceConfig) HasCredentials() bool {
return len(d.Credentials) > 0
}
// HasConfiguredCredentials reports whether user-facing secret credentials are
// stored. RSS feed URLs are non-secret configuration (settings); only
// auth_headers count as credentials for that connector.
func (d DataSourceConfig) HasConfiguredCredentials(connectorType string) bool {
if len(d.Credentials) == 0 {
return false
}
switch connectorType {
case ConnectorTypeRSS:
raw, ok := d.Credentials["auth_headers"]
if !ok {
return false
}
s, ok := raw.(string)
return ok && strings.TrimSpace(s) != ""
default:
return len(d.Credentials) > 0
}
}
// StripNonSecretCredentials removes non-secret values mistakenly stored in the
// credentials map before persistence.
func (d *DataSourceConfig) StripNonSecretCredentials(connectorType string) {
if d == nil || d.Credentials == nil {
return
}
switch connectorType {
case ConnectorTypeRSS:
delete(d.Credentials, "feed_urls")
if len(d.Credentials) == 0 {
d.Credentials = nil
}
}
}
// Resource represents a syncable resource (document, folder, space) from external system
type Resource struct {
// Unique identifier in the external system
+25
View File
@@ -116,3 +116,28 @@ func TestDataSource_ParseConfig_MissingKeyDegradesGracefully(t *testing.T) {
assert.False(t, parsed.HasCredentials() && parsed.Credentials["token"] != "",
"HasCredentials should not report a usable credential when decrypt failed")
}
func TestDataSourceConfig_HasConfiguredCredentials_RSS(t *testing.T) {
feedOnly := DataSourceConfig{
Credentials: map[string]interface{}{
"feed_urls": "https://example.com/feed.xml",
},
}
assert.False(t, feedOnly.HasConfiguredCredentials(ConnectorTypeRSS))
assert.True(t, feedOnly.HasCredentials())
withAuth := DataSourceConfig{
Credentials: map[string]interface{}{
"feed_urls": "https://example.com/feed.xml",
"auth_headers": "Authorization: Bearer x",
},
}
assert.True(t, withAuth.HasConfiguredCredentials(ConnectorTypeRSS))
t.Run("strip feed_urls", func(t *testing.T) {
cfg := feedOnly
cfg.StripNonSecretCredentials(ConnectorTypeRSS)
assert.Nil(t, cfg.Credentials)
assert.False(t, cfg.HasCredentials())
})
}