@@ -15,6 +15,7 @@ interface Row {
1515interface State {
1616 encrypted : boolean ,
1717 enterPwdFirstTime : boolean ,
18+ password : string | null ,
1819 decryptor : DecryptionService | null ,
1920 rows : Row [ ] ,
2021 raw : boolean ,
@@ -31,18 +32,19 @@ export class Monitor extends Component<{}, State> {
3132
3233 this . state = {
3334 encrypted : false ,
35+ enterPwdFirstTime : ! ( new URLSearchParams ( new URL ( window . location . href ) . search ) . has ( "key" ) ) ,
36+ password : new URLSearchParams ( new URL ( window . location . href ) . search ) . get ( "key" ) ,
3437 decryptor : null ,
35- enterPwdFirstTime : true ,
3638 rows : [ ] ,
3739 raw : new URLSearchParams ( new URL ( window . location . href ) . search ) . has ( "raw" ) ,
3840 } ;
3941
4042 this . numLines = 1 ;
41- this . cli2CloudService = new Cli2CloudClient ( "https://cli2cloud.com:1443" , null , null ) ;
43+ this . cli2CloudService = new Cli2CloudClient ( "https://cli2cloud.com:1443" , null , null ) ; // production
44+ //this.cli2CloudService = new Cli2CloudClient("http://localhost:8000", null, null); // local dev
4245
43- const id = window . location . pathname . substring ( 1 ) ;
44-
4546 this . clientId = new ClientId ( ) ;
47+ const id = window . location . pathname . substring ( 1 ) ;
4648 this . clientId . setId ( id ) ;
4749
4850 this . client = this . cli2CloudService . getClientById ( this . clientId , { } )
@@ -56,16 +58,27 @@ export class Monitor extends Component<{}, State> {
5658 this . switchToRawData = this . switchToRawData . bind ( this ) ;
5759
5860 this . client . then ( ( client ) => { this . setState ( { encrypted : client . getEncrypted ( ) } ) } ) ;
61+
62+ if ( ! this . state . enterPwdFirstTime ) {
63+ this . createDecryptor ( ) ;
64+ }
65+
5966 this . loadContent ( ) ;
6067 }
6168
6269 private updatePassword ( newPassword : string ) {
63- this . createDecryptor ( newPassword ) ;
70+ this . setURLParams ( "key" , newPassword ) ;
71+ this . setState ( { password : newPassword } ) ;
72+ this . createDecryptor ( ) ;
6473 }
6574
66- private createDecryptor ( password : string ) {
75+ private createDecryptor ( ) {
76+ if ( this . state . password === null ) {
77+ console . log ( "Can't create decryptor" ) ;
78+ return ;
79+ }
6780 this . client . then ( ( client : Client ) => {
68- this . setState ( { decryptor : new DecryptionService ( password , client . getSalt ( ) , client . getIv ( ) ) } ) ;
81+ this . setState ( { decryptor : new DecryptionService ( this . state . password ! , client . getSalt ( ) , client . getIv ( ) ) } ) ;
6982 } ) ;
7083 }
7184
@@ -142,11 +155,14 @@ export class Monitor extends Component<{}, State> {
142155 ) ;
143156 }
144157
145- private switchToRawData ( ) {
158+ private setURLParams ( key : string , value : string ) {
146159 let params = new URLSearchParams ( new URL ( window . location . href ) . search ) ;
147- params . set ( "raw" , "true" ) ;
160+ params . set ( key , value ) ;
148161 window . location . search = params . toString ( )
162+ }
149163
164+ private switchToRawData ( ) {
165+ this . setURLParams ( "raw" , "true" ) ;
150166 this . setState ( { raw : true } ) ;
151167 }
152168
0 commit comments