Skip to content

Commit

Permalink
chore: fix rss route (#2010)
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Jul 22, 2023
1 parent 02881ce commit 2dcc77c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 37 deletions.
36 changes: 0 additions & 36 deletions api/v1/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,42 +78,6 @@ func (s *APIV1Service) registerRSSRoutes(g *echo.Group) {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationXMLCharsetUTF8)
return c.String(http.StatusOK, rss)
})

g.GET("/u/:username/rss.xml", func(c echo.Context) error {
ctx := c.Request().Context()
username := c.Param("username")
user, err := s.Store.GetUser(ctx, &store.FindUser{Username: &username})
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user").SetInternal(err)
}
if user == nil {
return echo.NewHTTPError(http.StatusNotFound, "User not found")
}

systemCustomizedProfile, err := s.getSystemCustomizedProfile(ctx)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get system customized profile").SetInternal(err)
}

normalStatus := store.Normal
memoFind := store.FindMemo{
CreatorID: &user.ID,
RowStatus: &normalStatus,
VisibilityList: []store.Visibility{store.Public},
}
memoList, err := s.Store.ListMemos(ctx, &memoFind)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find memo list").SetInternal(err)
}

baseURL := c.Scheme() + "://" + c.Request().Host
rss, err := s.generateRSSFromMemoList(ctx, memoList, baseURL, systemCustomizedProfile)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to generate rss").SetInternal(err)
}
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationXMLCharsetUTF8)
return c.String(http.StatusOK, rss)
})
}

func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*store.Memo, baseURL string, profile *CustomizedProfile) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/UserBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const UserBanner = () => {
</button>
<a
className="w-full px-3 truncate text-left leading-10 cursor-pointer rounded flex flex-row justify-start items-center dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-zinc-800"
href={`/u/${user?.username}/rss.xml`}
href={`/u/${user?.id}/rss.xml`}
target="_blank"
>
<Icon.Rss className="w-5 h-auto mr-2 opacity-80" /> RSS
Expand Down

0 comments on commit 2dcc77c

Please sign in to comment.