From ddcf1d669d41dbb19b94955d19c9ed6ca44c1b9f Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 8 Jan 2024 21:17:21 +0800 Subject: [PATCH] chore: add max content length --- api/v2/memo_service.go | 10 ++++++++++ web/src/store/v1/memo.ts | 1 + 2 files changed, 11 insertions(+) diff --git a/api/v2/memo_service.go b/api/v2/memo_service.go index e1d72c6a..0e00e72a 100644 --- a/api/v2/memo_service.go +++ b/api/v2/memo_service.go @@ -27,6 +27,10 @@ import ( "github.com/usememos/memos/store" ) +const ( + MaxContentLength = 8 * 1024 +) + func (s *APIV2Service) CreateMemo(ctx context.Context, request *apiv2pb.CreateMemoRequest) (*apiv2pb.CreateMemoResponse, error) { user, err := getCurrentUser(ctx, s.Store) if err != nil { @@ -35,6 +39,9 @@ func (s *APIV2Service) CreateMemo(ctx context.Context, request *apiv2pb.CreateMe if user == nil { return nil, status.Errorf(codes.PermissionDenied, "permission denied") } + if len(request.Content) > MaxContentLength { + return nil, status.Errorf(codes.InvalidArgument, "content too long") + } nodes, err := parser.Parse(tokenizer.Tokenize(request.Content)) if err != nil { @@ -260,6 +267,9 @@ func (s *APIV2Service) UpdateMemo(ctx context.Context, request *apiv2pb.UpdateMe } } } + if update.Content != nil && len(*update.Content) > MaxContentLength { + return nil, status.Errorf(codes.InvalidArgument, "content too long") + } if err = s.Store.UpdateMemo(ctx, update); err != nil { return nil, status.Errorf(codes.Internal, "failed to update memo") diff --git a/web/src/store/v1/memo.ts b/web/src/store/v1/memo.ts index 530183df..4f942b3a 100644 --- a/web/src/store/v1/memo.ts +++ b/web/src/store/v1/memo.ts @@ -21,6 +21,7 @@ export const useMemoStore = create( for (const memo of memos) { memoMap[memo.id] = memo; } + console.log("memos", memos); set({ memoMapById: memoMap }); return memos; },