@@ -3,7 +3,7 @@ import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
3
3
import { UnControlled as CodeMirror } from 'react-codemirror2'
4
4
import SnappyJS from 'snappyjs'
5
5
import { Buffer } from "buffer" ;
6
- import { decode } from "@msgpack/msgpack" ;
6
+ import { decode , encode } from "@msgpack/msgpack" ;
7
7
8
8
const zlib = require ( 'zlib' ) ;
9
9
require ( 'codemirror/mode/javascript/javascript' ) ;
@@ -83,11 +83,25 @@ export class JSONFormatter extends Component {
83
83
input = input . replace ( / \r ? \n | \r / g, "" ) ;
84
84
// check whether the input is a base64 string and then try use snappy to decompress it
85
85
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 ] + $ / ;
86
87
if ( base64regex . test ( input ) ) {
87
88
var uncompressed = SnappyJS . uncompress ( Buffer . from ( input , 'base64' ) ) ;
88
89
let utf8decoder = new TextDecoder ( )
89
90
jsonString = utf8decoder . decode ( uncompressed ) ;
90
91
}
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
+ }
91
105
else {
92
106
var parts = input . split ( '_' , 2 ) ;
93
107
if ( parts . length !== 2 ) {
0 commit comments