mirror of
https://github.com/iptv-org/iptv
synced 2025-12-18 11:27:34 -05:00
Check for network connection
This commit is contained in:
@@ -6,6 +6,7 @@ import { program } from 'commander'
|
|||||||
import { eachLimit } from 'async-es'
|
import { eachLimit } from 'async-es'
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
import os from 'node:os'
|
import os from 'node:os'
|
||||||
|
import dns from 'node:dns'
|
||||||
import type { DataLoaderData } from '../../types/dataLoader'
|
import type { DataLoaderData } from '../../types/dataLoader'
|
||||||
import type { DataProcessorData } from '../../types/dataProcessor'
|
import type { DataProcessorData } from '../../types/dataProcessor'
|
||||||
|
|
||||||
@@ -36,6 +37,11 @@ const logger = new Logger()
|
|||||||
const tester = new StreamTester()
|
const tester = new StreamTester()
|
||||||
|
|
||||||
async function main() {
|
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...')
|
logger.info('loading data from api...')
|
||||||
const processor = new DataProcessor()
|
const processor = new DataProcessor()
|
||||||
const dataStorage = new Storage(DATA_DIR)
|
const dataStorage = new Storage(DATA_DIR)
|
||||||
@@ -158,3 +164,12 @@ function onFinish(error: any) {
|
|||||||
|
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isOffline() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
dns.lookup('info.cern.ch', err => {
|
||||||
|
if (err) resolve(true)
|
||||||
|
reject(false)
|
||||||
|
})
|
||||||
|
}).catch(() => {})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user