Improved actor scraping and display.

This commit is contained in:
2020-05-18 01:22:56 +02:00
parent af5543190a
commit 8733fdc657
28 changed files with 1033 additions and 793 deletions

View File

@@ -4,53 +4,9 @@ import {
releaseActorsFragment,
releaseTagsFragment,
} from '../fragments';
import { curateRelease } from '../curate';
import { curateActor, curateRelease } from '../curate';
import getDateRange from '../get-date-range';
function curateActor(actor) {
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));
curatedActor.photos = Object.values(photos.reduce((acc, photo) => ({ ...acc, [photo.hash]: photo }), {}));
}
if (actor.releases) {
curatedActor.releases = actor.releases.map(release => curateRelease(release.release));
}
return curatedActor;
}
function initActorActions(store, _router) {
async function fetchActorBySlug({ _commit }, { actorSlug, limit = 100, range = 'latest' }) {
const { before, after, orderBy } = getDateRange(range);
@@ -110,6 +66,12 @@ function initActorActions(store, _router) {
hash
comment
copyright
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
profiles: actorsProfiles {
description
@@ -121,6 +83,12 @@ function initActorActions(store, _router) {
hash
comment
copyright
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
}
birthCity
@@ -202,7 +170,7 @@ function initActorActions(store, _router) {
exclude: store.state.ui.filter,
});
return curateActor(actor);
return curateActor(actor, null, curateRelease);
}
async function fetchActors({ _commit }, {
@@ -223,13 +191,16 @@ function initActorActions(store, _router) {
first:$limit,
orderBy: NAME_ASC,
filter: {
aliasFor: {
isNull: true
}
name: {
startsWith: $letter
},
}
gender: {
${genderFilter}
},
},
}
}
) {
id
name
@@ -249,17 +220,13 @@ function initActorActions(store, _router) {
lazy
comment
copyright
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
actorsProfiles {
actorsAvatarByProfileId {
media {
id
path
thumbnail
copyright
}
}
}
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name

View File

@@ -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;
}

View File

@@ -28,75 +28,6 @@ function initReleasesActions(store, _router) {
return releases.map(release => curateRelease(release));
}
async function searchReleases({ _commit }, { query, limit = 20 }) {
const res = await graphql(`
query SearchReleases(
$query: String!
$limit: Int = 20
) {
releases: searchReleases(
query: $query
first: $limit
) {
id
title
slug
date
url
type
isNew
site {
id
slug
name
url
network {
id
slug
name
url
}
}
actors: releasesActors {
actor {
id
slug
name
}
}
tags: releasesTags(orderBy: TAG_BY_TAG_ID__PRIORITY_DESC) {
tag {
id
name
slug
}
}
poster: releasesPosterByReleaseId {
media {
id
thumbnail
lazy
}
}
covers: releasesCovers {
media {
id
thumbnail
lazy
}
}
}
}
`, {
query,
limit,
});
if (!res) return [];
return res.releases.map(release => curateRelease(release));
}
async function fetchReleaseById({ _commit }, releaseId) {
// const release = await get(`/releases/${releaseId}`);
@@ -114,7 +45,6 @@ function initReleasesActions(store, _router) {
return {
fetchReleases,
fetchReleaseById,
searchReleases,
};
}

View File

@@ -1,3 +1,6 @@
import { graphql } from '../api';
import { curateRelease, curateActor } from '../curate';
function initUiActions(_store, _router) {
function setFilter({ commit }, filter) {
commit('setFilter', filter);
@@ -23,7 +26,133 @@ function initUiActions(_store, _router) {
localStorage.setItem('sfw', sfw);
}
async function search({ _commit }, { query, limit = 20 }) {
const res = await graphql(`
query SearchReleases(
$query: String!
$limit: Int = 20
) {
releases: searchReleases(
query: $query
first: $limit
) {
id
title
slug
date
url
type
isNew
site {
id
slug
name
url
network {
id
slug
name
url
}
}
actors: releasesActors {
actor {
id
slug
name
}
}
tags: releasesTags(orderBy: TAG_BY_TAG_ID__PRIORITY_DESC) {
tag {
id
name
slug
}
}
poster: releasesPosterByReleaseId {
media {
id
thumbnail
lazy
}
}
covers: releasesCovers {
media {
id
thumbnail
lazy
}
}
}
actors: searchActors(
search: $query,
first: $limit
) {
id
name
slug
age
dateOfBirth
gender
aliasFor: actorByAliasFor {
id
name
slug
age
dateOfBirth
gender
network {
id
name
slug
}
avatar: avatarMedia {
id
path
thumbnail
lazy
comment
copyright
}
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
}
network {
id
name
slug
}
avatar: avatarMedia {
id
path
thumbnail
lazy
comment
copyright
}
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
}
}
`, {
query,
limit,
});
return {
releases: res.releases.map(release => curateRelease(release)),
actors: res.actors.map(actor => curateActor(actor)),
};
}
return {
search,
setFilter,
setRange,
setBatch,