filter out duplicate embeds

This commit is contained in:
Jorrin
2024-04-03 18:34:04 +02:00
parent 3d7e8aacec
commit 2f4e76747d
2 changed files with 10 additions and 7 deletions

View File

@@ -59,12 +59,14 @@ export async function scrapeInvidualSource(
if (!output) throw new Error('output is null'); if (!output) throw new Error('output is null');
// filter output with only valid embeds that are not disabled // filter output with only valid embeds that are not disabled, and remove duplicates
output.embeds = output.embeds.filter((embed) => { output.embeds = output.embeds
const e = list.embeds.find((v) => v.id === embed.embedId); .filter((embed) => {
if (!e || e.disabled) return false; const e = list.embeds.find((v) => v.id === embed.embedId);
return true; if (!e || e.disabled) return false;
}); return true;
})
.filter((v, i, a) => a.findIndex((t) => t.embedId === v.embedId) === i);
if ((!output.stream || output.stream.length === 0) && output.embeds.length === 0) if ((!output.stream || output.stream.length === 0) && output.embeds.length === 0)
throw new NotFoundError('No streams found'); throw new NotFoundError('No streams found');

View File

@@ -112,12 +112,13 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
}; };
} }
// filter disabled and run embed scrapers on listed embeds // filter disabled, filter out duplicates, run embed scrapers on listed embeds
const sortedEmbeds = output.embeds const sortedEmbeds = output.embeds
.filter((embed) => { .filter((embed) => {
const e = list.embeds.find((v) => v.id === embed.embedId); const e = list.embeds.find((v) => v.id === embed.embedId);
return e && !e.disabled; return e && !e.disabled;
}) })
.filter((v, i, a) => a.findIndex((t) => t.embedId === v.embedId) === i)
.sort((a, b) => embedIds.indexOf(a.embedId) - embedIds.indexOf(b.embedId)); .sort((a, b) => embedIds.indexOf(a.embedId) - embedIds.indexOf(b.embedId));
if (sortedEmbeds.length > 0) { if (sortedEmbeds.length > 0) {