Drastic actor page redesign. Storing one avatar per actor, other profile photos as 'photo' role; no longer assuming first photo is avatar.

This commit is contained in:
2019-11-28 05:36:22 +01:00
parent 884ef248e4
commit 4be508b388
300 changed files with 1110 additions and 213 deletions

View File

@@ -9,7 +9,7 @@ const whereOr = require('./utils/where-or');
const { createActorMediaDirectory, storeAvatars } = require('./media');
async function curateActor(actor) {
const [aliases, avatars, social] = await Promise.all([
const [aliases, photos, social] = await Promise.all([
knex('actors').where({ alias_for: actor.id }),
knex('media')
.where({ domain: 'actors', target_id: actor.id })
@@ -41,14 +41,17 @@ async function curateActor(actor) {
: null,
ethnicity: actor.ethnicity,
height: actor.height,
weight: actor.weight,
bust: actor.bust,
waist: actor.waist,
hip: actor.hip,
naturalBoobs: actor.natural_boobs,
aliases: aliases.map(({ name }) => name),
slug: actor.slug,
avatars,
avatar: photos.find(photo => photo.role === 'avatar'),
photos: photos.filter(photo => photo.role === 'photo'),
social,
scrapedAt: actor.scraped_at,
};
}
@@ -97,27 +100,32 @@ function curateActorEntry(actor, scraped, scrapeSuccess) {
return curatedActor;
}
function curateSocialEntry(url, actor) {
function curateSocialEntry(url, actorId) {
const { hostname, origin, pathname } = new URL(url);
const platform = ['twitter', 'instagram', 'snapchat', 'modelhub', 'youtube'].find(platformName => hostname.match(platformName));
const platform = ['facebook', 'twitter', 'instagram', 'tumblr', 'snapchat', 'amazon', 'youtube'].find(platformName => hostname.match(platformName));
return {
url: `${origin}${pathname}`,
platform,
domain: 'actors',
target_id: actor.id,
target_id: actorId,
};
}
function curateSocialEntries(urls, actor) {
async function curateSocialEntries(urls, actorId) {
if (!urls) {
return [];
}
return urls.reduce((acc, url) => {
const socialEntry = curateSocialEntry(url, actor);
const existingSocialLinks = await knex('social').where({
domain: 'actors',
target_id: actorId,
});
if (acc.some(entry => socialEntry.url === entry.url)) {
return urls.reduce((acc, url) => {
const socialEntry = curateSocialEntry(url, actorId);
if (acc.some(entry => socialEntry.url === entry.url) || existingSocialLinks.some(entry => socialEntry.url === entry.url)) {
// prevent duplicates
return acc;
}
@@ -141,15 +149,10 @@ async function fetchActors(queryObject) {
return curateActors(releases);
}
async function storeSocialLinks(actor) {
const existingSocialLinks = await knex('social').where({
domain: 'actors',
target_id: actor.id,
});
async function storeSocialLinks(urls, actorId) {
const curatedSocialEntries = await curateSocialEntries(urls, actorId);
const newSocialLinks = actor.social.filter(url => !existingSocialLinks.some(existingLink => url === existingLink.url));
await knex('social').insert(curateSocialEntries(newSocialLinks, actor));
await knex('social').insert(curatedSocialEntries);
}
async function storeActor(actor, scraped = false, scrapeSuccess = false) {
@@ -159,7 +162,7 @@ async function storeActor(actor, scraped = false, scrapeSuccess = false) {
.insert(curatedActor)
.returning('*');
await storeSocialLinks({ ...actor, ...actorEntry });
await storeSocialLinks(actor.social, actorEntry.id);
console.log(`Added new entry for actor '${actor.name}'`);
@@ -174,7 +177,7 @@ async function updateActor(actor, scraped = false, scrapeSuccess = false) {
.update(curatedActor)
.returning('*');
await storeSocialLinks({ ...actor, ...curatedActor, ...actorEntry });
await storeSocialLinks(actor.social, actor.id);
console.log(`Updated entry for actor '${actor.name}'`);
@@ -239,7 +242,6 @@ async function scrapeActors(actorNames) {
return;
}
if (actorEntry && profile) {
await createActorMediaDirectory(profile, actorEntry);