From 0f7a771e8545929245db757adf221a7c756a5114 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 12 Nov 2023 13:41:02 +0800 Subject: [PATCH 1/4] chore: update collection metric --- api/v2/collection_service.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/v2/collection_service.go b/api/v2/collection_service.go index 62a4698..a181bb3 100644 --- a/api/v2/collection_service.go +++ b/api/v2/collection_service.go @@ -10,6 +10,7 @@ import ( apiv2pb "github.com/boojack/slash/proto/gen/api/v2" storepb "github.com/boojack/slash/proto/gen/store" + "github.com/boojack/slash/server/metric" "github.com/boojack/slash/store" ) @@ -78,6 +79,7 @@ func (s *APIV2Service) GetCollectionByName(ctx context.Context, request *apiv2pb response := &apiv2pb.GetCollectionByNameResponse{ Collection: convertCollectionFromStore(collection), } + metric.Enqueue("collection view") return response, nil } @@ -99,6 +101,7 @@ func (s *APIV2Service) CreateCollection(ctx context.Context, request *apiv2pb.Cr response := &apiv2pb.CreateCollectionResponse{ Collection: convertCollectionFromStore(collection), } + metric.Enqueue("collection create") return response, nil } From dddb643bed57237634328bd84b4ce28c2c55793e Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 12 Nov 2023 14:01:00 +0800 Subject: [PATCH 2/4] chore: fix creator initial --- frontend/web/src/pages/CollectionSpace.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/web/src/pages/CollectionSpace.tsx b/frontend/web/src/pages/CollectionSpace.tsx index 1d35d76..d051b83 100644 --- a/frontend/web/src/pages/CollectionSpace.tsx +++ b/frontend/web/src/pages/CollectionSpace.tsx @@ -31,8 +31,8 @@ const CollectionSpace = () => { (async () => { try { const collection = await collectionStore.fetchCollectionByName(collectionName); + await userStore.getOrFetchUserById(collection.creatorId); setCollection(collection); - document.title = `${collection.title} - Slash`; setShortcuts([]); for (const shortcutId of collection.shortcutIds) { try { @@ -44,6 +44,7 @@ const CollectionSpace = () => { // do nth } } + document.title = `${collection.title} - Slash`; } catch (error: any) { console.error(error); toast.error(error.details); From 916423cc89590111194c2b6920c18c71a2f18c2f Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 12 Nov 2023 14:02:39 +0800 Subject: [PATCH 3/4] chore: check selected shortcuts --- frontend/web/src/components/CreateCollectionDialog.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/web/src/components/CreateCollectionDialog.tsx b/frontend/web/src/components/CreateCollectionDialog.tsx index c0cea77..932ac3b 100644 --- a/frontend/web/src/components/CreateCollectionDialog.tsx +++ b/frontend/web/src/components/CreateCollectionDialog.tsx @@ -104,6 +104,10 @@ const CreateCollectionDialog: React.FC = (props: Props) => { toast.error("Please fill in required fields."); return; } + if (selectedShortcuts.length === 0) { + toast.error("Please select at least one shortcut."); + return; + } try { if (!isCreating) { From af9655eeaf9c29868d3fd1263a93efb9a43c5020 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 12 Nov 2023 15:49:00 +0800 Subject: [PATCH 4/4] chore: fix user message --- api/v1/jwt.go | 2 +- api/v1/user.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/v1/jwt.go b/api/v1/jwt.go index d306cd4..545e62f 100644 --- a/api/v1/jwt.go +++ b/api/v1/jwt.go @@ -63,7 +63,7 @@ func JWTMiddleware(s *APIV1Service, next echo.HandlerFunc, secret string) echo.H accessToken := findAccessToken(c) if accessToken == "" { // When the request is not authenticated, we allow the user to access the shortcut endpoints for those public shortcuts. - if util.HasPrefixes(path, "/s/") && method == http.MethodGet { + if util.HasPrefixes(path, "/s/", "/api/v1/user/") && method == http.MethodGet { return next(c) } return echo.NewHTTPError(http.StatusUnauthorized, "Missing access token") diff --git a/api/v1/user.go b/api/v1/user.go index 6ff0014..c516fd4 100644 --- a/api/v1/user.go +++ b/api/v1/user.go @@ -188,7 +188,12 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) { return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find user, err: %s", err)).SetInternal(err) } - return c.JSON(http.StatusOK, convertUserFromStore(user)) + userMessage := convertUserFromStore(user) + userID, ok := c.Get(userIDContextKey).(int32) + if !ok { + userMessage.Email = "" + } + return c.JSON(http.StatusOK, userMessage) }) g.PATCH("/user/:id", func(c echo.Context) error {