Ensuring affiliate URL is valid.

This commit is contained in:
DebaucheryLibrarian 2026-01-30 22:39:34 +01:00
parent bff3bc6a0b
commit 5ae3b5d91c
2 changed files with 22 additions and 10 deletions

View File

@ -1,16 +1,20 @@
import format from 'template-format';
function getWatchUrl(scene) {
if (scene.url) {
return scene.url;
}
try {
if (scene.url) {
return new URL(scene.url).href;
}
if (scene.channel && (scene.channel.isIndependent || scene.channel.type === 'network')) {
return scene.channel.url;
}
if (scene.channel && (scene.channel.isIndependent || scene.channel.type === 'network')) {
return new URL(scene.channel.url).href;
}
if (scene.network) {
return scene.network.url;
if (scene.network) {
return new URL(scene.network.url).href;
}
} catch (_error) {
// invalid URL
}
return null;
@ -73,8 +77,16 @@ export function getAffiliateSceneUrl(scene) {
return watchUrl;
}
function getEntityUrl(entity) {
try {
return new URL(entity.url || entity.parent?.url).href;
} catch (_error) {
return null;
}
}
export function getAffiliateEntityUrl(entity) {
const entityUrl = entity.url || entity.parent?.url;
const entityUrl = getEntityUrl(entity);
if (!entityUrl) {
return null;

View File

@ -39,7 +39,7 @@ export function curateEntity(entity, context) {
},
};
curatedEntity.affiliateUrl = getAffiliateEntityUrl(curatedEntity, curatedEntity);
curatedEntity.affiliateUrl = getAffiliateEntityUrl(curatedEntity);
return curatedEntity;
}