Skip to content

Commit a98ac24

Browse files
raararaarahackerwins
authored andcommitted
Introduce document size limit (#1270)
Added size limit for documents(10 MiB default), enforced during the document editing. Local updates will be checked against this limit, but remote changes exceeding the limit will still be accepted. This helps prevent excessive resource usage and ensures stable client-server interactions.
1 parent 3b3283d commit a98ac24

34 files changed

+2101
-1498
lines changed

api/converter/from_pb.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func FromProject(pbProject *api.Project) *types.Project {
6767
ClientDeactivateThreshold: pbProject.ClientDeactivateThreshold,
6868
MaxSubscribersPerDocument: int(pbProject.MaxSubscribersPerDocument),
6969
MaxAttachmentsPerDocument: int(pbProject.MaxAttachmentsPerDocument),
70+
MaxSizePerDocument: int(pbProject.MaxSizePerDocument),
7071
AllowedOrigins: pbProject.AllowedOrigins,
7172
PublicKey: pbProject.PublicKey,
7273
SecretKey: pbProject.SecretKey,
@@ -900,6 +901,10 @@ func FromUpdatableProjectFields(pbProjectFields *api.UpdatableProjectFields) (*t
900901
value := int(pbProjectFields.MaxAttachmentsPerDocument.Value)
901902
updatableProjectFields.MaxAttachmentsPerDocument = &value
902903
}
904+
if pbProjectFields.MaxSizePerDocument != nil {
905+
value := int(pbProjectFields.MaxSizePerDocument.Value)
906+
updatableProjectFields.MaxSizePerDocument = &value
907+
}
903908
if pbProjectFields.AllowedOrigins != nil {
904909
updatableProjectFields.AllowedOrigins = &pbProjectFields.AllowedOrigins.Origins
905910
}

api/converter/to_pb.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func ToProject(project *types.Project) *api.Project {
6666
ClientDeactivateThreshold: project.ClientDeactivateThreshold,
6767
MaxSubscribersPerDocument: int32(project.MaxSubscribersPerDocument),
6868
MaxAttachmentsPerDocument: int32(project.MaxAttachmentsPerDocument),
69+
MaxSizePerDocument: int32(project.MaxSizePerDocument),
6970
AllowedOrigins: project.AllowedOrigins,
7071
PublicKey: project.PublicKey,
7172
SecretKey: project.SecretKey,
@@ -607,5 +608,10 @@ func ToUpdatableProjectFields(fields *types.UpdatableProjectFields) (*api.Updata
607608
Value: int32(*fields.MaxAttachmentsPerDocument),
608609
}
609610
}
611+
if fields.MaxSizePerDocument != nil {
612+
pbUpdatableProjectFields.MaxSizePerDocument = &wrapperspb.Int32Value{
613+
Value: int32(*fields.MaxSizePerDocument),
614+
}
615+
}
610616
return pbUpdatableProjectFields, nil
611617
}

api/docs/yorkie/v1/admin.openapi.yaml

Lines changed: 368 additions & 358 deletions
Large diffs are not rendered by default.

api/docs/yorkie/v1/cluster.openapi.yaml

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,141 @@
11
openapi: 3.1.0
22
info:
3-
description:
4-
Yorkie is an open source document store for building collaborative
3+
description: Yorkie is an open source document store for building collaborative
54
editing applications.
65
title: Yorkie
76
version: v0.6.12
87
servers:
9-
- description: Production server
10-
url: https://api.yorkie.dev
11-
- description: Local server
12-
url: http://localhost:8080
8+
- description: Production server
9+
url: https://api.yorkie.dev
10+
- description: Local server
11+
url: http://localhost:8080
1312
paths:
1413
/yorkie.v1.ClusterService/CompactDocument:
1514
post:
1615
description: ""
1716
requestBody:
18-
$ref: "#/components/requestBodies/yorkie.v1.ClusterService.CompactDocument.yorkie.v1.ClusterServiceCompactDocumentRequest"
17+
$ref: '#/components/requestBodies/yorkie.v1.ClusterService.CompactDocument.yorkie.v1.ClusterServiceCompactDocumentRequest'
1918
responses:
2019
"200":
21-
$ref: "#/components/responses/yorkie.v1.ClusterService.CompactDocument.yorkie.v1.ClusterServiceCompactDocumentResponse"
20+
$ref: '#/components/responses/yorkie.v1.ClusterService.CompactDocument.yorkie.v1.ClusterServiceCompactDocumentResponse'
2221
default:
23-
$ref: "#/components/responses/connect.error"
22+
$ref: '#/components/responses/connect.error'
2423
tags:
25-
- yorkie.v1.ClusterService
24+
- yorkie.v1.ClusterService
2625
/yorkie.v1.ClusterService/DetachDocument:
2726
post:
2827
description: ""
2928
requestBody:
30-
$ref: "#/components/requestBodies/yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentRequest"
29+
$ref: '#/components/requestBodies/yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentRequest'
3130
responses:
3231
"200":
33-
$ref: "#/components/responses/yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentResponse"
32+
$ref: '#/components/responses/yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentResponse'
3433
default:
35-
$ref: "#/components/responses/connect.error"
34+
$ref: '#/components/responses/connect.error'
3635
tags:
37-
- yorkie.v1.ClusterService
36+
- yorkie.v1.ClusterService
3837
/yorkie.v1.ClusterService/PurgeDocument:
3938
post:
4039
description: ""
4140
requestBody:
42-
$ref: "#/components/requestBodies/yorkie.v1.ClusterService.PurgeDocument.yorkie.v1.ClusterServicePurgeDocumentRequest"
41+
$ref: '#/components/requestBodies/yorkie.v1.ClusterService.PurgeDocument.yorkie.v1.ClusterServicePurgeDocumentRequest'
4342
responses:
4443
"200":
45-
$ref: "#/components/responses/yorkie.v1.ClusterService.PurgeDocument.yorkie.v1.ClusterServicePurgeDocumentResponse"
44+
$ref: '#/components/responses/yorkie.v1.ClusterService.PurgeDocument.yorkie.v1.ClusterServicePurgeDocumentResponse'
4645
default:
47-
$ref: "#/components/responses/connect.error"
46+
$ref: '#/components/responses/connect.error'
4847
tags:
49-
- yorkie.v1.ClusterService
48+
- yorkie.v1.ClusterService
5049
components:
5150
requestBodies:
5251
yorkie.v1.ClusterService.CompactDocument.yorkie.v1.ClusterServiceCompactDocumentRequest:
5352
content:
5453
application/json:
5554
schema:
56-
$ref: "#/components/schemas/yorkie.v1.ClusterServiceCompactDocumentRequest"
55+
$ref: '#/components/schemas/yorkie.v1.ClusterServiceCompactDocumentRequest'
5756
application/proto:
5857
schema:
59-
$ref: "#/components/schemas/yorkie.v1.ClusterServiceCompactDocumentRequest"
58+
$ref: '#/components/schemas/yorkie.v1.ClusterServiceCompactDocumentRequest'
6059
required: true
6160
yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentRequest:
6261
content:
6362
application/json:
6463
schema:
65-
$ref: "#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentRequest"
64+
$ref: '#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentRequest'
6665
application/proto:
6766
schema:
68-
$ref: "#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentRequest"
67+
$ref: '#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentRequest'
6968
required: true
7069
yorkie.v1.ClusterService.PurgeDocument.yorkie.v1.ClusterServicePurgeDocumentRequest:
7170
content:
7271
application/json:
7372
schema:
74-
$ref: "#/components/schemas/yorkie.v1.ClusterServicePurgeDocumentRequest"
73+
$ref: '#/components/schemas/yorkie.v1.ClusterServicePurgeDocumentRequest'
7574
application/proto:
7675
schema:
77-
$ref: "#/components/schemas/yorkie.v1.ClusterServicePurgeDocumentRequest"
76+
$ref: '#/components/schemas/yorkie.v1.ClusterServicePurgeDocumentRequest'
7877
required: true
7978
responses:
8079
connect.error:
8180
content:
8281
application/json:
8382
schema:
84-
$ref: "#/components/schemas/connect.error"
83+
$ref: '#/components/schemas/connect.error'
8584
application/proto:
8685
schema:
87-
$ref: "#/components/schemas/connect.error"
86+
$ref: '#/components/schemas/connect.error'
8887
description: ""
8988
yorkie.v1.ClusterService.CompactDocument.yorkie.v1.ClusterServiceCompactDocumentResponse:
9089
content:
9190
application/json:
9291
schema:
93-
$ref: "#/components/schemas/yorkie.v1.ClusterServiceCompactDocumentResponse"
92+
$ref: '#/components/schemas/yorkie.v1.ClusterServiceCompactDocumentResponse'
9493
application/proto:
9594
schema:
96-
$ref: "#/components/schemas/yorkie.v1.ClusterServiceCompactDocumentResponse"
95+
$ref: '#/components/schemas/yorkie.v1.ClusterServiceCompactDocumentResponse'
9796
description: ""
9897
yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentResponse:
9998
content:
10099
application/json:
101100
schema:
102-
$ref: "#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentResponse"
101+
$ref: '#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentResponse'
103102
application/proto:
104103
schema:
105-
$ref: "#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentResponse"
104+
$ref: '#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentResponse'
106105
description: ""
107106
yorkie.v1.ClusterService.PurgeDocument.yorkie.v1.ClusterServicePurgeDocumentResponse:
108107
content:
109108
application/json:
110109
schema:
111-
$ref: "#/components/schemas/yorkie.v1.ClusterServicePurgeDocumentResponse"
110+
$ref: '#/components/schemas/yorkie.v1.ClusterServicePurgeDocumentResponse'
112111
application/proto:
113112
schema:
114-
$ref: "#/components/schemas/yorkie.v1.ClusterServicePurgeDocumentResponse"
113+
$ref: '#/components/schemas/yorkie.v1.ClusterServicePurgeDocumentResponse'
115114
description: ""
116115
schemas:
117116
connect.error:
118117
additionalProperties: false
119-
description: "Error type returned by Connect: https://connectrpc.com/docs/go/errors/#http-representation"
118+
description: 'Error type returned by Connect: https://connectrpc.com/docs/go/errors/#http-representation'
120119
properties:
121120
code:
122121
enum:
123-
- CodeCanceled
124-
- CodeUnknown
125-
- CodeInvalidArgument
126-
- CodeDeadlineExceeded
127-
- CodeNotFound
128-
- CodeAlreadyExists
129-
- CodePermissionDenied
130-
- CodeResourceExhausted
131-
- CodeFailedPrecondition
132-
- CodeAborted
133-
- CodeOutOfRange
134-
- CodeInternal
135-
- CodeUnavailable
136-
- CodeDataLoss
137-
- CodeUnauthenticated
122+
- CodeCanceled
123+
- CodeUnknown
124+
- CodeInvalidArgument
125+
- CodeDeadlineExceeded
126+
- CodeNotFound
127+
- CodeAlreadyExists
128+
- CodePermissionDenied
129+
- CodeResourceExhausted
130+
- CodeFailedPrecondition
131+
- CodeAborted
132+
- CodeOutOfRange
133+
- CodeInternal
134+
- CodeUnavailable
135+
- CodeDataLoss
136+
- CodeUnauthenticated
138137
examples:
139-
- CodeNotFound
138+
- CodeNotFound
140139
type: string
141140
message:
142141
type: string
@@ -267,13 +266,13 @@ components:
267266
title: client_id
268267
type: string
269268
documentSummary:
270-
$ref: "#/components/schemas/yorkie.v1.DocumentSummary"
269+
$ref: '#/components/schemas/yorkie.v1.DocumentSummary'
271270
additionalProperties: false
272271
description: ""
273272
title: document_summary
274273
type: object
275274
project:
276-
$ref: "#/components/schemas/yorkie.v1.Project"
275+
$ref: '#/components/schemas/yorkie.v1.Project'
277276
additionalProperties: false
278277
description: ""
279278
title: project
@@ -327,13 +326,13 @@ components:
327326
description: ""
328327
properties:
329328
gc:
330-
$ref: "#/components/schemas/yorkie.v1.DataSize"
329+
$ref: '#/components/schemas/yorkie.v1.DataSize'
331330
additionalProperties: false
332331
description: ""
333332
title: gc
334333
type: object
335334
live:
336-
$ref: "#/components/schemas/yorkie.v1.DataSize"
335+
$ref: '#/components/schemas/yorkie.v1.DataSize'
337336
additionalProperties: false
338337
description: ""
339338
title: live
@@ -345,7 +344,7 @@ components:
345344
description: ""
346345
properties:
347346
accessedAt:
348-
$ref: "#/components/schemas/google.protobuf.Timestamp"
347+
$ref: '#/components/schemas/google.protobuf.Timestamp'
349348
additionalProperties: false
350349
description: ""
351350
title: accessed_at
@@ -356,13 +355,13 @@ components:
356355
title: attached_clients
357356
type: integer
358357
createdAt:
359-
$ref: "#/components/schemas/google.protobuf.Timestamp"
358+
$ref: '#/components/schemas/google.protobuf.Timestamp'
360359
additionalProperties: false
361360
description: ""
362361
title: created_at
363362
type: object
364363
documentSize:
365-
$ref: "#/components/schemas/yorkie.v1.DocSize"
364+
$ref: '#/components/schemas/yorkie.v1.DocSize'
366365
additionalProperties: false
367366
description: ""
368367
title: document_size
@@ -383,7 +382,7 @@ components:
383382
title: snapshot
384383
type: string
385384
updatedAt:
386-
$ref: "#/components/schemas/google.protobuf.Timestamp"
385+
$ref: '#/components/schemas/google.protobuf.Timestamp'
387386
additionalProperties: false
388387
description: ""
389388
title: updated_at
@@ -419,7 +418,7 @@ components:
419418
title: client_deactivate_threshold
420419
type: string
421420
createdAt:
422-
$ref: "#/components/schemas/google.protobuf.Timestamp"
421+
$ref: '#/components/schemas/google.protobuf.Timestamp'
423422
additionalProperties: false
424423
description: ""
425424
title: created_at
@@ -446,6 +445,11 @@ components:
446445
description: ""
447446
title: max_attachments_per_document
448447
type: integer
448+
maxSizePerDocument:
449+
additionalProperties: false
450+
description: ""
451+
title: max_size_per_document
452+
type: integer
449453
maxSubscribersPerDocument:
450454
additionalProperties: false
451455
description: ""
@@ -467,7 +471,7 @@ components:
467471
title: secret_key
468472
type: string
469473
updatedAt:
470-
$ref: "#/components/schemas/google.protobuf.Timestamp"
474+
$ref: '#/components/schemas/google.protobuf.Timestamp'
471475
additionalProperties: false
472476
description: ""
473477
title: updated_at
@@ -480,7 +484,7 @@ components:
480484
name: Authorization
481485
type: apiKey
482486
security:
483-
- ApiKeyAuth: []
487+
- ApiKeyAuth: []
484488
tags:
485-
- description: ClusterService is a service that provides an API for Cluster.
486-
name: yorkie.v1.ClusterService
489+
- description: ClusterService is a service that provides an API for Cluster.
490+
name: yorkie.v1.ClusterService

0 commit comments

Comments
 (0)