Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix: rss route (#2008)

boojack9138ab80952e
diff --git a/api/v1/jwt.go b/api/v1/jwt.go
index 0a4bc18ad..83db1986f 100644
--- a/api/v1/jwt.go
+++ b/api/v1/jwt.go
@@ -82,7 +82,7 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
}
// Skip validation for server status endpoints.
- if util.HasPrefixes(path, "/api/v1/ping", "/api/v1/idp", "/api/v1/status", "/api/v1/user/:id") && method == http.MethodGet {
+ if util.HasPrefixes(path, "/api/v1/ping", "/api/v1/idp", "/api/v1/status", "/api/v1/user") && path != "/api/v1/user/me" && method == http.MethodGet {
return next(c)
}
diff --git a/api/v1/rss.go b/api/v1/rss.go
index 7d130cf24..3e6e711e4 100644
--- a/api/v1/rss.go
+++ b/api/v1/rss.go
@@ -78,6 +78,42 @@ 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) {
diff --git a/api/v1/user.go b/api/v1/user.go
index d6def764c..b84341380 100644
--- a/api/v1/user.go
+++ b/api/v1/user.go
@@ -262,7 +262,6 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
g.GET("/user/:username", 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)
diff --git a/web/vite.config.ts b/web/vite.config.ts
index 003f0479e..8258abdd3 100644
--- a/web/vite.config.ts
+++ b/web/vite.config.ts
@@ -23,7 +23,7 @@ export default defineConfig({
target: devProxyServer,
changeOrigin: true,
},
- "^/u/\\d*/rss.xml": {
+ "^/u/.+/rss.xml": {
target: devProxyServer,
changeOrigin: true,
},