Fix async causing shadow banned segments to always appear

This commit is contained in:
Ajay Ramachandran
2021-12-12 23:35:10 -05:00
parent a0720329d0
commit 4092ce2616

View File

@@ -32,15 +32,15 @@ async function prepareCategorySegments(req: Request, videoID: VideoID, category:
[videoID, segment.timeSubmitted, service]) as { hashedIP: HashedIP }[]; [videoID, segment.timeSubmitted, service]) as { hashedIP: HashedIP }[];
} }
//if this isn't their ip, don't send it to them const ipList = cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted];
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);
}
return shadowHiddenSegment.hashedIP === cache.userHashedIP; if (ipList?.length > 0 && cache.userHashedIP === undefined) {
}) ?? false; //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]); const filteredSegments = segments.filter((_, index) => shouldFilter[index]);