@@ -3,7 +3,14 @@ import {StorePatch} from './types';
33import { RpcError , RpcErrorCodes } from '../../../reactive-rpc/common/rpc/caller' ;
44import type { Services } from '../Services' ;
55
6- const BLOCK_TTL = 1000 * 60 * 20 ; // 20 minutes
6+ const BLOCK_TTL = 1000 * 60 * 60 ; // 1 hour
7+
8+ const validatePatches = ( patches : StorePatch [ ] ) => {
9+ for ( const patch of patches ) {
10+ if ( patch . blob . length > 2000 ) throw RpcError . validation ( 'patch blob too large' ) ;
11+ if ( patch . seq > 500_000 ) throw RpcError . validation ( 'patch seq too large' ) ;
12+ }
13+ } ;
714
815export class BlocksServices {
916 protected readonly store = new MemoryStore ( ) ;
@@ -13,6 +20,7 @@ export class BlocksServices {
1320 public async create ( id : string , patches : StorePatch [ ] ) {
1421 this . maybeGc ( ) ;
1522 const { store} = this ;
23+ validatePatches ( patches ) ;
1624 const { block} = await store . create ( id , patches ) ;
1725 const data = {
1826 block,
@@ -47,12 +55,13 @@ export class BlocksServices {
4755 return { patches} ;
4856 }
4957
50- public async edit ( id : string , patches : any [ ] ) {
58+ public async edit ( id : string , patches : StorePatch [ ] ) {
5159 this . maybeGc ( ) ;
5260 if ( ! Array . isArray ( patches ) ) throw RpcError . validation ( 'patches must be an array' ) ;
5361 if ( ! patches . length ) throw RpcError . validation ( 'patches must not be empty' ) ;
5462 const seq = patches [ 0 ] . seq ;
5563 const { store} = this ;
64+ validatePatches ( patches ) ;
5665 const { block} = await store . edit ( id , patches ) ;
5766 this . services . pubsub . publish ( `__block:${ id } ` , { patches} ) . catch ( ( error ) => {
5867 // tslint:disable-next-line:no-console
0 commit comments