@@ -18,9 +18,10 @@ let { template } = argv.options;
1818if ( ! template || typeof template !== 'string' ) template = findFileSync ( '@hydrooj/ui-default/templates' ) ;
1919else template = findFileSync ( template ) ;
2020
21- const replacer = ( k , v ) => {
21+ const replacer = ( s ) => ( k , v ) => {
2222 if ( k . startsWith ( '_' ) && k !== '_id' ) return undefined ;
2323 if ( typeof v === 'bigint' ) return `BigInt::${ v . toString ( ) } ` ;
24+ if ( v && typeof v === 'object' && 'serialize' in v && typeof v . serialize === 'function' ) return v . serialize ( s ) ;
2425 return v ;
2526} ;
2627
@@ -68,7 +69,7 @@ class Nunjucks extends nunjucks.Environment {
6869 callback ( error ) ;
6970 }
7071 } , true ) ;
71- this . addFilter ( 'json' , ( self ) => ( self ? JSON . stringify ( self , replacer ) : '' ) ) ;
72+ this . addFilter ( 'json' , ( self , s ) => ( self ? JSON . stringify ( self , replacer ( s ) ) : '' ) ) ;
7273 this . addFilter ( 'parseYaml' , ( self ) => yaml . load ( self ) ) ;
7374 this . addFilter ( 'dumpYaml' , ( self ) => yaml . dump ( self ) ) ;
7475 this . addFilter ( 'assign' , ( self , data ) => Object . assign ( self , data ) ) ;
@@ -79,7 +80,7 @@ class Nunjucks extends nunjucks.Environment {
7980 this . addFilter ( 'base64_decode' , ( s ) => Buffer . from ( s , 'base64' ) . toString ( ) ) ;
8081 this . addFilter ( 'jsesc' , ( self ) => jsesc ( self , { isScriptContext : true } ) ) ;
8182 this . addFilter ( 'bitand' , ( self , val ) => self & val ) ;
82- this . addFilter ( 'toString' , ( self ) => ( typeof self === 'string' ? self : JSON . stringify ( self , replacer ) ) ) ;
83+ this . addFilter ( 'toString' , ( self , s ) => ( typeof self === 'string' ? self : JSON . stringify ( self , replacer ( s ) ) ) ) ;
8384 this . addFilter ( 'content' , ( content , language , html ) => {
8485 let s : any = '' ;
8586 try {
0 commit comments