Use a set to deduplicate subscriptions

This commit is contained in:
Kevin Raoofi 2020-11-11 14:50:32 -05:00
parent 30c93c2c4f
commit 8341291497

View file

@ -2,7 +2,7 @@ import { Fragment, h, render } from 'preact';
import { useState } from 'preact/hooks'; import { useState } from 'preact/hooks';
import { getSettingsAsync, redirectDomains } from '../common/settings'; import { getSettingsAsync, redirectDomains } from '../common/settings';
import { YTDescriptor, getFileContent, ytService } from '../common/yt'; import { getFileContent, ytService } from '../common/yt';
/** /**
* Parses the subscription file and queries the API for lbry channels * Parses the subscription file and queries the API for lbry channels
@ -14,10 +14,8 @@ async function lbryChannelsFromFile(file: File) {
const ext = file.name.split('.').pop()?.toLowerCase(); const ext = file.name.split('.').pop()?.toLowerCase();
const content = await getFileContent(file); const content = await getFileContent(file);
const ids: YTDescriptor[] = (ext === 'xml' || ext == 'opml' ? ytService.readOpml(content) : ytService.readJson(content)) const ids = new Set((ext === 'xml' || ext == 'opml' ? ytService.readOpml(content) : ytService.readJson(content)))
.map(id => ({ id, type: 'channel' })); const lbryUrls = await ytService.resolveById(...Array.from(ids).map(id => ({ id, type: 'channel' } as const)));
const lbryUrls = await ytService.resolveById(...ids);
const { redirect } = await getSettingsAsync('redirect'); const { redirect } = await getSettingsAsync('redirect');
const urlPrefix = redirectDomains[redirect].prefix; const urlPrefix = redirectDomains[redirect].prefix;
return lbryUrls.map(channel => urlPrefix + channel); return lbryUrls.map(channel => urlPrefix + channel);