iptv-database/scripts/schemes/channels.ts

71 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-12-05 06:25:53 -05:00
import BaseJoi from 'joi'
import JoiDate from '@joi/date'
import path from 'path'
import url from 'url'
2023-10-06 22:14:21 -04:00
2024-12-05 06:25:53 -05:00
const Joi = BaseJoi.extend(JoiDate)
export default {
2023-10-06 22:14:21 -04:00
id: Joi.string()
.regex(/^[A-Za-z0-9]+\.[a-z]{2}$/)
.required(),
name: Joi.string()
2023-11-30 05:14:37 -05:00
.regex(/^[a-z0-9-!:&.+'/»#%°$@?|¡–\s_—]+$/i)
2023-10-06 22:14:21 -04:00
.required(),
alt_names: Joi.array().items(
Joi.string()
.regex(/^[^",]+$/)
.invalid(Joi.ref('name'))
),
network: Joi.string()
.regex(/^[^",]+$/)
.allow(null),
owners: Joi.array().items(Joi.string().regex(/^[^",]+$/)),
country: Joi.string()
.regex(/^[A-Z]{2}$/)
.required(),
subdivision: Joi.string()
.regex(/^[A-Z]{2}-[A-Z0-9]{1,3}$/)
.allow(null),
city: Joi.string()
.regex(/^[^",]+$/)
.allow(null),
broadcast_area: Joi.array().items(
Joi.string()
2023-11-19 02:23:27 -05:00
.regex(/^(s\/[A-Z]{2}-[A-Z0-9]{1,3}|c\/[A-Z]{2}|r\/[A-Z0-9]{2,7})$/)
2023-10-06 22:14:21 -04:00
.required()
),
languages: Joi.array().items(
Joi.string()
.regex(/^[a-z]{3}$/)
.required()
),
categories: Joi.array().items(Joi.string().regex(/^[a-z]+$/)),
is_nsfw: Joi.boolean().strict().required(),
launched: Joi.date().format('YYYY-MM-DD').raw().allow(null),
closed: Joi.date().format('YYYY-MM-DD').raw().allow(null).greater(Joi.ref('launched')),
replaced_by: Joi.string()
.regex(/^[A-Za-z0-9]+\.[a-z]{2}$/)
.allow(null),
website: Joi.string()
2023-10-30 15:12:32 -04:00
.regex(/,/, { invert: true })
2023-10-06 22:14:21 -04:00
.uri({
scheme: ['http', 'https']
})
.allow(null),
logo: Joi.string()
2023-10-30 15:12:32 -04:00
.regex(/,/, { invert: true })
2023-10-06 22:14:21 -04:00
.uri({
scheme: ['https']
})
.custom((value, helper) => {
const ext = path.extname(url.parse(value).pathname)
if (!ext || /(\.png|\.jpeg|\.jpg)/i.test(ext)) {
return true
} else {
return helper.message(`"logo" has an invalid file extension "${ext}"`)
}
})
.required()
}