2023-06-17 16:25:46 +03:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/usememos/memos/server/profile"
|
|
|
|
"github.com/usememos/memos/store"
|
|
|
|
)
|
|
|
|
|
|
|
|
type APIV1Service struct {
|
|
|
|
Secret string
|
|
|
|
Profile *profile.Profile
|
|
|
|
Store *store.Store
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAPIV1Service(secret string, profile *profile.Profile, store *store.Store) *APIV1Service {
|
|
|
|
return &APIV1Service{
|
|
|
|
Secret: secret,
|
|
|
|
Profile: profile,
|
|
|
|
Store: store,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-30 19:03:28 +03:00
|
|
|
func (s *APIV1Service) Register(rootGroup *echo.Group) {
|
2023-07-06 17:53:38 +03:00
|
|
|
// Register RSS routes.
|
|
|
|
s.registerRSSRoutes(rootGroup)
|
|
|
|
|
|
|
|
// Register API v1 routes.
|
2023-06-30 19:03:28 +03:00
|
|
|
apiV1Group := rootGroup.Group("/api/v1")
|
|
|
|
apiV1Group.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
|
|
return JWTMiddleware(s, next, s.Secret)
|
|
|
|
})
|
2023-07-02 13:56:25 +03:00
|
|
|
s.registerSystemRoutes(apiV1Group)
|
|
|
|
s.registerSystemSettingRoutes(apiV1Group)
|
2023-06-30 19:03:28 +03:00
|
|
|
s.registerAuthRoutes(apiV1Group)
|
2023-06-17 17:35:17 +03:00
|
|
|
s.registerIdentityProviderRoutes(apiV1Group)
|
2023-07-02 13:56:25 +03:00
|
|
|
s.registerUserRoutes(apiV1Group)
|
|
|
|
s.registerUserSettingRoutes(apiV1Group)
|
|
|
|
s.registerTagRoutes(apiV1Group)
|
2023-07-04 05:05:57 +03:00
|
|
|
s.registerStorageRoutes(apiV1Group)
|
2023-07-05 19:01:40 +03:00
|
|
|
s.registerResourceRoutes(apiV1Group)
|
2023-07-06 16:56:42 +03:00
|
|
|
s.registerMemoRoutes(apiV1Group)
|
|
|
|
s.registerMemoOrganizerRoutes(apiV1Group)
|
|
|
|
s.registerMemoResourceRoutes(apiV1Group)
|
|
|
|
s.registerMemoRelationRoutes(apiV1Group)
|
2023-07-05 19:01:40 +03:00
|
|
|
|
2023-07-06 17:53:38 +03:00
|
|
|
// Register public routes.
|
2023-07-05 19:01:40 +03:00
|
|
|
publicGroup := rootGroup.Group("/o")
|
|
|
|
publicGroup.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
|
|
return JWTMiddleware(s, next, s.Secret)
|
|
|
|
})
|
2023-07-06 16:56:42 +03:00
|
|
|
s.registerGetterPublicRoutes(publicGroup)
|
2023-07-05 19:01:40 +03:00
|
|
|
s.registerResourcePublicRoutes(publicGroup)
|
2023-06-17 16:25:46 +03:00
|
|
|
}
|