Merge pull request #48471 from iptv-org/patch-2026.08.2

Patch 2026.08.2
This commit is contained in:
LPhilip1999
2026-08-16 10:24:23 +08:00
committed by GitHub
3 changed files with 78 additions and 50 deletions
+75 -48
View File
@@ -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):'
@@ -1,2 +1,2 @@
The request contains error(s): The request contains error(s):
- There is no feed with the ID "undefined" for the "ManoramaNews.in" channel in the database - The request is missing the feed ID
@@ -1,2 +1,3 @@
The request contains error(s): The request contains error(s):
- The stream with the URL "https://livestream.telvue.com/templeuni1/f7b44cfafd5c52223d5498196c8a2e7b.sdp/playlist.m3u8" is missing from the playlists - The stream with the URL "https://livestream.telvue.com/templeuni1/f7b44cfafd5c52223d5498196c8a2e7b.sdp/playlist.m3u8" is missing from the playlists
- There is no channel with the ID "boo.us" in the database