From 44fb9f603623e3f8e9aa36a810bc845bee2994b7 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Wed, 3 Sep 2025 06:22:48 +0300 Subject: [PATCH] Check for network connection --- scripts/commands/playlist/test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/commands/playlist/test.ts b/scripts/commands/playlist/test.ts index 590c2e7111..0e3b42d729 100644 --- a/scripts/commands/playlist/test.ts +++ b/scripts/commands/playlist/test.ts @@ -6,6 +6,7 @@ import { program } from 'commander' import { eachLimit } from 'async-es' import chalk from 'chalk' import os from 'node:os' +import dns from 'node:dns' import type { DataLoaderData } from '../../types/dataLoader' import type { DataProcessorData } from '../../types/dataProcessor' @@ -36,6 +37,11 @@ const logger = new Logger() const tester = new StreamTester() async function main() { + if (await isOffline()) { + logger.error(chalk.red('Internet connection is required for the script to work')) + return + } + logger.info('loading data from api...') const processor = new DataProcessor() const dataStorage = new Storage(DATA_DIR) @@ -158,3 +164,12 @@ function onFinish(error: any) { process.exit(0) } + +async function isOffline() { + return new Promise((resolve, reject) => { + dns.lookup('info.cern.ch', err => { + if (err) resolve(true) + reject(false) + }) + }).catch(() => {}) +}