mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-18 21:19:44 +00:00
chore: update workspace api
This commit is contained in:
parent
a27457c4d3
commit
ff963e36d7
@ -84,7 +84,7 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
|
|||||||
token := findAccessToken(c)
|
token := findAccessToken(c)
|
||||||
if token == "" {
|
if token == "" {
|
||||||
// When the request is not authenticated, we allow the user to access the shortcut endpoints for those public shortcuts.
|
// When the request is not authenticated, we allow the user to access the shortcut endpoints for those public shortcuts.
|
||||||
if util.HasPrefixes(path, "/api/v1/status", "/s/*") && method == http.MethodGet {
|
if util.HasPrefixes(path, "/api/v1/workspace/status", "/s/*") && method == http.MethodGet {
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing access token")
|
return echo.NewHTTPError(http.StatusUnauthorized, "Missing access token")
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package v1
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/boojack/shortify/server/profile"
|
|
||||||
"github.com/boojack/shortify/store"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SystemStatus struct {
|
|
||||||
Profile *profile.Profile `json:"profile"`
|
|
||||||
DisallowSignUp bool `json:"disallowSignUp"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *APIV1Service) registerSystemRoutes(g *echo.Group) {
|
|
||||||
g.GET("/ping", func(c echo.Context) error {
|
|
||||||
return c.JSON(http.StatusOK, s.Profile)
|
|
||||||
})
|
|
||||||
|
|
||||||
g.GET("/status", func(c echo.Context) error {
|
|
||||||
ctx := c.Request().Context()
|
|
||||||
systemStatus := SystemStatus{
|
|
||||||
Profile: s.Profile,
|
|
||||||
}
|
|
||||||
|
|
||||||
disallowSignUpSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
|
||||||
Key: WorkspaceDisallowSignUp.String(),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get workspace setting")
|
|
||||||
}
|
|
||||||
if disallowSignUpSetting != nil {
|
|
||||||
systemStatus.DisallowSignUp = disallowSignUpSetting.Value == "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, systemStatus)
|
|
||||||
})
|
|
||||||
}
|
|
@ -24,8 +24,7 @@ func (s *APIV1Service) Start(apiGroup *echo.Group, secret string) {
|
|||||||
apiV1Group.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
apiV1Group.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return JWTMiddleware(s, next, string(secret))
|
return JWTMiddleware(s, next, string(secret))
|
||||||
})
|
})
|
||||||
s.registerSystemRoutes(apiV1Group)
|
s.registerWorkspaceRoutes(apiV1Group)
|
||||||
s.registerWorkspaceSettingRoutes(apiV1Group)
|
|
||||||
s.registerAuthRoutes(apiV1Group, secret)
|
s.registerAuthRoutes(apiV1Group, secret)
|
||||||
s.registerUserRoutes(apiV1Group)
|
s.registerUserRoutes(apiV1Group)
|
||||||
s.registerShortcutRoutes(apiV1Group)
|
s.registerShortcutRoutes(apiV1Group)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/boojack/shortify/server/profile"
|
||||||
"github.com/boojack/shortify/store"
|
"github.com/boojack/shortify/store"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@ -48,7 +49,31 @@ func (upsert WorkspaceSettingUpsert) Validate() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *APIV1Service) registerWorkspaceSettingRoutes(g *echo.Group) {
|
type WorkspaceStatus struct {
|
||||||
|
Profile *profile.Profile `json:"profile"`
|
||||||
|
DisallowSignUp bool `json:"disallowSignUp"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *APIV1Service) registerWorkspaceRoutes(g *echo.Group) {
|
||||||
|
g.GET("/workspace/status", func(c echo.Context) error {
|
||||||
|
ctx := c.Request().Context()
|
||||||
|
workspaceStatus := WorkspaceStatus{
|
||||||
|
Profile: s.Profile,
|
||||||
|
}
|
||||||
|
|
||||||
|
disallowSignUpSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||||
|
Key: WorkspaceDisallowSignUp.String(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get workspace setting")
|
||||||
|
}
|
||||||
|
if disallowSignUpSetting != nil {
|
||||||
|
workspaceStatus.DisallowSignUp = disallowSignUpSetting.Value == "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, workspaceStatus)
|
||||||
|
})
|
||||||
|
|
||||||
g.POST("/workspace/setting", func(c echo.Context) error {
|
g.POST("/workspace/setting", func(c echo.Context) error {
|
||||||
ctx := c.Request().Context()
|
ctx := c.Request().Context()
|
||||||
userID, ok := c.Get(getUserIDContextKey()).(int)
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
@ -1,7 +1,7 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
export function getSystemStatus() {
|
export function getSystemStatus() {
|
||||||
return axios.get<SystemStatus>("/api/v1/status");
|
return axios.get<SystemStatus>("/api/v1/workspace/status");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function signin(email: string, password: string) {
|
export function signin(email: string, password: string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user