@@ -3,6 +3,7 @@ import { InvalidRequestError, AuthRequiredError } from '@atproto/xrpc-server'
3
3
import { prepareCreate , prepareDelete , prepareUpdate } from '../../../../repo'
4
4
import { Server } from '../../../../lexicon'
5
5
import {
6
+ HandlerInput ,
6
7
isCreate ,
7
8
isUpdate ,
8
9
isDelete ,
@@ -15,9 +16,36 @@ import {
15
16
import AppContext from '../../../../context'
16
17
import { ConcurrentWriteError } from '../../../../services/repo'
17
18
19
+ const ratelimitPoints = ( { input } : { input : HandlerInput } ) => {
20
+ let points = 0
21
+ for ( const op of input . body . writes ) {
22
+ if ( isCreate ( op ) ) {
23
+ points += 3
24
+ } else if ( isUpdate ( op ) ) {
25
+ points += 2
26
+ } else {
27
+ points += 1
28
+ }
29
+ }
30
+ return points
31
+ }
32
+
18
33
export default function ( server : Server , ctx : AppContext ) {
19
34
server . com . atproto . repo . applyWrites ( {
20
35
auth : ctx . accessVerifierCheckTakedown ,
36
+ rateLimit : [
37
+ {
38
+ name : 'repo-write-hour' ,
39
+ calcKey : ( { auth } ) => auth . credentials . did ,
40
+ calcPoints : ratelimitPoints ,
41
+ } ,
42
+ {
43
+ name : 'repo-write-day' ,
44
+ calcKey : ( { auth } ) => auth . credentials . did ,
45
+ calcPoints : ratelimitPoints ,
46
+ } ,
47
+ ] ,
48
+
21
49
handler : async ( { input, auth } ) => {
22
50
const tx = input . body
23
51
const { repo, validate, swapCommit } = tx
0 commit comments