From a897c4c2840f6e5fff16cf46e873007ac6f957ab Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Fri, 21 Mar 2025 02:53:21 +0300 Subject: [PATCH] Update validate.ts --- scripts/db/validate.ts | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/scripts/db/validate.ts b/scripts/db/validate.ts index eccae4ff..78b2e87b 100644 --- a/scripts/db/validate.ts +++ b/scripts/db/validate.ts @@ -79,15 +79,13 @@ async function main() { for (const [i, row] of rowsCopy.entries()) { fileErrors = fileErrors.concat(validateChannelId(row, i)) fileErrors = fileErrors.concat(validateChannelBroadcastArea(row, i)) + fileErrors = fileErrors.concat(validateReplacedBy(row, i)) fileErrors = fileErrors.concat( checkValue(i, row, 'id', 'subdivision', buffer.get('subdivisions')) ) fileErrors = fileErrors.concat( checkValue(i, row, 'id', 'categories', buffer.get('categories')) ) - fileErrors = fileErrors.concat( - checkValue(i, row, 'id', 'replaced_by', buffer.get('channels')) - ) fileErrors = fileErrors.concat( checkValue(i, row, 'id', 'languages', buffer.get('languages')) ) @@ -102,9 +100,7 @@ async function main() { for (const [i, row] of rowsCopy.entries()) { fileErrors = fileErrors.concat(validateChannel(row.channel, i)) fileErrors = fileErrors.concat(validateTimezones(row, i)) - fileErrors = fileErrors.concat( - checkValue(i, row, 'id', 'replaced_by', buffer.get('channels')) - ) + fileErrors = fileErrors.concat(validateReplacedBy(row, i)) } break case 'blocklist': @@ -198,6 +194,30 @@ function checkValue( return errors } +function validateReplacedBy(row: { [key: string]: string }, i: number) { + const errors = new Collection() + + if (!row.replaced_by) return errors + + const channels = buffer.get('channels') + const feeds = buffer.get('feeds') + const [channelId, feedId] = row.replaced_by.split('@') + + if (channels.missing(channelId)) { + errors.push({ + line: i + 2, + message: `"${row.id}" has an invalid replaced_by "${row.replaced_by}"` + }) + } else if (feedId && feeds.missing(channelId + feedId)) { + errors.push({ + line: i + 2, + message: `"${row.id}" has an invalid replaced_by "${row.replaced_by}"` + }) + } + + return errors +} + function validateChannel(channelId: string, i: number) { const errors = new Collection() const channels = buffer.get('channels')