iptv-database/scripts/db/schemes/channels.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-04-11 23:31:51 +03:00
const Joi = require('joi').extend(require('@joi/date'))
2022-04-08 22:59:38 +03:00
const path = require('path')
2022-02-12 05:55:50 +03:00
module.exports = {
id: Joi.string()
.regex(/^[A-Za-z0-9]+\.[a-z]{2}$/)
.required(),
name: Joi.string()
2022-06-02 21:06:08 +03:00
.regex(/^[\sa-z\u00C0-\u00FF0-9-čâộăšİ!:&.+'/»#%°$@?()¡]+$/i)
2022-02-12 05:55:50 +03:00
.required(),
2022-03-01 12:26:55 +03:00
native_name: Joi.string()
.regex(/^[^",]+$/)
2022-05-25 00:37:36 +03:00
.invalid(Joi.ref('name'))
2022-03-01 12:26:55 +03:00
.allow(null),
2022-02-12 05:55:50 +03:00
network: Joi.string().allow(null),
country: Joi.string()
.regex(/^[A-Z]{2}$/)
.required(),
subdivision: Joi.string()
.regex(/^[A-Z]{2}-[A-Z0-9]{1,3}$/)
.allow(null),
2022-02-17 00:03:39 +03:00
city: Joi.string()
.regex(/^[\sa-zA-Z\u00C0-\u00FF0-9'-]+$/)
.allow(null),
2022-02-12 05:55:50 +03:00
broadcast_area: Joi.array().items(
2022-02-19 06:18:41 +03:00
Joi.string()
.regex(/^(s\/[A-Z]{2}-[A-Z0-9]{1,3}|c\/[A-Z]{2}|r\/[A-Z0-9]{3,7})$/)
.required()
),
languages: Joi.array().items(
Joi.string()
.regex(/^[a-z]{3}$/)
.required()
2022-02-12 05:55:50 +03:00
),
categories: Joi.array().items(Joi.string().regex(/^[a-z]+$/)),
2022-02-16 22:58:26 +03:00
is_nsfw: Joi.boolean().strict().required(),
2022-04-11 23:31:51 +03:00
launched: Joi.date().format('YYYY-MM-DD').raw().allow(null),
closed: Joi.date().format('YYYY-MM-DD').raw().allow(null),
2022-04-21 21:47:00 +03:00
replaced_by: Joi.string()
.regex(/^[A-Za-z0-9]+\.[a-z]{2}$/)
.allow(null),
2022-02-20 07:05:31 +03:00
website: Joi.string()
.uri({
scheme: ['http', 'https']
})
.allow(null),
2022-02-19 19:10:21 +03:00
logo: Joi.string()
.uri({
scheme: ['https']
})
2022-04-08 22:59:38 +03:00
.custom((value, helper) => {
const ext = path.extname(value)
if (!ext || /(\.png|\.jpeg|\.jpg)/i.test(ext)) {
return true
} else {
return helper.message(`"logo" has an invalid file extension "${ext}"`)
}
})
2022-04-29 16:29:16 +03:00
.required()
2022-02-12 05:55:50 +03:00
}