chore: update workspace api

This commit is contained in:
Steven 2023-06-24 22:57:16 +08:00
parent a27457c4d3
commit ff963e36d7
5 changed files with 29 additions and 44 deletions

View File

@ -84,7 +84,7 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
token := findAccessToken(c)
if token == "" {
// 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 echo.NewHTTPError(http.StatusUnauthorized, "Missing access token")

View File

@ -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)
})
}

View File

@ -24,8 +24,7 @@ func (s *APIV1Service) Start(apiGroup *echo.Group, secret string) {
apiV1Group.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return JWTMiddleware(s, next, string(secret))
})
s.registerSystemRoutes(apiV1Group)
s.registerWorkspaceSettingRoutes(apiV1Group)
s.registerWorkspaceRoutes(apiV1Group)
s.registerAuthRoutes(apiV1Group, secret)
s.registerUserRoutes(apiV1Group)
s.registerShortcutRoutes(apiV1Group)

View File

@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"github.com/boojack/shortify/server/profile"
"github.com/boojack/shortify/store"
"github.com/labstack/echo/v4"
)
@ -48,7 +49,31 @@ func (upsert WorkspaceSettingUpsert) Validate() error {
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 {
ctx := c.Request().Context()
userID, ok := c.Get(getUserIDContextKey()).(int)

View File

@ -1,7 +1,7 @@
import axios from "axios";
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) {