138 lines
4.2 KiB
JavaScript
138 lines
4.2 KiB
JavaScript
import dayjs from 'dayjs';
|
|
|
|
function curateActor(actor, release) {
|
|
if (!actor) {
|
|
return null;
|
|
}
|
|
|
|
const curatedActor = {
|
|
...actor,
|
|
height: actor.heightMetric && {
|
|
metric: actor.heightMetric,
|
|
imperial: actor.heightImperial,
|
|
},
|
|
weight: actor.weightMetric && {
|
|
metric: actor.weightMetric,
|
|
imperial: actor.weightImperial,
|
|
},
|
|
origin: actor.birthCountry && {
|
|
city: actor.birthCity,
|
|
state: actor.birthState,
|
|
country: actor.birthCountry,
|
|
},
|
|
residence: actor.residenceCountry && {
|
|
city: actor.residenceCity,
|
|
state: actor.residenceState,
|
|
country: actor.residenceCountry,
|
|
},
|
|
scrapedAt: new Date(actor.createdAt),
|
|
updatedAt: new Date(actor.updatedAt),
|
|
};
|
|
|
|
if (actor.profiles && actor.profiles.length > 0) {
|
|
const photos = actor.profiles
|
|
.map(profile => profile.avatar)
|
|
.filter(avatar => avatar && (!curatedActor.avatar || avatar.hash !== curatedActor.avatar.hash));
|
|
|
|
const descriptions = actor.profiles.reduce((acc, profile) => ({
|
|
...acc,
|
|
...(profile.description && {
|
|
[profile.descriptionHash]: {
|
|
text: profile.description,
|
|
network: profile.network,
|
|
site: profile.site,
|
|
},
|
|
}),
|
|
}), {});
|
|
|
|
curatedActor.photos = Object.values(photos.reduce((acc, photo) => ({ ...acc, [photo.hash]: photo }), {}));
|
|
curatedActor.descriptions = Object.values(descriptions);
|
|
}
|
|
|
|
if (release && release.date && curatedActor.birthdate) {
|
|
curatedActor.ageThen = dayjs(release.date).diff(actor.birthdate, 'year');
|
|
}
|
|
|
|
if (actor.aliasFor) {
|
|
curatedActor.aliasFor = curateActor(curatedActor.aliasFor);
|
|
}
|
|
|
|
return curatedActor;
|
|
}
|
|
|
|
function curateRelease(release) {
|
|
const curatedRelease = {
|
|
...release,
|
|
actors: [],
|
|
poster: release.poster && release.poster.media,
|
|
tags: release.tags ? release.tags.map(({ tag }) => tag) : [],
|
|
};
|
|
|
|
if (release.site) curatedRelease.network = release.site.network;
|
|
if (release.scenes) curatedRelease.scenes = release.scenes.map(({ scene }) => curateRelease(scene));
|
|
if (release.movies) curatedRelease.movies = release.movies.map(({ movie }) => curateRelease(movie));
|
|
if (release.photos) curatedRelease.photos = release.photos.map(({ media }) => media);
|
|
if (release.covers) curatedRelease.covers = release.covers.map(({ media }) => media);
|
|
if (release.trailer) curatedRelease.trailer = release.trailer.media;
|
|
if (release.teaser) curatedRelease.teaser = release.teaser.media;
|
|
if (release.actors) curatedRelease.actors = release.actors.map(({ actor }) => curateActor(actor, curatedRelease));
|
|
if (release.movieTags && release.movieTags.length > 0) curatedRelease.tags = release.movieTags.map(({ tag }) => tag);
|
|
if (release.movieActors && release.movieActors.length > 0) curatedRelease.actors = release.movieActors.map(({ actor }) => curateActor(actor, curatedRelease));
|
|
|
|
return curatedRelease;
|
|
}
|
|
|
|
function curateSite(site, network) {
|
|
const curatedSite = {
|
|
id: site.id,
|
|
name: site.name,
|
|
slug: site.slug,
|
|
url: site.url,
|
|
independent: site.independent,
|
|
};
|
|
|
|
if (site.releases) curatedSite.releases = site.releases.map(release => curateRelease(release));
|
|
if (site.network || network) curatedSite.network = site.network || network;
|
|
if (site.tags) curatedSite.tags = site.tags.map(({ tag }) => tag);
|
|
|
|
return curatedSite;
|
|
}
|
|
|
|
function curateNetwork(network, releases) {
|
|
const curatedNetwork = {
|
|
id: network.id,
|
|
name: network.name,
|
|
slug: network.slug,
|
|
url: network.url,
|
|
networks: [],
|
|
};
|
|
|
|
if (network.parent) curatedNetwork.parent = curateNetwork(network.parent);
|
|
if (network.sites) curatedNetwork.sites = network.sites.map(site => curateSite(site, curatedNetwork));
|
|
if (network.networks) curatedNetwork.networks = network.networks.map(subNetwork => curateNetwork(subNetwork));
|
|
if (network.studios) curatedNetwork.studios = network.studios;
|
|
if (releases) curatedNetwork.releases = releases.map(release => curateRelease(release));
|
|
|
|
return curatedNetwork;
|
|
}
|
|
|
|
function curateTag(tag) {
|
|
const curatedTag = {
|
|
...tag,
|
|
};
|
|
|
|
if (tag.releases) curatedTag.releases = tag.releases.map(({ release }) => curateRelease(release));
|
|
if (tag.photos) curatedTag.photos = tag.photos.map(({ media }) => media);
|
|
if (tag.poster) curatedTag.poster = tag.poster.media;
|
|
|
|
return curatedTag;
|
|
}
|
|
|
|
export {
|
|
curateActor,
|
|
curateRelease,
|
|
curateSite,
|
|
curateNetwork,
|
|
curateTag,
|
|
};
|