forked from DebaucheryLibrarian/traxxx
Improved actor scraping and display.
This commit is contained in:
@@ -1,17 +1,50 @@
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
function curateActor(actor, release) {
|
||||
function curateActor(actor, release, curateActorRelease) {
|
||||
if (!actor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const curatedActor = {
|
||||
...actor,
|
||||
origin: actor.originCountry && {
|
||||
country: actor.originCountry,
|
||||
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));
|
||||
|
||||
curatedActor.photos = Object.values(photos.reduce((acc, photo) => ({ ...acc, [photo.hash]: photo }), {}));
|
||||
}
|
||||
|
||||
if (release && release.date && curatedActor.birthdate) {
|
||||
curatedActor.ageThen = dayjs(release.date).diff(actor.birthdate, 'year');
|
||||
}
|
||||
|
||||
if (actor.releases) {
|
||||
curatedActor.releases = actor.releases.map(actorRelease => curateActorRelease(actorRelease.release));
|
||||
}
|
||||
|
||||
return curatedActor;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user