From 4092ce26167049c517d166cacffae4e38bc37dac Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sun, 12 Dec 2021 23:35:10 -0500 Subject: [PATCH] Fix async causing shadow banned segments to always appear --- src/routes/getSkipSegments.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/routes/getSkipSegments.ts b/src/routes/getSkipSegments.ts index 547e8d0..6c7c587 100644 --- a/src/routes/getSkipSegments.ts +++ b/src/routes/getSkipSegments.ts @@ -32,15 +32,15 @@ async function prepareCategorySegments(req: Request, videoID: VideoID, category: [videoID, segment.timeSubmitted, service]) as { hashedIP: HashedIP }[]; } - //if this isn't their ip, don't send it to them - return cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted]?.some(async (shadowHiddenSegment) => { - if (cache.userHashedIP === undefined) { - //hash the IP only if it's strictly necessary - cache.userHashedIP = await getHashCache((getIP(req) + config.globalSalt) as IPAddress); - } + const ipList = cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted]; - return shadowHiddenSegment.hashedIP === cache.userHashedIP; - }) ?? false; + if (ipList?.length > 0 && cache.userHashedIP === undefined) { + //hash the IP only if it's strictly necessary + cache.userHashedIP = await getHashCache((getIP(req) + config.globalSalt) as IPAddress); + } + //if this isn't their ip, don't send it to them + return cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted]?.some( + (shadowHiddenSegment) => shadowHiddenSegment.hashedIP === cache.userHashedIP) ?? false; })); const filteredSegments = segments.filter((_, index) => shouldFilter[index]);