import config from 'config'; import { graphql, get } from '../api'; import { releaseFields, getIncludedEntities, getIncludedActors } from '../fragments'; import { curateActor, curateRelease } from '../curate'; import getDateRange from '../get-date-range'; function initActorActions(store, router) { async function fetchActorById({ _commit }, { actorId, limit = 10, pageNumber = 1, range = 'latest', }) { 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( $actorId: Int! $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!] ) { actor(id: $actorId) { id name slug realName gender dateOfBirth dateOfDeath age dateOfBirth ageFromBirth ageAtDeath ethnicity 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 entity { id name slug type parent { id name slug type } } avatar: avatarMedia { id path thumbnail lazy hash comment credit isS3 sfw: sfwMedia { id thumbnail path comment } } profiles: actorsProfiles(orderBy: PRIORITY_DESC) { description descriptionHash entity { id name slug type independent parent { id name slug type } } avatar: avatarMedia { id path thumbnail lazy hash isS3 comment credit entropy sharpness 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 } tags(selectableTags: $selectableTags) { id name slug priority } 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 } } } } } ] } selectedTags: $includedTags mode: $mode first: $limit offset: $offset orderBy: $orderBy ) { releases: nodes { ${releaseFields} } totalCount } } } `, { actorId, limit, 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, }); if (!actor) { router.replace('/not-found'); return null; } return { actor: curateActor(actor, null, curateRelease), releases: actor.scenesConnection.releases.map(release => curateRelease(release)), totalCount: actor.scenesConnection.totalCount, }; } async function fetchActors({ _commit }, { limit = 10, pageNumber = 1, letter, gender, naturalBoobs, }) { const genderFilter = (gender === null && 'gender: { isNull: true }') || (gender === 'all' && ' ') || `gender: { equalTo: "${gender}" }`; const naturalBoobsFilter = (naturalBoobs && 'naturalBoobs: { equalTo: true }') || (naturalBoobs === false && 'naturalBoobs: { equalTo: false }') || ''; const { connection: { actors, totalCount } } = await graphql(` query Actors( $limit: Int, $offset: Int = 0, $letter: String! = "", ) { connection: actorsConnection( first: $limit, offset: $offset orderBy: NAME_ASC filter: { aliasFor: { isNull: true } name: { startsWith: $letter } ${genderFilter} ${naturalBoobsFilter} } ) { totalCount actors: nodes { id name slug age dateOfBirth ageFromBirth ageAtDeath dateOfBirth dateOfDeath gender entity { id name slug type parent { id name slug type } } avatar: avatarMedia { id path thumbnail lazy comment credit isS3 sfw: sfwMedia { id thumbnail path comment } } birthCountry: countryByBirthCountryAlpha2 { alpha2 name alias } } } } `, { offset: Math.max(0, (pageNumber - 1)) * limit, limit, letter, naturalBoobs, }); return { actors: actors.map(actor => curateActor(actor)), totalCount, }; } 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 { fetchActorById, fetchActors, fetchActorReleases, }; } export default initActorActions;