1- import  {  Injectable ,  Logger  }  from  '@nestjs/common' ; 
1+ import  {  Injectable ,  Logger ,   OnModuleInit  }  from  '@nestjs/common' ; 
22import  {  ConfigService  }  from  '@nestjs/config' ; 
33
44import  {  URL_TYPE  }  from  '@unraid/shared/network.model.js' ; 
@@ -15,15 +15,19 @@ import { StaticRemoteAccessService } from './static-remote-access.service.js';
1515import  {  UpnpRemoteAccessService  }  from  './upnp-remote-access.service.js' ; 
1616
1717@Injectable ( ) 
18- export  class  DynamicRemoteAccessService  { 
18+ export  class  DynamicRemoteAccessService  implements   OnModuleInit   { 
1919    private  readonly  logger  =  new  Logger ( DynamicRemoteAccessService . name ) ; 
2020
2121    constructor ( 
22-         private  readonly  configService : ConfigService < ConfigType > , 
22+         private  readonly  configService : ConfigService < ConfigType ,   true > , 
2323        private  readonly  staticRemoteAccessService : StaticRemoteAccessService , 
2424        private  readonly  upnpRemoteAccessService : UpnpRemoteAccessService 
2525    )  { } 
2626
27+     async  onModuleInit ( )  { 
28+         await  this . initRemoteAccess ( ) ; 
29+     } 
30+ 
2731    /** 
2832     * Get the current state of dynamic remote access 
2933     */ 
@@ -60,6 +64,7 @@ export class DynamicRemoteAccessService {
6064            type : url . type  ??  URL_TYPE . WAN , 
6165        } ; 
6266        this . configService . set ( 'connect.dynamicRemoteAccess.allowedUrl' ,  newAllowed ) ; 
67+         this . logger . verbose ( `setAllowedUrl: ${ JSON . stringify ( newAllowed ,  null ,  2 ) }  ) ; 
6368    } 
6469
6570    private  setErrorMessage ( error : string )  { 
@@ -75,6 +80,7 @@ export class DynamicRemoteAccessService {
7580        type : DynamicRemoteAccessType ; 
7681    } )  { 
7782        try  { 
83+             this . logger . verbose ( 'enableDynamicRemoteAccess' ) ; 
7884            await  this . stopRemoteAccess ( ) ; 
7985            if  ( input . allowedUrl )  { 
8086                this . setAllowedUrl ( { 
@@ -98,6 +104,7 @@ export class DynamicRemoteAccessService {
98104     * @param  type The new dynamic remote access type to set 
99105     */ 
100106    private  async  setType ( type : DynamicRemoteAccessType ) : Promise < void >  { 
107+         this . logger . verbose ( `setType: ${ type }  ) ; 
101108        // Update the config first 
102109        this . configService . set ( 'connect.config.dynamicRemoteAccessType' ,  type ) ; 
103110
@@ -138,4 +145,14 @@ export class DynamicRemoteAccessService {
138145        this . clearPing ( ) ; 
139146        this . clearError ( ) ; 
140147    } 
148+ 
149+     private  async  initRemoteAccess ( )  { 
150+         const  enabled  =  this . configService . get ( 'connect.config.wanaccess' ,  {  infer : true  } ) ; 
151+         if  ( ! enabled )  { 
152+             return ; 
153+         } 
154+ 
155+         const  type  =  this . configService . get ( 'connect.config.dynamicRemoteAccessType' ,  {  infer : true  } ) ; 
156+         await  this . setType ( type ) ; 
157+     } 
141158} 
0 commit comments