package initdb import ( "gorm.io/gorm" "senlinai-agent/backend/internal/models" ) type defaultDatasetSource struct { Key string Name string URL string IconURL string } var defaultDatasetSources = []defaultDatasetSource{ {Key: "buzzing-bloomberg", Name: "彭博社最新报道", URL: "https://bbg.buzzing.cc/feed.json", IconURL: "https://bbg.buzzing.cc/apple-touch-icon.png"}, {Key: "buzzing-tech", Name: "国外科技头条", URL: "https://tech.buzzing.cc/feed.json", IconURL: "https://tech.buzzing.cc/apple-touch-icon.png"}, {Key: "buzzing-finance", Name: "国外财经新闻", URL: "https://finance.buzzing.cc/feed.json", IconURL: "https://finance.buzzing.cc/apple-touch-icon.png"}, {Key: "buzzing-wsj", Name: "华尔街日报热门", URL: "https://wsj.buzzing.cc/feed.json", IconURL: "https://wsj.buzzing.cc/apple-touch-icon.png"}, {Key: "buzzing-product-hunt", Name: "Product Hunt", URL: "https://ph.buzzing.cc/feed.json", IconURL: "https://ph.buzzing.cc/apple-touch-icon.png"}, {Key: "buzzing-devto", Name: "Dev.to", URL: "https://dev.buzzing.cc/feed.json", IconURL: "https://dev.buzzing.cc/apple-touch-icon.png"}, {Key: "rsshub-cls-hot", Name: "财联社-热门", URL: "https://rsshub.ktachibana.party/cls/hot"}, {Key: "rsshub-jin10", Name: "金十数据-快讯", URL: "https://rsshub.ktachibana.party/jin10"}, } // InitDataset inserts the built-in dataset sources when the owner has no sources. func InitDataset(database *gorm.DB, ownerID uint, ownerIdentity string) error { var count int64 if err := database.Model(&models.SaDatasetSource{}). Where("owner_id = ?", ownerID). Count(&count).Error; err != nil { return err } if count > 0 { return nil } for _, definition := range defaultDatasetSources { seedKey := definition.Key if err := database.Create(&models.SaDatasetSource{ OwnerID: ownerID, OwnerIdentity: ownerIdentity, SeedKey: &seedKey, Name: definition.Name, Kind: "rss", URL: definition.URL, IconURL: definition.IconURL, Description: "默认资讯订阅", Enabled: true, }).Error; err != nil { return err } } return nil }