mirror of
https://github.com/iptv-org/database.git
synced 2024-11-22 02:44:10 -05:00
Update validate.js
This commit is contained in:
parent
0677c90002
commit
6fa99c38a7
1 changed files with 31 additions and 11 deletions
|
@ -3,6 +3,7 @@ const { program } = require('commander')
|
||||||
const schemes = require('./schemes')
|
const schemes = require('./schemes')
|
||||||
const chalk = require('chalk')
|
const chalk = require('chalk')
|
||||||
const Joi = require('joi')
|
const Joi = require('joi')
|
||||||
|
const _ = require('lodash')
|
||||||
|
|
||||||
program.argument('[filepath]', 'Path to file to validate').parse(process.argv)
|
program.argument('[filepath]', 'Path to file to validate').parse(process.argv)
|
||||||
|
|
||||||
|
@ -58,20 +59,39 @@ async function main() {
|
||||||
logger.error(chalk.red(`\nError: ${err.message}`))
|
logger.error(chalk.red(`\nError: ${err.message}`))
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
categories = categories.map(c => c.id)
|
|
||||||
|
|
||||||
data.forEach((row, i) => {
|
if (categories.length) {
|
||||||
if (
|
categories = _.keyBy(categories, 'id')
|
||||||
categories.length &&
|
data.forEach((row, i) => {
|
||||||
row.categories.length &&
|
row.categories.forEach(category => {
|
||||||
intersection(categories, row.categories).length !== row.categories.length
|
if (!categories[category]) {
|
||||||
) {
|
fileErrors.push({
|
||||||
fileErrors.push({
|
line: i + 2,
|
||||||
line: i + 2,
|
message: `"${row.id}" has the wrong category "${category}"`
|
||||||
message: `"${row.id}" has the wrong categories "${row.categories.join(';')}"`
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let languages = await csv.fromFile('data/languages.csv').catch(err => {
|
||||||
|
logger.error(chalk.red(`\nError: ${err.message}`))
|
||||||
|
process.exit(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (languages.length) {
|
||||||
|
languages = _.keyBy(languages, 'code')
|
||||||
|
data.forEach((row, i) => {
|
||||||
|
row.languages.forEach(language => {
|
||||||
|
if (!languages[language]) {
|
||||||
|
fileErrors.push({
|
||||||
|
line: i + 2,
|
||||||
|
message: `"${row.id}" has the wrong language "${language}"`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
} else if (filename === 'blocklist') {
|
} else if (filename === 'blocklist') {
|
||||||
let channels = await csv.fromFile('data/channels.csv').catch(err => {
|
let channels = await csv.fromFile('data/channels.csv').catch(err => {
|
||||||
logger.error(chalk.red(`\nError: ${err.message}`))
|
logger.error(chalk.red(`\nError: ${err.message}`))
|
||||||
|
|
Loading…
Reference in a new issue