chore: add max content length

This commit is contained in:
Steven 2024-01-08 21:17:21 +08:00
parent 32d02ba022
commit ddcf1d669d
2 changed files with 11 additions and 0 deletions

View file

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

View file

@ -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;
},