traxxx/assets/js/actors/actions.js

277 lines
7.1 KiB
JavaScript

import { graphql, get } from '../api';
import {
releasePosterFragment,
releaseActorsFragment,
releaseTagsFragment,
} from '../fragments';
import { curateActor, curateRelease } from '../curate';
import getDateRange from '../get-date-range';
function initActorActions(store, _router) {
async function fetchActorBySlug({ _commit }, { actorSlug, limit = 100, range = 'latest' }) {
const { before, after, orderBy } = getDateRange(range);
const { actors: [actor] } = await graphql(`
query Actor(
$actorSlug: String!
$limit:Int = 1000,
$after:Date = "1900-01-01",
$before:Date = "2100-01-01",
$orderBy:[ReleasesActorsOrderBy!]
$exclude: [String!]
) {
actors(filter: {
slug: {
equalTo: $actorSlug,
},
networkId: {
isNull: true,
},
}) {
id
name
slug
realName
gender
dateOfBirth
dateOfDeath
age
ageAtDeath
ethnicity
cup
bust
waist
hip
naturalBoobs
heightMetric: height(units:METRIC)
heightImperial: height(units:IMPERIAL)
weightMetric: weight(units:METRIC)
weightImperial: weight(units:IMPERIAL)
hair
eyes
hasTattoos
hasPiercings
tattoos
piercings
description
createdAt
updatedAt
network {
id
name
slug
}
avatar: avatarMedia {
id
path
thumbnail
lazy
hash
comment
copyright
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
profiles: actorsProfiles {
description
descriptionHash
network {
id
slug
name
}
site {
id
slug
name
}
avatar: avatarMedia {
id
path
thumbnail
lazy
hash
comment
copyright
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
}
birthCity
birthState
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
residenceCity
residenceState
residenceCountry: countryByResidenceCountryAlpha2 {
alpha2
name
alias
}
social: actorsSocials {
id
url
platform
}
aliases: actorsByAliasFor {
id
name
slug
}
releases: releasesActors(
filter: {
release: {
date: {
lessThan: $before,
greaterThan: $after,
},
releasesTags: {
none: {
tag: {
slug: {
in: $exclude
}
}
}
}
}
},
first: $limit,
orderBy: $orderBy
) {
release {
id
url
title
date
slug
${releaseActorsFragment}
${releaseTagsFragment}
${releasePosterFragment}
site {
id
name
slug
url
network {
id
name
slug
url
}
}
}
}
}
}
`, {
actorSlug,
limit,
after,
before,
orderBy: orderBy === 'DATE_DESC' ? 'RELEASE_BY_RELEASE_ID__DATE_DESC' : 'RELEASE_BY_RELEASE_ID__DATE_ASC',
exclude: store.state.ui.filter,
});
return curateActor(actor, null, curateRelease);
}
async function fetchActors({ _commit }, {
limit = 100,
letter,
gender,
}) {
const genderFilter = gender === null
? 'isNull: true'
: `equalTo: "${gender}"`;
const { actors } = await graphql(`
query Actors(
$limit: Int,
$letter: String! = "",
) {
actors(
first:$limit,
orderBy: NAME_ASC,
filter: {
aliasFor: {
isNull: true
}
name: {
startsWith: $letter
}
gender: {
${genderFilter}
}
}
) {
id
name
slug
age
dateOfBirth
gender
network {
id
name
slug
}
avatar: avatarMedia {
id
path
thumbnail
lazy
comment
copyright
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
}
}
`, {
limit,
letter,
});
return actors.map(actor => curateActor(actor));
}
async function fetchActorReleases({ _commit }, actorId) {
const releases = await get(`/actors/${actorId}/releases`, {
filter: store.state.ui.filter,
after: store.getters.after,
before: store.getters.before,
});
return releases;
}
return {
fetchActorBySlug,
fetchActors,
fetchActorReleases,
};
}
export default initActorActions;