traxxx/assets/js/actors/actions.js

456 lines
9.8 KiB
JavaScript
Raw Normal View History

import config from 'config';
import dayjs from 'dayjs';
2019-12-15 22:01:48 +00:00
import { graphql, get } from '../api';
2020-05-17 23:22:56 +00:00
import { curateActor, curateRelease } from '../curate';
import getDateRange from '../get-date-range';
2019-12-15 22:01:48 +00:00
2021-03-24 00:52:27 +00:00
import {
releaseFields,
actorStashesFields,
getIncludedEntities,
getIncludedActors,
} from '../fragments';
function initActorActions(store, router) {
2020-05-26 23:40:10 +00:00
async function fetchActorById({ _commit }, {
actorId,
limit = 10,
pageNumber = 1,
range = 'latest',
}) {
if (!actorId) {
return null;
}
const { before, after, orderBy } = getDateRange(range);
const includedTags = router.currentRoute.value.query.tags ? router.currentRoute.value.query.tags.split(',') : [];
const mode = router.currentRoute.value.query.mode || 'all';
const { actor } = await graphql(`
query Actor(
2020-05-25 02:39:58 +00:00
$actorId: Int!
2021-03-15 02:30:47 +00:00
$userId: Int,
$hasAuth: Boolean!,
2020-05-26 23:40:10 +00:00
$limit:Int = 10,
$offset:Int = 0,
$after:Datetime = "1900-01-01",
$before:Datetime = "2100-01-01",
$afterTime:Datetime = "1900-01-01",
$beforeTime:Datetime = "2100-01-01",
$orderBy:[ReleasesOrderBy!]
$selectableTags: [String],
$includedTags: [String!],
$exclude: [String!],
$mode: String!,
$includedEntities: [ReleaseFilter!],
$includedActors: [ReleaseFilter!]
) {
2020-05-25 02:39:58 +00:00
actor(id: $actorId) {
2019-12-15 22:01:48 +00:00
id
name
slug
realName
gender
dateOfBirth
dateOfDeath
age
dateOfBirth
ageFromBirth
ageAtDeath
ethnicity
2020-05-17 01:00:44 +00:00
cup
bust
waist
hip
naturalBoobs
penisLengthMetric: penisLength(units:METRIC)
penisLengthImperial: penisLength(units:IMPERIAL)
penisGirthMetric: penisGirth(units:METRIC)
penisGirthImperial: penisGirth(units:IMPERIAL)
circumcised
heightMetric: height(units:METRIC)
heightImperial: height(units:IMPERIAL)
weightMetric: weight(units:METRIC)
weightImperial: weight(units:IMPERIAL)
hairColor
hairLength
eyes
hasTattoos
hasPiercings
tattoos
piercings
description
createdAt
updatedAt
2020-06-28 02:22:19 +00:00
entity {
id
name
slug
2020-06-28 02:22:19 +00:00
type
parent {
id
name
slug
type
}
}
2020-05-17 01:00:44 +00:00
avatar: avatarMedia {
id
path
thumbnail
lazy
width
height
thumbnailWidth
thumbnailHeight
2020-05-17 01:00:44 +00:00
hash
comment
credit
isS3
2020-05-17 23:22:56 +00:00
sfw: sfwMedia {
id
thumbnail
path
comment
}
2020-05-17 01:00:44 +00:00
}
profiles: actorsProfiles(orderBy: PRIORITY_DESC) {
description
descriptionHash
2020-06-28 02:22:19 +00:00
entity {
id
name
2020-06-28 02:22:19 +00:00
slug
type
independent
2020-06-28 02:22:19 +00:00
parent {
id
name
slug
type
}
}
avatar: avatarMedia {
id
path
thumbnail
lazy
width
height
thumbnailWidth
thumbnailHeight
2020-05-17 01:00:44 +00:00
hash
isS3
comment
credit
entropy
sharpness
2020-05-17 23:22:56 +00:00
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
}
birthCity
birthState
birthCountry: countryByBirthCountryAlpha2 {
2019-12-15 22:01:48 +00:00
alpha2
name
alias
}
residenceCity
residenceState
residenceCountry: countryByResidenceCountryAlpha2 {
alpha2
name
alias
}
social: actorsSocials {
id
url
platform
}
2019-12-15 22:01:48 +00:00
aliases: actorsByAliasFor {
id
name
slug
}
tags(selectableTags: $selectableTags) {
id
name
slug
priority
}
2020-07-20 02:20:33 +00:00
channels {
id
name
slug
type
independent
parent {
id
name
slug
type
}
}
actors {
id
name
slug
}
scenesConnection(
filter: {
or: [
{
date: {
lessThan: $before,
greaterThan: $after
}
},
{
date: {
isNull: true
},
createdAt: {
lessThan: $beforeTime,
greaterThan: $afterTime,
}
}
]
and: [
{
or: $includedEntities
}
{
or: $includedActors
}
{
releasesTagsConnection: {
none: {
tag: {
slug: {
in: $exclude
}
}
}
}
}
]
2020-05-26 23:40:10 +00:00
}
selectedTags: $includedTags
mode: $mode
2020-05-26 23:40:10 +00:00
first: $limit
offset: $offset
orderBy: $orderBy
) {
2020-05-26 23:40:10 +00:00
releases: nodes {
${releaseFields}
2020-05-26 23:40:10 +00:00
}
totalCount
}
2021-03-24 00:52:27 +00:00
${actorStashesFields}
2019-12-15 22:01:48 +00:00
}
}
`, {
2020-05-25 02:39:58 +00:00
actorId,
limit,
2020-05-26 23:40:10 +00:00
offset: Math.max(0, (pageNumber - 1)) * limit,
after,
before,
afterTime: store.getters.after,
beforeTime: store.getters.before,
selectableTags: config.selectableTags,
orderBy,
exclude: store.state.ui.tagFilter,
includedTags,
includedEntities: getIncludedEntities(router),
includedActors: getIncludedActors(router),
mode,
2021-03-15 02:30:47 +00:00
hasAuth: !!store.state.auth.user,
userId: store.state.auth.user?.id,
});
2019-12-15 22:01:48 +00:00
2020-09-10 01:17:19 +00:00
if (!actor) {
router.replace('/not-found');
return null;
}
2020-05-26 23:40:10 +00:00
return {
actor: curateActor(actor, null, curateRelease),
releases: actor.scenesConnection.releases.map(release => curateRelease(release)),
totalCount: actor.scenesConnection.totalCount,
2020-05-26 23:40:10 +00:00
};
}
2019-12-15 22:01:48 +00:00
async function fetchActors({ _commit }, {
limit = 10,
pageNumber = 1,
query,
gender,
age,
2021-08-22 23:29:46 +00:00
country,
2021-03-03 22:54:54 +00:00
dob,
2021-02-28 02:38:54 +00:00
naturalBoobs,
boobSize,
height,
weight,
}) {
const now = dayjs();
const genderFilter = (gender === null && 'gender: { isNull: true }')
|| (gender === 'all' && ' ')
|| (gender && `gender: { equalTo: "${gender}" }`)
|| '';
const ageFilter = age ? `
or: [
{
dateOfBirth: {
greaterThanOrEqualTo: "${now.subtract(age[1], 'year').format('YYYY-MM-DD')}",
lessThanOrEqualTo: "${now.subtract(age[0], 'year').format('YYYY-MM-DD')}"
}
},
{
dateOfBirth: {
isNull: true
}
age: {
greaterThanOrEqualTo: ${age[0]}
lessThanOrEqualTo: ${age[1]}
}
}
]
` : '';
2021-03-03 22:54:54 +00:00
const dobFilter = dob ? `dateOfBirth: { equalTo: "${dob}" }` : '';
2021-08-22 23:29:46 +00:00
const countryFilter = country ? `countryByBirthCountryAlpha2: { alpha2: { equalTo: "${country}" } }` : '';
2021-03-03 22:54:54 +00:00
const heightFilter = height ? `height: { greaterThanOrEqualTo: ${height[0]}, lessThanOrEqualTo: ${height[1]} }` : '';
const weightFilter = weight ? `weight: { greaterThanOrEqualTo: ${weight[0]}, lessThanOrEqualTo: ${weight[1]} }` : '';
const cupFilter = boobSize ? `cup: { greaterThanOrEqualTo: "${boobSize[0]}", lessThanOrEqualTo: "${boobSize[1]}" }` : '';
2021-08-22 23:29:46 +00:00
const { connection: { actors, totalCount }, countries } = await graphql(`
query Actors(
$query: String
$limit: Int,
$offset: Int = 0,
$naturalBoobs: Boolean,
2021-03-24 00:52:27 +00:00
$userId: Int,
$hasAuth: Boolean!,
) {
connection: searchActorsConnection(
query: $query
first: $limit,
offset: $offset
orderBy: NAME_ASC
minLength: 0
filter: {
2020-05-17 23:22:56 +00:00
aliasFor: {
isNull: true
}
${genderFilter}
${ageFilter}
2021-03-03 22:54:54 +00:00
${dobFilter}
${heightFilter}
${weightFilter}
${cupFilter}
2021-08-22 23:29:46 +00:00
${countryFilter}
naturalBoobs: {
equalTo: $naturalBoobs
}
2020-05-17 23:22:56 +00:00
}
) {
totalCount
actors: nodes {
2020-05-17 01:00:44 +00:00
id
name
slug
age
dateOfBirth
ageFromBirth
ageAtDeath
dateOfBirth
dateOfDeath
gender
2020-06-28 02:22:19 +00:00
entity {
id
name
slug
2020-06-28 02:22:19 +00:00
type
parent {
id
name
slug
type
}
}
avatar: avatarMedia {
2020-05-17 23:22:56 +00:00
id
path
thumbnail
lazy
2020-05-17 23:22:56 +00:00
comment
credit
isS3
sfw: sfwMedia {
id
thumbnail
path
comment
}
}
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
2020-05-17 23:22:56 +00:00
}
2021-03-24 00:52:27 +00:00
${actorStashesFields}
2020-05-17 01:00:44 +00:00
}
2019-12-15 22:01:48 +00:00
}
countries(
orderBy: NAME_ASC,
) {
2021-08-22 23:29:46 +00:00
alpha2
name
alias
}
2019-12-15 22:01:48 +00:00
}
`, {
query,
offset: Math.max(0, (pageNumber - 1)) * limit,
limit,
naturalBoobs: naturalBoobs || null,
2021-03-24 00:52:27 +00:00
hasAuth: !!store.state.auth.user,
userId: store.state.auth.user?.id,
});
2019-12-15 22:01:48 +00:00
return {
actors: actors.map(actor => curateActor(actor)),
totalCount,
2021-08-22 23:29:46 +00:00
countries,
};
}
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 {
2020-05-25 02:39:58 +00:00
fetchActorById,
fetchActors,
fetchActorReleases,
};
}
export default initActorActions;