@@ -233,6 +233,9 @@ function connect() {
233233 } ;
234234}
235235
236+ window . activeTls = [ ] ;
237+ window . certStatusCache = { } ;
238+
236239function sendReq ( obj ) {
237240 if ( ws && ws . readyState === WebSocket . OPEN ) {
238241 ws . send ( JSON . stringify ( obj ) ) ;
@@ -325,6 +328,7 @@ function handleResponse(data) {
325328 // We don't fetch get_tls again because we update window.activeTls synchronously.
326329 break ;
327330 case 'cert_status' :
331+ window . certStatusCache [ data . subdomain + ':' + data . port ] = data ;
328332 let span = document . getElementById ( `cert-status-${ data . subdomain } ` ) ;
329333 if ( certCheckTimers [ data . subdomain ] ) {
330334 clearTimeout ( certCheckTimers [ data . subdomain ] ) ;
@@ -419,9 +423,6 @@ function renderZoneTable() {
419423 if ( ! currentZone ) return ;
420424
421425 certCheckQueue = [ ] ;
422- Object . values ( certCheckTimers ) . forEach ( t => clearTimeout ( t ) ) ;
423- certCheckTimers = { } ;
424- concurrentChecks = 0 ;
425426 window . renderedTlsFqdns = new Set ( ) ;
426427 const records = currentZone . records . filter ( r => r . type !== 'comment' && r . type !== 'macro' ) ;
427428
@@ -457,10 +458,22 @@ function renderZoneTable() {
457458 window . renderedTlsFqdns . add ( fqdn ) ;
458459 let activeConfig = window . activeTls ? window . activeTls . find ( t => t . fqdn === fqdn ) : null ;
459460 let portVal = activeConfig ? activeConfig . port : '' ;
461+ let cacheKey = fqdn + ':' + portVal ;
462+ let cached = window . certStatusCache [ cacheKey ] ;
463+ let initStatus = '' ;
464+ let initColor = '#aaa' ;
465+ if ( cached ) {
466+ initStatus = cached . msg ;
467+ initColor = ( cached . status === 'ok' ) ? '#34d399' : '#f87171' ;
468+ } else if ( certCheckTimers [ fqdn ] ) {
469+ initStatus = 'Checking...' ;
470+ }
471+
460472 tlsTd = `<td class="ext-tls-cell">
461- <div style="display:flex; align-items:center; justify-content:flex-start; gap: 0.5rem ">
473+ <div style="display:block; text-align: right; ">
462474 <input type="number" class="tls-port ext-port" data-fqdn="${ fqdn } " value="${ portVal } " maxlength="5" placeholder="Port" style="width:70px; background: rgba(0,0,0,0.2); color:#fff; border:1px solid #444; border-radius:4px; padding:2px;">
463- <span id="cert-status-${ fqdn } " class="cert-status" style="font-size:0.8em; color:#aaa;"></span>
475+ <br>
476+ <span id="cert-status-${ fqdn } " class="cert-status" style="font-size:0.8em; color:${ initColor } ;">${ initStatus } </span>
464477 </div>
465478 </td>` ;
466479 }
@@ -483,21 +496,32 @@ function renderZoneTable() {
483496 sendReq ( { req : 'delete_tls' , domain : currentDomain , subdomain : fqdn } ) ;
484497 if ( window . activeTls ) window . activeTls = window . activeTls . filter ( x => x . fqdn !== fqdn ) ;
485498 document . getElementById ( `cert-status-${ fqdn } ` ) . innerText = '' ;
499+ Object . keys ( window . certStatusCache ) . forEach ( k => {
500+ if ( k . startsWith ( fqdn + ':' ) ) delete window . certStatusCache [ k ] ;
501+ } ) ;
486502 } else {
487503 sendReq ( { req : 'create_tls' , domain : currentDomain , subdomain : fqdn , port : pnum } ) ;
488504 if ( ! window . activeTls ) window . activeTls = [ ] ;
489505 let exist = window . activeTls . find ( x => x . fqdn === fqdn ) ;
490506 if ( exist ) exist . port = pnum ;
491507 else window . activeTls . push ( { fqdn : fqdn , port : pnum } ) ;
492-
508+
509+ if ( certCheckTimers [ fqdn ] ) {
510+ clearTimeout ( certCheckTimers [ fqdn ] ) ;
511+ delete certCheckTimers [ fqdn ] ;
512+ concurrentChecks = Math . max ( 0 , concurrentChecks - 1 ) ;
513+ }
514+ delete window . certStatusCache [ fqdn + ':' + pnum ] ;
493515 certCheckQueue . push ( { fqdn : fqdn , port : pnum } ) ;
494516 processCertQueue ( ) ;
495517 }
496518 } ;
497519
498520 if ( portInput . value ) {
499521 let pnum = parseInt ( portInput . value , 10 ) ;
500- certCheckQueue . push ( { fqdn : fqdn , port : pnum } ) ;
522+ if ( ! window . certStatusCache [ fqdn + ':' + pnum ] && ! certCheckTimers [ fqdn ] ) {
523+ certCheckQueue . push ( { fqdn : fqdn , port : pnum } ) ;
524+ }
501525 }
502526 }
503527
0 commit comments