@@ -3,7 +3,7 @@ import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
33import { UnControlled as CodeMirror } from 'react-codemirror2'
44import SnappyJS from 'snappyjs'
55import { Buffer } from "buffer" ;
6- import { decode } from "@msgpack/msgpack" ;
6+ import { decode , encode } from "@msgpack/msgpack" ;
77
88const zlib = require ( 'zlib' ) ;
99require ( 'codemirror/mode/javascript/javascript' ) ;
@@ -83,11 +83,25 @@ export class JSONFormatter extends Component {
8383 input = input . replace ( / \r ? \n | \r / g, "" ) ;
8484 // check whether the input is a base64 string and then try use snappy to decompress it
8585 var base64regex = / ^ ( [ 0 - 9 a - z A - Z + / ] { 4 } ) * ( ( [ 0 - 9 a - z A - Z + / ] { 2 } = = ) | ( [ 0 - 9 a - z A - Z + / ] { 3 } = ) ) ? $ / ;
86+ var intRegex = / ^ [ 0 - 9 ] + $ / ;
8687 if ( base64regex . test ( input ) ) {
8788 var uncompressed = SnappyJS . uncompress ( Buffer . from ( input , 'base64' ) ) ;
8889 let utf8decoder = new TextDecoder ( )
8990 jsonString = utf8decoder . decode ( uncompressed ) ;
9091 }
92+ else if ( intRegex . test ( input ) ) {
93+ var intValue = parseInt ( input , 10 ) ; // base 10
94+ var ids = [ 0 , intValue ] ; // Example: Wrap it in an array
95+ var encodedBuffer = encode ( ids ) ;
96+ var base64WithoutPadding = Buffer . from ( encodedBuffer ) . toString ( 'base64' ) . replace ( / = + $ / , '' ) ;
97+
98+ var json = { } ;
99+ json [ "Enterprise" ] = 'E_' + base64WithoutPadding ;
100+ json [ "Organization" ] = 'O_' + base64WithoutPadding ;
101+ json [ "User" ] = 'U_' + base64WithoutPadding ;
102+ json [ "Repository" ] = 'R_' + base64WithoutPadding ;
103+ jsonString = JSON . stringify ( json , null , 4 ) ;
104+ }
91105 else {
92106 var parts = input . split ( '_' , 2 ) ;
93107 if ( parts . length !== 2 ) {
0 commit comments