2020-01-07 03:23:28 +00:00
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
2020-05-26 23:40:10 +00:00
|
|
|
function curateActor(actor, release) {
|
2020-05-17 23:22:56 +00:00
|
|
|
if (!actor) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const curatedActor = {
|
|
|
|
...actor,
|
2020-05-17 23:22:56 +00:00
|
|
|
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,
|
2020-05-14 02:26:05 +00:00
|
|
|
},
|
2020-05-17 23:22:56 +00:00
|
|
|
scrapedAt: new Date(actor.createdAt),
|
|
|
|
updatedAt: new Date(actor.updatedAt),
|
2020-05-14 02:26:05 +00:00
|
|
|
};
|
2019-12-16 04:30:25 +00:00
|
|
|
|
2020-12-30 01:23:43 +00:00
|
|
|
if (actor.profiles) {
|
2020-05-17 23:22:56 +00:00
|
|
|
const photos = actor.profiles
|
2020-06-29 01:55:10 +00:00
|
|
|
.map(profile => ({ entity: profile.entity, ...profile.avatar }))
|
|
|
|
.filter(avatar => avatar.id && (!curatedActor.avatar || avatar.hash !== curatedActor.avatar.hash));
|
2020-05-17 23:22:56 +00:00
|
|
|
|
2020-05-19 02:46:49 +00:00
|
|
|
const descriptions = actor.profiles.reduce((acc, profile) => ({
|
|
|
|
...acc,
|
|
|
|
...(profile.description && {
|
|
|
|
[profile.descriptionHash]: {
|
|
|
|
text: profile.description,
|
2020-06-28 02:22:19 +00:00
|
|
|
entity: profile.entity,
|
2020-05-19 02:46:49 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
}), {});
|
|
|
|
|
2020-05-17 23:22:56 +00:00
|
|
|
curatedActor.photos = Object.values(photos.reduce((acc, photo) => ({ ...acc, [photo.hash]: photo }), {}));
|
2020-05-19 02:46:49 +00:00
|
|
|
curatedActor.descriptions = Object.values(descriptions);
|
2020-05-17 23:22:56 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (release && release.date && curatedActor.birthdate) {
|
|
|
|
curatedActor.ageThen = dayjs(release.date).diff(actor.birthdate, 'year');
|
|
|
|
}
|
2020-01-07 03:23:28 +00:00
|
|
|
|
2020-05-26 02:11:29 +00:00
|
|
|
if (actor.aliasFor) {
|
|
|
|
curatedActor.aliasFor = curateActor(curatedActor.aliasFor);
|
|
|
|
}
|
|
|
|
|
2021-03-21 02:23:58 +00:00
|
|
|
if (actor.stashes) {
|
|
|
|
curatedActor.stashes = actor.stashes.filter(Boolean).map(stash => curateStash(stash.stash || stash)); // eslint-disable-line no-use-before-define
|
|
|
|
}
|
|
|
|
|
2021-03-15 02:30:47 +00:00
|
|
|
curatedActor.stashes = actor.stashes?.map(stash => stash.stash || stash) || [];
|
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return curatedActor;
|
2019-12-16 04:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function curateRelease(release) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const curatedRelease = {
|
|
|
|
...release,
|
|
|
|
actors: [],
|
|
|
|
poster: release.poster && release.poster.media,
|
2020-08-10 19:39:55 +00:00
|
|
|
tags: release.tags ? release.tags.map(tag => tag.tag || tag) : [],
|
2020-05-14 02:26:05 +00:00
|
|
|
};
|
|
|
|
|
2021-02-02 02:47:06 +00:00
|
|
|
if (release.scenes) curatedRelease.scenes = release.scenes.filter(Boolean).map(({ scene }) => curateRelease(scene));
|
|
|
|
if (release.movies) curatedRelease.movies = release.movies.filter(Boolean).map(({ movie }) => curateRelease(movie));
|
2021-02-26 23:37:22 +00:00
|
|
|
if (release.chapters) curatedRelease.chapters = release.chapters.filter(Boolean).map(chapter => curateRelease(chapter));
|
2021-02-02 02:47:06 +00:00
|
|
|
if (release.photos) curatedRelease.photos = release.photos.filter(Boolean).map(photo => photo.media || photo);
|
|
|
|
if (release.covers) curatedRelease.covers = release.covers.filter(Boolean).map(({ media }) => media);
|
2020-05-14 02:26:05 +00:00
|
|
|
if (release.trailer) curatedRelease.trailer = release.trailer.media;
|
|
|
|
if (release.teaser) curatedRelease.teaser = release.teaser.media;
|
2021-02-02 02:47:06 +00:00
|
|
|
if (release.actors) curatedRelease.actors = release.actors.filter(Boolean).map(actor => curateActor(actor.actor || actor, curatedRelease));
|
2021-03-06 23:01:02 +00:00
|
|
|
if (release.directors) curatedRelease.directors = release.directors.filter(Boolean).map(director => curateActor(director.director || director, curatedRelease));
|
2021-02-02 02:47:06 +00:00
|
|
|
if (release.movieTags && release.movieTags.length > 0) curatedRelease.tags = release.movieTags.filter(Boolean).map(({ tag }) => tag);
|
|
|
|
if (release.movieActors && release.movieActors.length > 0) curatedRelease.actors = release.movieActors.filter(Boolean).map(({ actor }) => curateActor(actor, curatedRelease));
|
2021-03-21 02:23:58 +00:00
|
|
|
if (release.stashes) curatedRelease.stashes = release.stashes.filter(Boolean).map(stash => curateStash(stash.stash || stash)); // eslint-disable-line no-use-before-define
|
2020-05-14 02:26:05 +00:00
|
|
|
|
2020-08-20 02:57:38 +00:00
|
|
|
if (release.productionLocation) {
|
|
|
|
curatedRelease.productionLocation = {
|
|
|
|
raw: release.productionLocation,
|
|
|
|
city: release.productionCity,
|
|
|
|
state: release.productionState,
|
|
|
|
country: release.productionCountry,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return curatedRelease;
|
2019-12-16 04:30:25 +00:00
|
|
|
}
|
|
|
|
|
2020-06-27 00:57:30 +00:00
|
|
|
function curateEntity(entity, parent, releases) {
|
|
|
|
const curatedEntity = {
|
|
|
|
...entity,
|
|
|
|
children: [],
|
|
|
|
};
|
|
|
|
|
2020-07-05 02:10:35 +00:00
|
|
|
if (entity.tags) curatedEntity.tags = entity.tags.map(({ tag }) => tag);
|
|
|
|
|
2020-06-28 01:58:16 +00:00
|
|
|
if (entity.children) {
|
|
|
|
if (entity.children.nodes) {
|
|
|
|
curatedEntity.children = entity.children.nodes.map(childEntity => curateEntity(childEntity, curatedEntity));
|
|
|
|
}
|
|
|
|
|
|
|
|
curatedEntity.childrenTotal = entity.children.totalCount;
|
|
|
|
}
|
|
|
|
|
2020-06-27 00:57:30 +00:00
|
|
|
if (entity.parent || parent) curatedEntity.parent = curateEntity(entity.parent || parent);
|
|
|
|
if (releases) curatedEntity.releases = releases.map(release => curateRelease(release));
|
|
|
|
|
|
|
|
return curatedEntity;
|
|
|
|
}
|
|
|
|
|
2019-12-19 03:42:50 +00:00
|
|
|
function curateTag(tag) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const curatedTag = {
|
|
|
|
...tag,
|
|
|
|
};
|
2019-12-19 03:42:50 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (tag.releases) curatedTag.releases = tag.releases.map(({ release }) => curateRelease(release));
|
2021-06-27 22:05:24 +00:00
|
|
|
if (tag.banners) curatedTag.banners = tag.banners.map(({ banner }) => banner);
|
2020-05-14 02:26:05 +00:00
|
|
|
if (tag.photos) curatedTag.photos = tag.photos.map(({ media }) => media);
|
|
|
|
if (tag.poster) curatedTag.poster = tag.poster.media;
|
2019-12-19 03:42:50 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return curatedTag;
|
2019-12-19 03:42:50 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 03:54:43 +00:00
|
|
|
function curateStash(stash) {
|
2021-03-15 02:30:47 +00:00
|
|
|
const curatedStash = stash;
|
2021-03-14 03:54:43 +00:00
|
|
|
|
|
|
|
if (stash.scenes) {
|
|
|
|
curatedStash.scenes = stash.scenes.map(item => ({
|
|
|
|
...item,
|
|
|
|
scene: curateRelease(item.scene),
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stash.actors) {
|
|
|
|
curatedStash.actors = stash.actors.map(item => ({
|
|
|
|
...item,
|
|
|
|
actor: curateActor(item.actor),
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return curatedStash;
|
|
|
|
}
|
|
|
|
|
2021-04-04 22:48:03 +00:00
|
|
|
function curateAlert(alert) {
|
|
|
|
if (!alert) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const curatedAlert = alert;
|
|
|
|
|
|
|
|
if (alert.actors) {
|
|
|
|
curatedAlert.actors = alert.actors.map(actor => curateActor(actor.actor || actor));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alert.tags) {
|
|
|
|
curatedAlert.tags = alert.tags.map(tag => curateTag(tag.tag || tag));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alert.entity) {
|
|
|
|
curatedAlert.entity = curateEntity(alert.entity.entity || alert.entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alert.stashes) {
|
|
|
|
curatedAlert.stashes = alert.stashes.map(stash => curateStash(stash.stash || stash));
|
|
|
|
}
|
|
|
|
|
|
|
|
return curatedAlert;
|
|
|
|
}
|
|
|
|
|
2021-03-15 02:30:47 +00:00
|
|
|
function curateUser(user) {
|
2021-03-19 20:57:04 +00:00
|
|
|
if (!user) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-03-15 02:30:47 +00:00
|
|
|
const curatedUser = user;
|
|
|
|
|
|
|
|
if (user.stashes) {
|
2021-03-21 02:23:58 +00:00
|
|
|
curatedUser.stashes = user.stashes.map(stash => curateStash(stash.stash || stash));
|
2021-03-15 02:30:47 +00:00
|
|
|
}
|
|
|
|
|
2021-04-04 22:48:03 +00:00
|
|
|
if (user.alerts) {
|
|
|
|
curatedUser.alerts = user.alerts.map(alert => curateAlert(alert.alert || alert));
|
|
|
|
}
|
|
|
|
|
2021-03-15 02:30:47 +00:00
|
|
|
return curatedUser;
|
|
|
|
}
|
|
|
|
|
2021-04-22 17:44:23 +00:00
|
|
|
function curateNotification(notification) {
|
|
|
|
const curatedNotification = notification;
|
|
|
|
|
|
|
|
curatedNotification.scene = curateRelease(notification.scene);
|
2021-04-25 22:48:31 +00:00
|
|
|
|
|
|
|
if (notification.alert) {
|
|
|
|
curatedNotification.alert = curateAlert(notification.alert.alert || notification.alert);
|
|
|
|
}
|
2021-04-22 17:44:23 +00:00
|
|
|
|
|
|
|
return curatedNotification;
|
|
|
|
}
|
|
|
|
|
2019-12-16 04:30:25 +00:00
|
|
|
export {
|
2020-05-14 02:26:05 +00:00
|
|
|
curateActor,
|
2020-06-27 00:57:30 +00:00
|
|
|
curateEntity,
|
2020-05-14 02:26:05 +00:00
|
|
|
curateRelease,
|
2021-04-22 17:44:23 +00:00
|
|
|
curateNotification,
|
2020-05-14 02:26:05 +00:00
|
|
|
curateTag,
|
2021-03-14 03:54:43 +00:00
|
|
|
curateStash,
|
2021-03-15 02:30:47 +00:00
|
|
|
curateUser,
|
2019-12-16 04:30:25 +00:00
|
|
|
};
|