diff --git a/.gitignore b/.gitignore index 4209a5f..4cc6308 100644 --- a/.gitignore +++ b/.gitignore @@ -182,4 +182,5 @@ yarn-error.log web/admin/.idea web/admin/dist .aider* -.run \ No newline at end of file +.run +main diff --git a/internal/craft/entry.go b/internal/craft/entry.go index 1ed14b3..2bf9dd0 100644 --- a/internal/craft/entry.go +++ b/internal/craft/entry.go @@ -4,11 +4,12 @@ import ( "FeedCraft/internal/dao" "FeedCraft/internal/util" "fmt" + "net/http" + "github.com/gin-gonic/gin" "github.com/samber/lo" "github.com/sirupsen/logrus" "gorm.io/gorm" - "net/http" ) func GetSysCraftTemplateDict() map[string]CraftTemplate { @@ -122,7 +123,6 @@ func Entry(c *gin.Context) { return } CommonCraftHandlerUsingCraftOptionList(c, craftOptionList) - return } const MaxCallDepth = 5 diff --git a/internal/craft/fulltext_plus.go b/internal/craft/fulltext_plus.go index e970d31..e6171dc 100644 --- a/internal/craft/fulltext_plus.go +++ b/internal/craft/fulltext_plus.go @@ -2,14 +2,15 @@ package craft import ( "FeedCraft/internal/util" - "github.com/go-resty/resty/v2" - "github.com/go-shiori/go-readability" - "github.com/gorilla/feeds" - "github.com/sirupsen/logrus" "log" "net/url" "strings" "time" + + "github.com/go-resty/resty/v2" + "github.com/go-shiori/go-readability" + "github.com/gorilla/feeds" + "github.com/sirupsen/logrus" ) //func getRenderedHTML(websiteUrl string) (string, error) { @@ -96,7 +97,6 @@ func getRenderedHTML2(websiteUrl string, timeout time.Duration) (string, error) article, err := readability.FromReader(strings.NewReader(response.String()), parseUrl) return article.Content, err - return response.String(), nil } func GetFulltextPlusCraftOptions() []CraftOption { diff --git a/internal/craft/keyword.go b/internal/craft/keyword.go index b9120d0..590b832 100644 --- a/internal/craft/keyword.go +++ b/internal/craft/keyword.go @@ -1,9 +1,10 @@ package craft import ( + "strings" + "github.com/gorilla/feeds" "github.com/sirupsen/logrus" - "strings" ) type KeywordFilterMode string @@ -54,12 +55,10 @@ func optionKeyword(mode KeywordFilterMode, matchScope KeywordMatchScope, keyword if matched { filtered = append(filtered, feedItem) } - break case KeywordExcludeMode: if !matched { filtered = append(filtered, feedItem) } - break default: logrus.Warnf("unknown mode %s", mode) } @@ -83,7 +82,7 @@ var keywordCraftParamTmpl = []ParamTemplate{ } func keywordCraftLoadParams(m map[string]string) []CraftOption { - modeStr, _ := m["mode"] + modeStr := m["mode"] mode := KeywordIncludeMode if modeStr == string(KeywordIncludeMode) { mode = KeywordIncludeMode @@ -92,7 +91,7 @@ func keywordCraftLoadParams(m map[string]string) []CraftOption { } else { logrus.Warnf("unknown mode str %s", modeStr) } - scopeStr, _ := m["scope"] + scopeStr := m["scope"] scope := KeywordMatchAll if scopeStr == string(KeywordMatchTitle) { scope = KeywordMatchTitle @@ -103,7 +102,7 @@ func keywordCraftLoadParams(m map[string]string) []CraftOption { } else { logrus.Warnf("unknown scope str %s", scopeStr) } - keywordStr, _ := m["keywords"] + keywordStr := m["keywords"] keywordList := strings.Split(keywordStr, ",") return GetKeywordOption(mode, scope, keywordList) } diff --git a/internal/dao/migrate.go b/internal/dao/migrate.go index 6d59415..dfaf315 100644 --- a/internal/dao/migrate.go +++ b/internal/dao/migrate.go @@ -2,6 +2,7 @@ package dao import ( "FeedCraft/internal/util" + "github.com/sirupsen/logrus" "gorm.io/gorm" ) @@ -27,6 +28,12 @@ func MigrateDatabases() { var defaultAdminUsername = "admin" var defaultPassword = "adminadmin" // default defaultPassword string +var defaultAdminUser = User{ + Username: defaultAdminUsername, + NickName: "Admin", + Email: "admin@example.com", +} + func createAdminUser(db *gorm.DB) { md5Password := util.GetMD5Hash(defaultPassword) @@ -39,12 +46,7 @@ func createAdminUser(db *gorm.DB) { } // 创建 admin 用户 - adminUser := &User{ - Username: defaultAdminUsername, - NickName: "Admin", - Email: "admin@example.com", - } - if err := CreateUser(db, adminUser, md5Password); err != nil { + if err := CreateUser(db, &defaultAdminUser, md5Password); err != nil { logrus.Error("failed to create admin user:", err) return } @@ -53,9 +55,9 @@ func createAdminUser(db *gorm.DB) { } // 重置 admin 密码 -func ResetAdminPassword()error { +func ResetAdminPassword() error { logrus.Info("resetting admin password...") db := util.GetDatabase() md5Password := util.GetMD5Hash(defaultPassword) - return db.Model(&User{}).Where("username = ?", defaultAdminUsername).Update("password", md5Password).Error + return UpdateUserPassword(db, &defaultAdminUser, md5Password) }