Added improved affiliate URL logic for entities.
This commit is contained in:
parent
e28904b791
commit
2380342328
|
|
@ -168,6 +168,9 @@ const entityUrl = (() => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return entity.affiliateUrl || entity.url;
|
||||||
|
|
||||||
|
/*
|
||||||
// affiliate might be inherited, only use full URL when directly associated
|
// affiliate might be inherited, only use full URL when directly associated
|
||||||
if (entity.affiliate?.url && entity.affiliate.entityId === entity.id) {
|
if (entity.affiliate?.url && entity.affiliate.entityId === entity.id) {
|
||||||
return entity.affiliate.url;
|
return entity.affiliate.url;
|
||||||
|
|
@ -183,6 +186,7 @@ const entityUrl = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity.url;
|
return entity.url;
|
||||||
|
*/
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
function getWatchUrl(scene) {
|
||||||
|
if (scene.url) {
|
||||||
|
return scene.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scene.channel && (scene.channel.isIndependent || scene.channel.type === 'network')) {
|
||||||
|
return scene.channel.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scene.network) {
|
||||||
|
return scene.network.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAffiliateSceneUrl(scene) {
|
||||||
|
const watchUrl = getWatchUrl(scene);
|
||||||
|
|
||||||
|
if (!watchUrl) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!scene.affiliate) {
|
||||||
|
return watchUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scene.affiliate.url?.includes('/track')
|
||||||
|
&& scene.affiliate.parameters.scene !== false
|
||||||
|
&& (!scene.channel.isIndependent || scene.channel.id === scene.affiliate.entityId)) { // standard NATS redirect
|
||||||
|
const { pathname, search } = new URL(watchUrl);
|
||||||
|
|
||||||
|
return `${scene.affiliate.url}${pathname.replace(/^\/trial/, '')}${search}`; // replace needed for Jules Jordan, verify behavior on other sites
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scene.affiliate.parameters.query) { // used by e.g. Bang
|
||||||
|
const newParams = new URLSearchParams({
|
||||||
|
...Object.fromEntries(new URL(watchUrl).searchParams),
|
||||||
|
...Object.fromEntries(new URLSearchParams(scene.affiliate.parameters.query)),
|
||||||
|
});
|
||||||
|
|
||||||
|
return `${watchUrl}?${newParams.toString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return watchUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAffiliateEntityUrl(entity) {
|
||||||
|
if (!entity.affiliate) {
|
||||||
|
return entity.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.id === entity.affiliate.entityId) {
|
||||||
|
return entity.affiliate.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.isIndependent) {
|
||||||
|
return entity.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.affiliate.url?.includes('/track')
|
||||||
|
&& entity.affiliate.parameters.channel !== false) {
|
||||||
|
const { pathname, search } = new URL(entity.url);
|
||||||
|
|
||||||
|
return `${entity.affiliate.url}${pathname.replace(/^\/trial/, '')}${search}`; // replace needed for Jules Jordan, verify behavior on other sites
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.affiliate.parameters.query) { // used by e.g. Bang
|
||||||
|
const newParams = new URLSearchParams({
|
||||||
|
...Object.fromEntries(new URL(entity.url).searchParams),
|
||||||
|
...Object.fromEntries(new URLSearchParams(entity.affiliate.parameters.query)),
|
||||||
|
});
|
||||||
|
|
||||||
|
return `${entity.url}?${newParams.toString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return entity.url;
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ import knex from './knex.js';
|
||||||
import redis from './redis.js';
|
import redis from './redis.js';
|
||||||
import initLogger from './logger.js';
|
import initLogger from './logger.js';
|
||||||
import entityPrefixes from './entities-prefixes.js';
|
import entityPrefixes from './entities-prefixes.js';
|
||||||
|
import { getAffiliateEntityUrl } from './affiliates.js';
|
||||||
|
|
||||||
const logger = initLogger();
|
const logger = initLogger();
|
||||||
|
|
||||||
|
|
@ -10,7 +11,7 @@ export function curateEntity(entity, context) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const curatedEntity = {
|
||||||
id: entity.id,
|
id: entity.id,
|
||||||
name: entity.name,
|
name: entity.name,
|
||||||
slug: entity.slug,
|
slug: entity.slug,
|
||||||
|
|
@ -29,7 +30,7 @@ export function curateEntity(entity, context) {
|
||||||
id: entity.affiliate.id,
|
id: entity.affiliate.id,
|
||||||
entityId: entity.affiliate.entity_id,
|
entityId: entity.affiliate.entity_id,
|
||||||
url: entity.affiliate.url,
|
url: entity.affiliate.url,
|
||||||
parameters: entity.affiliate.parameters,
|
parameters: entity.affiliate.parameters || {},
|
||||||
} : null,
|
} : null,
|
||||||
...context?.append?.[entity.id],
|
...context?.append?.[entity.id],
|
||||||
alerts: {
|
alerts: {
|
||||||
|
|
@ -37,6 +38,10 @@ export function curateEntity(entity, context) {
|
||||||
multi: context?.alerts?.filter((alert) => !alert.is_only).flatMap((alert) => alert.alert_ids) || [],
|
multi: context?.alerts?.filter((alert) => !alert.is_only).flatMap((alert) => alert.alert_ids) || [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
curatedEntity.affiliateUrl = getAffiliateEntityUrl(curatedEntity, curatedEntity);
|
||||||
|
|
||||||
|
return curatedEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchEntities(options = {}) {
|
export async function fetchEntities(options = {}) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import util from 'util'; /* eslint-disable-line no-unused-vars */
|
|
||||||
import { MerkleJson } from 'merkle-json';
|
import { MerkleJson } from 'merkle-json';
|
||||||
|
|
||||||
import { knexQuery as knex, knexOwner, knexManticore } from './knex.js';
|
import { knexQuery as knex, knexOwner, knexManticore } from './knex.js';
|
||||||
|
|
@ -15,57 +14,11 @@ import escape from '../utils/escape-manticore.js';
|
||||||
import promiseProps from '../utils/promise-props.js';
|
import promiseProps from '../utils/promise-props.js';
|
||||||
import initLogger from './logger.js';
|
import initLogger from './logger.js';
|
||||||
import { curateRevision } from './revisions.js';
|
import { curateRevision } from './revisions.js';
|
||||||
|
import { getAffiliateSceneUrl } from './affiliates.js';
|
||||||
|
|
||||||
const logger = initLogger();
|
const logger = initLogger();
|
||||||
const mj = new MerkleJson();
|
const mj = new MerkleJson();
|
||||||
|
|
||||||
function getWatchUrl(scene) {
|
|
||||||
if (scene.url) {
|
|
||||||
return scene.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scene.channel && (scene.channel.isIndependent || scene.channel.type === 'network')) {
|
|
||||||
return scene.channel.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scene.network) {
|
|
||||||
return scene.network.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAffiliateUrl(scene) {
|
|
||||||
const watchUrl = getWatchUrl(scene);
|
|
||||||
|
|
||||||
if (!watchUrl) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!scene.affiliate) {
|
|
||||||
return watchUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scene.affiliate.url?.includes('/track')
|
|
||||||
&& scene.affiliate.parameters.scene !== false
|
|
||||||
&& (!scene.channel.isIndependent || scene.channel.id === scene.affiliate.entityId)) { // standard NATS redirect
|
|
||||||
const { pathname, search } = new URL(watchUrl);
|
|
||||||
|
|
||||||
return `${scene.affiliate.url}${pathname.replace(/^\/trial/, '')}${search}`; // replace needed for Jules Jordan, verify behavior on other sites
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scene.affiliate.parameters.query) { // used by e.g. Bang
|
|
||||||
const newParams = new URLSearchParams({
|
|
||||||
...Object.fromEntries(new URL(watchUrl).searchParams),
|
|
||||||
...Object.fromEntries(new URLSearchParams(scene.affiliate.parameters.query)),
|
|
||||||
});
|
|
||||||
|
|
||||||
return `${watchUrl}?${newParams.toString()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return watchUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
function curateScene(rawScene, assets) {
|
function curateScene(rawScene, assets) {
|
||||||
if (!rawScene) {
|
if (!rawScene) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -164,7 +117,7 @@ function curateScene(rawScene, assets) {
|
||||||
isNew: assets.lastBatchId === rawScene.created_batch_id,
|
isNew: assets.lastBatchId === rawScene.created_batch_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
curatedScene.watchUrl = getAffiliateUrl(curatedScene);
|
curatedScene.watchUrl = getAffiliateSceneUrl(curatedScene);
|
||||||
|
|
||||||
return curatedScene;
|
return curatedScene;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
static
2
static
|
|
@ -1 +1 @@
|
||||||
Subproject commit 323fb4c9220637d48a1f7516bbfbfafdfdb45ccc
|
Subproject commit 8ba0b203fad2fa85624590a2547c1ae71f8fb481
|
||||||
Loading…
Reference in New Issue