mirror of
https://github.com/iptv-org/database.git
synced 2025-05-09 19:20:01 -04:00
Update scripts
This commit is contained in:
parent
37b4197fb2
commit
6244ba7adb
54 changed files with 2020 additions and 1145 deletions
66
scripts/validators/feedValidator.ts
Normal file
66
scripts/validators/feedValidator.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { ValidatorProps } from '../types/validator'
|
||||
import { Collection } from '@freearhey/core'
|
||||
import { Validator } from './validator'
|
||||
import { Feed } from '../models'
|
||||
import { DataLoaderData } from '../types/dataLoader'
|
||||
|
||||
export class FeedValidator extends Validator {
|
||||
constructor(props: ValidatorProps) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
validate(feed: Feed): Collection {
|
||||
const {
|
||||
channelsKeyById,
|
||||
countriesKeyByCode,
|
||||
subdivisionsKeyByCode,
|
||||
regionsKeyByCode,
|
||||
timezonesKeyById
|
||||
}: DataLoaderData = this.data
|
||||
|
||||
let errors = new Collection()
|
||||
|
||||
const joiResults = feed.getSchema().validate(feed.data(), { abortEarly: false })
|
||||
if (joiResults.error) {
|
||||
joiResults.error.details.forEach((detail: { message: string }) => {
|
||||
errors.add({ line: feed.getLine(), message: `${feed.getStreamId()}: ${detail.message}` })
|
||||
})
|
||||
}
|
||||
|
||||
if (!feed.hasValidId()) {
|
||||
errors.add({
|
||||
line: feed.getLine(),
|
||||
message: `"${feed.getStreamId()}" id "${feed.id}" must be derived from the name "${
|
||||
feed.name
|
||||
}"`
|
||||
})
|
||||
}
|
||||
|
||||
if (!feed.hasValidChannelId(channelsKeyById)) {
|
||||
errors.add({
|
||||
line: feed.getLine(),
|
||||
message: `"${feed.getStreamId()}" has the wrong channel "${feed.channelId}"`
|
||||
})
|
||||
}
|
||||
|
||||
if (
|
||||
!feed.hasValidBroadcastAreaCodes(countriesKeyByCode, subdivisionsKeyByCode, regionsKeyByCode)
|
||||
) {
|
||||
errors.add({
|
||||
line: feed.getLine(),
|
||||
message: `"${feed.getStreamId()}" has the wrong broadcast_area "${feed.broadcastAreaCodes.join(
|
||||
';'
|
||||
)}"`
|
||||
})
|
||||
}
|
||||
|
||||
if (!feed.hasValidTimezones(timezonesKeyById)) {
|
||||
errors.add({
|
||||
line: feed.getLine(),
|
||||
message: `"${feed.getStreamId()}" has the wrong timezones "${feed.timezoneIds.join(';')}"`
|
||||
})
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue