lbry-desktop/ui/util/geoRestriction.js
infinite-persistence 7504cf07b3
Geoblock: fix anonymous claims passing through
My bad, added an unnecessary check in the previous change that shorted the logic too early.

Accessing an object using 'null' or 'undefined' as the key won't cause trouble (and is expected in this case), so just suppress flow instead of fixing it using
  `channelId && geoBlockLists.livestreams[channelId]`

https://github.com/OdyseeTeam/odysee-frontend/issues/1100#issuecomment-1138928520
2022-05-27 12:51:47 +08:00

45 lines
1.5 KiB
JavaScript

// @flow
import { getChannelIdFromClaim, isStreamPlaceholderClaim } from 'util/claim';
/**
* Returns the geo restriction for the given claim, or null if not restricted.
*
* @param claim
* @param locale
* @param geoBlockLists
* @returns {{id: string, trigger?: string, reason?: string, message?:
* string}|null}
*/
export function getGeoRestrictionForClaim(claim: ?StreamClaim, locale: LocaleInfo, geoBlockLists: ?GBL) {
if (locale && geoBlockLists && claim) {
const claimId: ?string = claim.claim_id;
const channelId: ?string = getChannelIdFromClaim(claim);
let geoConfig: ?GeoConfig;
// --- livestreams
if (isStreamPlaceholderClaim(claim) && geoBlockLists.livestreams) {
// $FlowIgnore: null key is fine
geoConfig = geoBlockLists.livestreams[channelId] || geoBlockLists.livestreams[claimId];
}
// --- videos (actually, everything else)
else if (geoBlockLists.videos) {
// $FlowIgnore: null key is fine
geoConfig = geoBlockLists.videos[channelId] || geoBlockLists.videos[claimId];
}
if (geoConfig) {
const specials = geoConfig.specials || [];
const countries = geoConfig.countries || [];
const continents = geoConfig.continents || [];
return (
specials.find((x: GeoRestriction) => x.id === 'EU-ONLY' && locale.is_eu_member) ||
countries.find((x: GeoRestriction) => x.id === locale.country) ||
continents.find((x: GeoRestriction) => x.id === locale.continent)
);
}
}
return null;
}