mirror of
https://github.com/iptv-org/iptv
synced 2026-09-06 12:01:57 -04:00
Update validate.ts
This commit is contained in:
@@ -17,7 +17,7 @@ const { body, labels } = program.opts()
|
|||||||
|
|
||||||
const logsStorage = new Storage(LOGS_DIR)
|
const logsStorage = new Storage(LOGS_DIR)
|
||||||
let streams = new Collection<Stream>()
|
let streams = new Collection<Stream>()
|
||||||
const errors: string[] = []
|
let errors: string[] = []
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const logger = new Logger()
|
const logger = new Logger()
|
||||||
@@ -30,53 +30,24 @@ async function main() {
|
|||||||
|
|
||||||
const data = parseIssueBody(body)
|
const data = parseIssueBody(body)
|
||||||
if (labels.includes('streams:add')) {
|
if (labels.includes('streams:add')) {
|
||||||
if (data.missing('stream_id')) {
|
const streamId = data.getString('stream_id')
|
||||||
|
if (!streamId) {
|
||||||
errors.push('The request is missing the "Stream ID"')
|
errors.push('The request is missing the "Stream ID"')
|
||||||
done()
|
done()
|
||||||
|
} else {
|
||||||
|
errors = errors.concat(validateStreamId(streamId))
|
||||||
}
|
}
|
||||||
|
|
||||||
const streamUrl = data.getString('stream_url')
|
const streamUrl = data.getString('stream_url')
|
||||||
if (!streamUrl) {
|
if (!streamUrl) {
|
||||||
errors.push('The request is missing the "Stream URL"')
|
errors.push('The request is missing the "Stream URL"')
|
||||||
done()
|
done()
|
||||||
} else if (!isURI(streamUrl) || !hasValidDomain(streamUrl)) {
|
} else {
|
||||||
errors.push(`The stream URL "${streamUrl}" is invalid`)
|
errors = errors.concat(validateStreamUrl(streamUrl))
|
||||||
}
|
|
||||||
|
|
||||||
if (streams.includes((_stream: Stream) => _stream.url === streamUrl)) {
|
if (streams.includes((_stream: Stream) => _stream.url === streamUrl)) {
|
||||||
errors.push(`The stream with the URL "${streamUrl}" is already included in the playlists`)
|
errors.push(`The stream with the URL "${streamUrl}" is already included in the playlists`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const streamId = data.getString('stream_id') || ''
|
|
||||||
const [channelId, feedId] = streamId.split('@')
|
|
||||||
|
|
||||||
const channel: sdk.Models.Channel | undefined = apiData.channelsKeyById.get(channelId)
|
|
||||||
if (!channel) {
|
|
||||||
errors.push(`There is no channel with the ID "${channelId}" in the database`)
|
|
||||||
done()
|
|
||||||
}
|
|
||||||
|
|
||||||
const blocklistRecords: sdk.Models.BlocklistRecord[] | undefined =
|
|
||||||
apiData.blocklistRecordsGroupedByChannel.get(channelId)
|
|
||||||
if (blocklistRecords) {
|
|
||||||
blocklistRecords.forEach((record: sdk.Models.BlocklistRecord) => {
|
|
||||||
if (record.reason === 'dmca') {
|
|
||||||
errors.push(
|
|
||||||
`The channel "${channelId}" has been added to our blocklist due to the claims of the copyright holder: ${record.ref}`
|
|
||||||
)
|
|
||||||
} else if (record.reason === 'nsfw') {
|
|
||||||
errors.push(
|
|
||||||
`The channel "${channelId}" has been added to our blocklist due to NSFW content: ${record.ref}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const feed: sdk.Models.Feed | undefined = apiData.feedsKeyByStreamId.get(streamId)
|
|
||||||
if (!feed) {
|
|
||||||
errors.push(
|
|
||||||
`There is no feed with the ID "${feedId}" for the "${channelId}" channel in the database`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else if (labels.includes('streams:remove')) {
|
} else if (labels.includes('streams:remove')) {
|
||||||
const streamUrls = data.getString('stream_url') || ''
|
const streamUrls = data.getString('stream_url') || ''
|
||||||
@@ -89,9 +60,7 @@ async function main() {
|
|||||||
.split(/\r?\n/)
|
.split(/\r?\n/)
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.forEach((link: string) => {
|
.forEach((link: string) => {
|
||||||
if (!isURI(link) || !hasValidDomain(link)) {
|
errors = errors.concat(validateStreamUrl(link))
|
||||||
errors.push(`The stream URL "${link}" is invalid`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const found: Stream = streams.first((_stream: Stream) => _stream.url === link.trim())
|
const found: Stream = streams.first((_stream: Stream) => _stream.url === link.trim())
|
||||||
if (!found) {
|
if (!found) {
|
||||||
@@ -104,20 +73,78 @@ async function main() {
|
|||||||
if (!streamUrl) {
|
if (!streamUrl) {
|
||||||
errors.push('The request is missing the "Stream URL"')
|
errors.push('The request is missing the "Stream URL"')
|
||||||
done()
|
done()
|
||||||
} else if (!isURI(streamUrl) || !hasValidDomain(streamUrl)) {
|
} else {
|
||||||
errors.push(`The stream URL "${streamUrl}" is invalid`)
|
const stream: Stream = streams.first((_stream: Stream) => _stream.url === streamUrl)
|
||||||
done()
|
if (!stream) {
|
||||||
|
errors.push(`The stream with the URL "${streamUrl}" is missing from the playlists`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream: Stream = streams.first((_stream: Stream) => _stream.url === streamUrl)
|
const streamId = data.getString('stream_id')
|
||||||
if (!stream) {
|
if (streamId) {
|
||||||
errors.push(`The stream with the URL "${streamUrl}" is missing from the playlists`)
|
errors = errors.concat(validateStreamId(streamId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validateStreamUrl(streamUrl: string): string[] {
|
||||||
|
const errors: string[] = []
|
||||||
|
|
||||||
|
if (!isURI(streamUrl) || !hasValidDomain(streamUrl)) {
|
||||||
|
errors.push(`The stream URL "${streamUrl}" is invalid`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateStreamId(streamId: string): string[] {
|
||||||
|
const errors: string[] = []
|
||||||
|
|
||||||
|
const [channelId, feedId] = streamId.split('@')
|
||||||
|
|
||||||
|
if (!channelId) {
|
||||||
|
errors.push('The request is missing the channel ID')
|
||||||
|
return errors
|
||||||
|
} else {
|
||||||
|
const channel: sdk.Models.Channel | undefined = apiData.channelsKeyById.get(channelId)
|
||||||
|
if (!channel) {
|
||||||
|
errors.push(`There is no channel with the ID "${channelId}" in the database`)
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const blocklistRecords: sdk.Models.BlocklistRecord[] | undefined =
|
||||||
|
apiData.blocklistRecordsGroupedByChannel.get(channelId)
|
||||||
|
if (blocklistRecords) {
|
||||||
|
blocklistRecords.forEach((record: sdk.Models.BlocklistRecord) => {
|
||||||
|
if (record.reason === 'dmca') {
|
||||||
|
errors.push(
|
||||||
|
`The channel "${channelId}" has been added to our blocklist due to the claims of the copyright holder: ${record.ref}`
|
||||||
|
)
|
||||||
|
} else if (record.reason === 'nsfw') {
|
||||||
|
errors.push(
|
||||||
|
`The channel "${channelId}" has been added to our blocklist due to NSFW content: ${record.ref}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!feedId) {
|
||||||
|
errors.push('The request is missing the feed ID')
|
||||||
|
} else {
|
||||||
|
const feed: sdk.Models.Feed | undefined = apiData.feedsKeyByStreamId.get(streamId)
|
||||||
|
if (!feed) {
|
||||||
|
errors.push(
|
||||||
|
`There is no feed with the ID "${feedId}" for the "${channelId}" channel in the database`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
function done() {
|
function done() {
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
let message = 'The request contains error(s):'
|
let message = 'The request contains error(s):'
|
||||||
|
|||||||
Reference in New Issue
Block a user