feat(PublicIp): Add PublicIp service and refactor SmartNetwork to use it; remove public-ip dependency; update exports, docs and dependencies

This commit is contained in:
2025-09-12 13:30:09 +00:00
parent ac3b501adf
commit 806606c9b9
9 changed files with 2796 additions and 2144 deletions

View File

@@ -1,5 +1,6 @@
import * as plugins from './smartnetwork.plugins.js';
import { CloudflareSpeed } from './smartnetwork.classes.cloudflarespeed.js';
import { PublicIp } from './smartnetwork.classes.publicip.js';
import { getLogger } from './logging.js';
import { NetworkError } from './errors.js';
import * as stats from './helpers/stats.js';
@@ -259,10 +260,10 @@ export class SmartNetwork {
* Lookup public IPv4 and IPv6
*/
public async getPublicIps(): Promise<{ v4: string | null; v6: string | null }> {
const fetcher = async () => ({
v4: await plugins.publicIp.publicIpv4({ timeout: 1000, onlyHttps: true }).catch(() => null),
v6: await plugins.publicIp.publicIpv6({ timeout: 1000, onlyHttps: true }).catch(() => null),
});
const fetcher = async () => {
const publicIp = new PublicIp({ timeout: 1000 });
return publicIp.getPublicIps();
};
if (this.options.cacheTtl && this.options.cacheTtl > 0) {
return this.getCached('publicIps', fetcher);
}