Skip to content

Commit

Permalink
fix(rss): host参数错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinvic authored Jan 27, 2025
1 parent f262bcd commit 348b1ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions backend/handler/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func NewRssHandler(injector do.Injector) *RssHandler {
}

func (r RssHandler) GetRss(c echo.Context) error {
rss, err := r.generateRss(c.Request().Host)
frontendHost := c.QueryParam("frontend_host")
if frontendHost == "" {
frontendHost = c.Request().Host // 如果未传递,则使用后端默认的 Host
}
rss, err := r.generateRss(frontendHost)
if err != nil {
return FailRespWithMsg(c, Fail, "RSS生成失败")
}
Expand Down Expand Up @@ -95,7 +99,7 @@ func generateFeed(memos []db.Memo, sysConfigVO *vo.FullSysConfigVO, user *db.Use
feed.Items = append(feed.Items, &feeds.Item{
Title: fmt.Sprintf("Memo #%d", memo.Id),
Link: &feeds.Link{Href: fmt.Sprintf("%s/memo/%d", host, memo.Id)},
Description: parseMarkdownToHtml(getContentWithExt(memo)),
Description: parseMarkdownToHtml(getContentWithExt(memo, host)),
Author: &feeds.Author{Name: memo.User.Nickname},
Created: *memo.CreatedAt,
Updated: *memo.UpdatedAt,
Expand Down Expand Up @@ -126,7 +130,7 @@ func parseMarkdownToHtml(md string) string {
return string(cleanHTML)
}

func getContentWithExt(memo db.Memo) string {
func getContentWithExt(memo db.Memo, host string) string {
content := memo.Content

// 处理链接
Expand All @@ -138,6 +142,9 @@ func getContentWithExt(memo db.Memo) string {
if memo.Imgs != "" {
imgs := strings.Split(memo.Imgs, ",")
for _, img := range imgs {
if img[:7] == "/upload" {
img = host + img
}
content += fmt.Sprintf("\n\n![%s](%s)", img, img)
}
}
Expand Down Expand Up @@ -224,6 +231,9 @@ func getContentWithExt(memo db.Memo) string {
title = "Youtube视频"
}
url = ext.Video.Value
if ext.Video.Type == "online" && url[:7] == "/upload" {
url = host + url
}
content += fmt.Sprintf("\n\n[%s](%s)", title, url)
}

Expand Down
2 changes: 1 addition & 1 deletion front/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ useHead({
rel: 'alternate',
type: 'application/rss+xml',
title: '我的 RSS 订阅',
href: sysConfigVO.rss || '/rss',
href: sysConfigVO.rss || `/rss?frontend_host=${encodeURIComponent(window.location.origin)}`,
},
],
style: [
Expand Down

0 comments on commit 348b1ef

Please sign in to comment.