@@ -52,28 +52,32 @@ function spawnTunnel(index) {
5252 } , 1000 ) ;
5353
5454 child . stdout . on ( "data" , ( data ) => {
55- const output = data . toString ( ) ;
56- // Improved URL regex to catch URLs even if they are surrounded by ANSI codes
57- const urlRegex = / h t t p s : \/ \/ [ ^ \s " ' < > ] + / g;
58- const foundLinks = output . match ( urlRegex ) ;
59-
60- if ( foundLinks ) {
61- foundLinks . forEach ( ( link ) => {
62- const s = link . trim ( ) . replace ( / \x1B \[ [ 0 - 9 ; ] * [ m K ] / g, "" ) ; // Clean ANSI colors
63-
64- if (
65- ! filterLinks . some ( ( f ) => s . startsWith ( f ) ) &&
66- ! activeTunnels . has ( pid )
67- ) {
68- clearInterval ( yesInterval ) ;
69- activeTunnels . set ( pid , {
70- url : s ,
71- ts : Date . now ( ) ,
72- } ) ;
73- }
74- } ) ;
75- }
76- } ) ;
55+ const output = data . toString ( ) ;
56+ const urlRegex = / h t t p s : \/ \/ [ ^ \s " ' < > ] + / g;
57+ const foundLinks = output . match ( urlRegex ) ;
58+
59+ if ( foundLinks ) {
60+ foundLinks . forEach ( ( link ) => {
61+ const s = link . trim ( ) . replace ( / \x1B \[ [ 0 - 9 ; ] * [ m K ] / g, "" ) ;
62+
63+ if ( ! filterLinks . some ( ( f ) => s . startsWith ( f ) ) ) {
64+ // If it's a new URL, update the Map regardless of whether the PID exists
65+ const currentData = activeTunnels . get ( pid ) ;
66+
67+ if ( ! currentData || currentData . url !== s ) {
68+ console . log ( `[Update] PID ${ pid } is now at ${ s } ` ) ;
69+
70+ clearInterval ( yesInterval ) ; // Stop the "yes" spam once we have a link
71+
72+ activeTunnels . set ( pid , {
73+ url : s ,
74+ ts : Date . now ( ) ,
75+ } ) ;
76+ }
77+ }
78+ } ) ;
79+ }
80+ } ) ;
7781
7882 child . stdin . on ( 'error' , ( err ) => {
7983 if ( err . code === 'EPIPE' ) {
0 commit comments