@@ -11,6 +11,7 @@ var pagesList = {
1111 }
1212} ;
1313
14+
1415module . exports = {
1516 pagesList : pagesList ,
1617 consumes : [ "app" ] ,
@@ -37,8 +38,9 @@ module.exports = {
3738 return arr1 . join ( '' ) ;
3839 }
3940
40- var page = { } ; //encrypt and encrypt-file will take over this object ;
41+ var terminal_applied = false ;
4142
43+ var page = { } ;
4244 var $page = {
4345 view : require ( "./decrypt.page.html" ) . default ,
4446 init : function ( app , $page , pathname ) {
@@ -52,36 +54,48 @@ module.exports = {
5254 var $ = app . $ ;
5355 var onlykeyApi = app . onlykeyApi ;
5456
55- page . okpgp = onlykeyApi . pgp ( ) . api ( ) ;
56-
57+ page . okpgp = app . onlykeyApi . pgp ( ) . api ( ) ;
58+
5759 if ( doInit ) {
60+
5861 page . gun = app . newGun ( ) ;
59-
60- var params = app . pages . getAllUrlParams ( ) ;
61- if ( params . type == 'dv' ) document . getElementById ( 'decrypt_and_verify' ) . checked = true ;
62- if ( params . type == 'd' ) document . getElementById ( 'decrypt_only' ) . checked = true ;
62+
63+ var params = onlykeyApi . api . getAllUrlParams ( ) ;
64+
65+ page . initParams = params ;
66+
6367 if ( params . sender ) document . getElementById ( 'pgpkeyurl' ) . value = params . sender ;
64-
68+ // if (params.recipients) document.getElementById('pgpkeyurl').value = params.recipients;
69+ if ( params . type == 'dv' ) {
70+ document . getElementById ( 'decrypt_and_verify' ) . checked = true ;
71+ page . okpgp . _$mode ( 'Decrypt and Verify' ) ;
72+ }
73+ if ( params . type == 'd' ) {
74+ document . getElementById ( 'decrypt_only' ) . checked = true ;
75+ page . okpgp . _$mode ( 'Decrypt Only' ) ;
76+ document . getElementById ( 'pgpkeyurl' ) . style . display = "none" ;
77+ }
78+
6579 if ( params . gm == 1 ) {
6680 var gm = params [ "#" ] . split ( "-" ) ;
6781 page . gun_message_key = gm [ 1 ] ;
6882 page . gun_message = gm_decode ( gm [ 0 ] ) ;
6983 }
70-
84+
7185 onlykeyApi . api . on ( "status" , function ( message ) {
7286 page . button . textContent = message ;
7387 } ) ;
74-
88+
7589 onlykeyApi . api . on ( "error" , function ( message ) {
7690 console . log ( "okapi-error" , message ) ;
7791 page . button . textContent = message ;
7892 page . button . classList . add ( 'error' ) ;
7993 page . button . classList . remove ( 'working' ) ;
94+ if ( page . okpgp ) page . okpgp . emit ( "completed" ) ;
8095 } ) ;
8196 }
82-
97+
8398 page . okpgp . _$mode ( $ ( "#action" ) [ 0 ] . select_one . value ) ;
84-
8599
86100 page . okpgp . on ( "status" , function ( message ) {
87101 page . button . textContent = message ;
@@ -109,6 +123,8 @@ module.exports = {
109123
110124 app . xterm . writeln ( "PGP Mode to " + page . okpgp . _$mode ( ) ) ;
111125
126+ if ( page . initParams . recipients ) document . getElementById ( 'pgpkeyurl2' ) . value = page . initParams . recipients ;
127+
112128 $ ( ".messageLink" ) . html ( "" ) ;
113129 onlykeyApi . api . request_pgp_pubkey = function ( ) {
114130 function error_1 ( err ) {
@@ -152,17 +168,64 @@ module.exports = {
152168 }
153169 }
154170
171+ onlykeyApi . api . request_pgp_pubkey = function ( ) {
172+ function error_1 ( err ) {
173+ page . button . textContent = err ;
174+ }
175+
176+ function error_2 ( err ) {
177+ page . button . textContent = 'Your PublicKey is ' + err ;
178+ }
179+ return new Promise ( async function ( resolve ) {
180+ var pubkey = $ ( "#pgpkeyurl2" ) . val ( ) ;
181+ if ( pubkey == "" || ! pubkey ) {
182+ resolve ( { value : false , on_error : error_1 } ) ;
183+ }
184+ else {
185+ pubkey = await onlykeyApi . api . getKey ( pubkey ) ;
186+ resolve ( {
187+ value : pubkey ,
188+ on_error : error_2
189+ } ) ;
190+ }
191+ } ) ;
192+ } ;
155193
156194 document . getElementsByTagName ( 'fieldset' ) [ 0 ] . style . backgroundColor = app . randomColor ( {
157195 luminosity : 'bright' ,
158196 format : 'rgba'
159197 } ) ;
160198
161- page . urlinputbox = document . getElementById ( 'pgpkeyurl' ) ;
162199 page . urlinputbox2 = document . getElementById ( 'pgpkeyurl2' ) ;
200+ page . urlinputbox = document . getElementById ( 'pgpkeyurl' ) ;
163201 page . messagebox = document . getElementById ( 'message' ) ;
164202 page . button = document . getElementById ( 'onlykey_start' ) ;
165203
204+ var pageType = false ;
205+
206+ if ( page . okpgp . _$mode_is ( 'Decrypt Only' ) ) {
207+ document . getElementById ( 'pgpkeyurl2' ) . style . display = "initial" ;
208+ document . getElementById ( 'pgpkeyurl' ) . style . display = "none" ;
209+ page . button . textContent = 'Decrypt' ;
210+ pageType = "d" ;
211+ }
212+ if ( page . okpgp . _$mode_is ( 'Decrypt and Verify' ) ) {
213+ document . getElementById ( 'pgpkeyurl' ) . style . display = "initial" ;
214+ document . getElementById ( 'pgpkeyurl2' ) . style . display = "initial" ;
215+ page . button . textContent = 'Decrypt and Verify' ;
216+ pageType = "dv" ;
217+ }
218+
219+ if ( pageType )
220+ app . pages . state . replace ( { pathname : pathname } , $ ( "title" ) . text ( ) ,
221+ "./" + pathname +
222+ "?type=" + pageType +
223+ ( page . initParams . recipients ? "&recipients=" + page . initParams . recipients : '' ) ) ;
224+
225+ $ ( ".messageLink" ) . html ( "" ) ;
226+ //$(window).scrollTo("h1", 1000);
227+
228+
166229 page . button . classList . remove ( 'error' ) ;
167230 page . button . classList . remove ( 'working' ) ;
168231
@@ -193,33 +256,21 @@ module.exports = {
193256 } ;
194257 dlGM ( ) ;
195258
196- var pageType = false ;
197-
198- switch ( page . okpgp . _$mode ( ) ) {
199- case 'Decrypt and Verify' :
200- $ ( "#pgpkeyurl" ) . show ( ) ;
201- $ ( "#pgpkeyurl2" ) . show ( ) ;
202- $ ( "#pgpkeyurl_tokenizer" ) . show ( ) ;
203- $ ( "#message" ) . show ( ) ;
204- page . button . textContent = 'Decrypt and Verify' ;
205- pageType = "dv" ;
206- break ;
207- case 'Decrypt Only' :
208- $ ( "#pgpkeyurl" ) . show ( ) ;
209- $ ( "#pgpkeyurl2" ) . show ( ) ;
210- $ ( "#pgpkeyurl_tokenizer" ) . show ( ) ;
211- $ ( "#message" ) . show ( ) ;
212- pageType = "d" ;
213- page . button . textContent = 'Decrypt' ;
214- break ;
215- }
216-
217259
218- if ( pageType )
219- app . pages . state . replace ( { pathname : pathname } , $ ( "title" ) . text ( ) , "./" + pathname + "?type=" + pageType ) ;
260+ $ ( "#pgpkeyurl2" ) . change ( function ( ) {
261+ switch ( page . okpgp . _$mode ( ) ) {
262+ case 'Decrypt and Verify' :
263+ pageType = "dv" ;
264+ break ;
265+ case 'Decrypt Only' :
266+ pageType = "d" ;
267+ break ;
268+ }
220269
270+ if ( pageType )
271+ app . pages . state . replace ( { pathname : pathname } , $ ( "title" ) . text ( ) , "./" + pathname + "?type=" + pageType + "&recipients=" + page . urlinputbox . value ) ;
221272
222- //$(window).scrollTo("h1", 1000 );
273+ } ) ;
223274
224275 page . okpgp . on ( "completed" , function ( data ) {
225276 $ ( ".messageLink" ) . html ( "" ) ;
@@ -239,17 +290,30 @@ module.exports = {
239290
240291 } ) ;
241292
242-
243293 if ( ! $ ( "#action" ) . data ( "changeSet" ) ) {
294+
244295 $ ( "#action" ) . data ( "changeSet" , true ) ;
245296 $ ( "#action" ) [ 0 ] . select_one . forEach ( el => el . addEventListener ( 'change' , ( function ( ) {
246297 page . setup ( app , $page , pathname ) ;
247298 } ) . bind ( null , false ) ) ) ;
299+
248300 page . button . addEventListener ( 'click' , async function ( ) {
249301
250302 var message = null ;
251303 var file = null ;
252304
305+ switch ( page . okpgp . _$mode ( ) ) {
306+ case 'Decrypt and Verify' :
307+ pageType = "dv" ;
308+ break ;
309+ case 'Decrypt Only' :
310+ pageType = "s" ;
311+ break ;
312+ }
313+
314+ if ( pageType )
315+ app . pages . state . replace ( { pathname : pathname } , $ ( "title" ) . text ( ) , "./" + pathname + "?type=" + pageType + "&recipients=" + page . urlinputbox . value ) ;
316+
253317 switch ( page . okpgp . _$status ( ) ) {
254318 case 'pending_pin' :
255319 break ;
@@ -290,6 +354,10 @@ module.exports = {
290354 else {
291355 message = page . messagebox . value ;
292356 }
357+
358+ console . log ( page . urlinputbox . value ) ;
359+ console . log ( page . urlinputbox . value ) ;
360+
293361 page . okpgp . startDecryption ( page . urlinputbox . value , page . urlinputbox2 . value , message , file , function ( err , data ) {
294362 if ( page . messagebox && data )
295363 page . messagebox . value = data ;
@@ -298,12 +366,16 @@ module.exports = {
298366 } ) ;
299367 break ;
300368 }
369+
301370 }
302371 } , false ) ;
372+
303373 }
374+
304375 } ,
305376 dispose : function ( app , pathname ) {
306377 //init = false;
378+ // terminal_applied = false;
307379 // console.log("disposed", pathname);
308380 }
309381 } ;
@@ -319,6 +391,7 @@ module.exports = {
319391 setup : $page . setup
320392 } ;
321393
394+
322395 register ( null , {
323396 plugin_decrypt : {
324397 pagesList : pagesList
0 commit comments