Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iIIusi0n committed Jan 10, 2025
1 parent f186390 commit 2ebe54b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion assets/mysql/initdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS user_license (
license_type_id BINARY(16) NOT NULL REFERENCES user_license_type(id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
);

INSERT INTO user_license_type (id, name) VALUES (UUID_TO_BIN(UUID()), 'free');
INSERT INTO user_license_type (id, name) VALUES (UUID_TO_BIN(UUID()), 'paid');
Expand Down
9 changes: 9 additions & 0 deletions internal/api/gateway/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,14 @@ func NewRouter(clients RouterClients) *gin.Engine {
project.DELETE("/:id", DeleteProjectHandler(clients.ProjectClient))
}

instance := r.Group("/instance")
{
instance.Use(jwtauth.AuthMiddleware())

instance.GET("")
instance.POST("")
instance.DELETE("/:id")
}

return r
}
8 changes: 7 additions & 1 deletion internal/api/stream/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ func InstanceAuthMiddleware(projectClient pb.ProjectClient, instanceClient pb.In
return func(c *gin.Context) {
ctx := context.Background()

if c.Param("id") == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Instance ID is required"})
c.Abort()
return
}

instanceInfo, err := instanceClient.GetInstance(ctx, &pb.GetInstanceRequest{
InstanceId: c.Param("id"),
})
Expand All @@ -37,7 +43,7 @@ func InstanceAuthMiddleware(projectClient pb.ProjectClient, instanceClient pb.In
return
}

c.Set("full_path", fmt.Sprintf("%s/%s", projectInfo.FilePath, projectInfo.FileName))
c.Set("full_path", fmt.Sprintf("/work/%s", projectInfo.FileName))
c.Next()
}
}
4 changes: 2 additions & 2 deletions internal/api/stream/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/gin-gonic/gin"

pb "easypwn/internal/api"
"easypwn/internal/pkg/auth"
authjwt "easypwn/internal/pkg/auth"
)

type RouterClients struct {
Expand All @@ -14,7 +14,7 @@ type RouterClients struct {

func NewRouter(clients RouterClients) *gin.Engine {
r := gin.Default()
r.Use(auth.AuthMiddleware())
r.Use(authjwt.AuthMiddleware())
r.Use(InstanceAuthMiddleware(clients.ProjectClient, clients.InstanceClient))

stream := r.Group("/stream")
Expand Down

0 comments on commit 2ebe54b

Please sign in to comment.