From da0bccd291a6ad0af60053607874d1338fda688f Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Sat, 7 Oct 2023 05:57:36 +0300 Subject: [PATCH] Update update.ts --- scripts/db/update.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/db/update.ts b/scripts/db/update.ts index 8f616008..c80a577e 100644 --- a/scripts/db/update.ts +++ b/scripts/db/update.ts @@ -25,11 +25,11 @@ async function main() { await blockChannels({ loader }) await unblockChannels({ loader }) - channels = channels.orderBy([(channel: Channel) => channel.id], ['asc']) + channels = sortBy(channels, 'id') const channelsOutput = new CSV({ items: channels }).toString() await dataStorage.save('channels.csv', channelsOutput) - blocklist = blocklist.orderBy([record => record.channel.toLowerCase()], ['asc']) + blocklist = sortBy(blocklist, 'channel') const blocklistOutput = new CSV({ items: blocklist }).toString() await dataStorage.save('blocklist.csv', blocklistOutput) @@ -39,6 +39,18 @@ async function main() { main() +function sortBy(channels: Collection, key: string) { + const items = channels.all().sort((a, b) => { + const normA = a[key].toLowerCase() + const normB = b[key].toLowerCase() + if (normA < normB) return -1 + if (normA > normB) return 1 + return 0 + }) + + return new Collection(items) +} + async function removeChannels({ loader }: { loader: IssueLoader }) { const issues = await loader.load({ labels: ['channels:remove,approved'] }) issues.forEach((issue: Issue) => {