2020-01-07 03:23:28 +00:00
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
|
|
|
function curateActor(actor, release) {
|
2019-12-16 04:30:25 +00:00
|
|
|
const curatedActor = {
|
|
|
|
...actor,
|
|
|
|
origin: actor.originCountry && {
|
|
|
|
country: actor.originCountry,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-12-19 03:42:50 +00:00
|
|
|
if (actor.avatar) curatedActor.avatar = actor.avatar.media;
|
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
if (release && release.date && curatedActor.birthdate) {
|
|
|
|
curatedActor.ageThen = dayjs(release.date).diff(actor.birthdate, 'year');
|
|
|
|
}
|
|
|
|
|
2019-12-16 04:30:25 +00:00
|
|
|
return curatedActor;
|
|
|
|
}
|
|
|
|
|
|
|
|
function curateRelease(release) {
|
|
|
|
const curatedRelease = {
|
|
|
|
...release,
|
2020-01-07 03:23:28 +00:00
|
|
|
actors: [],
|
2019-12-19 03:42:50 +00:00
|
|
|
poster: release.poster && release.poster.media,
|
2019-12-31 02:12:52 +00:00
|
|
|
tags: release.tags ? release.tags.map(({ tag }) => tag) : [],
|
2019-12-19 03:42:50 +00:00
|
|
|
network: release.site.network,
|
2019-12-16 04:30:25 +00:00
|
|
|
};
|
|
|
|
|
2019-12-19 03:42:50 +00:00
|
|
|
if (release.photos) curatedRelease.photos = release.photos.map(({ media }) => media);
|
2019-12-31 02:12:52 +00:00
|
|
|
if (release.trailer) curatedRelease.trailer = release.trailer.media;
|
2020-02-02 04:14:58 +00:00
|
|
|
if (release.teaser) curatedRelease.teaser = release.teaser.media;
|
2020-01-07 03:23:28 +00:00
|
|
|
if (release.actors) curatedRelease.actors = release.actors.map(({ actor }) => curateActor(actor, curatedRelease));
|
2019-12-16 04:30:25 +00:00
|
|
|
|
|
|
|
return curatedRelease;
|
|
|
|
}
|
|
|
|
|
2020-01-02 23:59:02 +00:00
|
|
|
function curateSite(site, network) {
|
|
|
|
const curatedSite = {
|
|
|
|
id: site.id,
|
|
|
|
name: site.name,
|
|
|
|
slug: site.slug,
|
|
|
|
url: site.url,
|
2020-01-06 23:30:51 +00:00
|
|
|
independent: site.independent,
|
2020-01-02 23:59:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (site.releases) curatedSite.releases = site.releases.map(release => curateRelease(release));
|
|
|
|
if (site.network || network) curatedSite.network = site.network || network;
|
2020-01-13 22:45:09 +00:00
|
|
|
if (site.tags) curatedSite.tags = site.tags.map(({ tag }) => tag);
|
2020-01-02 23:59:02 +00:00
|
|
|
|
|
|
|
return curatedSite;
|
|
|
|
}
|
|
|
|
|
2020-01-08 23:23:37 +00:00
|
|
|
function curateNetwork(network, releases) {
|
2020-01-02 23:59:02 +00:00
|
|
|
const curatedNetwork = {
|
|
|
|
id: network.id,
|
|
|
|
name: network.name,
|
|
|
|
slug: network.slug,
|
|
|
|
url: network.url,
|
|
|
|
};
|
|
|
|
|
2020-01-08 23:23:37 +00:00
|
|
|
if (network.sites) curatedNetwork.sites = network.sites.map(site => curateSite(site, curatedNetwork));
|
|
|
|
if (network.studios) curatedNetwork.studios = network.studios;
|
|
|
|
if (releases) curatedNetwork.releases = releases.map(release => curateRelease(release));
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-01-02 23:59:02 +00:00
|
|
|
return curatedNetwork;
|
|
|
|
}
|
|
|
|
|
2019-12-19 03:42:50 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-12-16 04:30:25 +00:00
|
|
|
export {
|
|
|
|
curateActor,
|
|
|
|
curateRelease,
|
2020-01-02 23:59:02 +00:00
|
|
|
curateSite,
|
|
|
|
curateNetwork,
|
2019-12-19 03:42:50 +00:00
|
|
|
curateTag,
|
2019-12-16 04:30:25 +00:00
|
|
|
};
|