Skip to content

Commit e2f7cc5

Browse files
committed
feat: add handling for empty hosts and user inbounds in FormatHostsService
- Implemented logic to return formatted hosts with remarks when no hosts are provided and active user inbounds exist. - Added handling for cases where the user has no active inbounds, returning formatted hosts with appropriate remarks. - Enhanced the structure of the returned formatted hosts to include default values for various fields.
1 parent 50789dc commit e2f7cc5

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/modules/subscription-template/generators/format-hosts.service.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,74 @@ export class FormatHostsService {
8383
return formattedHosts;
8484
}
8585

86+
if (hosts.length === 0 && user.activeUserInbounds.length > 0) {
87+
const emptyHostRemarks = [
88+
'→ Remnawave',
89+
'→ Did you forget to add hosts?',
90+
'→ No hosts found',
91+
];
92+
93+
emptyHostRemarks.forEach((remark) => {
94+
formattedHosts.push({
95+
remark,
96+
address: '0.0.0.0',
97+
port: 0,
98+
protocol: 'trojan',
99+
path: '',
100+
host: '',
101+
tls: 'tls',
102+
sni: '',
103+
alpn: '',
104+
publicKey: '',
105+
fingerprint: '',
106+
shortId: '',
107+
spiderX: '',
108+
network: 'tcp',
109+
password: {
110+
trojanPassword: '00000',
111+
vlessPassword: randomUUID(),
112+
ssPassword: '00000',
113+
},
114+
});
115+
});
116+
117+
return formattedHosts;
118+
}
119+
120+
if (user.activeUserInbounds.length === 0) {
121+
const emptyHostRemarks = [
122+
'→ Remnawave',
123+
'→ User has no active inbounds',
124+
'→ No active inbounds found',
125+
];
126+
127+
emptyHostRemarks.forEach((remark) => {
128+
formattedHosts.push({
129+
remark,
130+
address: '0.0.0.0',
131+
port: 0,
132+
protocol: 'trojan',
133+
path: '',
134+
host: '',
135+
tls: 'tls',
136+
sni: '',
137+
alpn: '',
138+
publicKey: '',
139+
fingerprint: '',
140+
shortId: '',
141+
spiderX: '',
142+
network: 'tcp',
143+
password: {
144+
trojanPassword: '00000',
145+
vlessPassword: randomUUID(),
146+
ssPassword: '00000',
147+
},
148+
});
149+
});
150+
151+
return formattedHosts;
152+
}
153+
86154
for (const inputHost of hosts) {
87155
const inbound = config.getInbound(inputHost.inboundTag.tag);
88156

0 commit comments

Comments
 (0)