Skip to content

Commit c4bdf07

Browse files
committed
init remote access on api boot & add log traces
1 parent 90a8880 commit c4bdf07

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

packages/unraid-api-plugin-connect/src/service/dynamic-remote-access.service.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, Logger } from '@nestjs/common';
1+
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
33

44
import { URL_TYPE } from '@unraid/shared/network.model.js';
@@ -15,15 +15,19 @@ import { StaticRemoteAccessService } from './static-remote-access.service.js';
1515
import { 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

Comments
 (0)