traxxx/assets/js/ui/actions.js

222 lines
4.3 KiB
JavaScript
Raw Normal View History

import { graphql } from '../api';
2020-05-17 23:22:56 +00:00
import { curateRelease, curateActor } from '../curate';
function initUiActions(_store, _router) {
2021-01-03 21:53:51 +00:00
function setTagFilter({ commit }, filter) {
const tagFilter = Array.from(new Set(filter));
commit('setTagFilter', tagFilter);
localStorage.setItem('tagFilter', tagFilter);
}
function setRange({ commit }, range) {
commit('setRange', range);
}
function setBatch({ commit }, batch) {
commit('setBatch', batch);
localStorage.setItem('batch', batch);
}
function setTheme({ commit }, theme) {
commit('setTheme', theme);
localStorage.setItem('theme', theme);
}
2020-03-23 00:43:49 +00:00
async function setSfw({ commit }, sfw) {
commit('setSfw', sfw);
localStorage.setItem('sfw', sfw);
}
2020-03-23 00:43:49 +00:00
2020-05-17 23:22:56 +00:00
async function search({ _commit }, { query, limit = 20 }) {
const res = await graphql(`
query SearchReleases(
$query: String!
$limit: Int = 20
) {
results: searchReleases(
2020-05-17 23:22:56 +00:00
query: $query
first: $limit
orderBy: RANK_DESC
filter: {
rank: {
greaterThan: 0.015
}
}
2020-05-17 23:22:56 +00:00
) {
release {
id
title
slug
date
url
isNew
entity {
id
slug
name
url
2020-11-30 02:09:31 +00:00
type
independent
parent {
id
slug
name
url
type
}
}
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
isS3
}
}
covers: releasesCovers {
media {
id
thumbnail
lazy
isS3
}
}
}
rank
2020-05-17 23:22:56 +00:00
}
actors: searchActors(
search: $query,
first: $limit
) {
id
name
slug
age
2020-05-26 02:11:29 +00:00
ageAtDeath
2020-05-17 23:22:56 +00:00
dateOfBirth
2020-05-26 02:11:29 +00:00
dateOfDeath
2020-05-17 23:22:56 +00:00
gender
aliasFor: actorByAliasFor {
id
name
slug
age
2020-05-26 02:11:29 +00:00
ageAtDeath
2020-05-17 23:22:56 +00:00
dateOfBirth
2020-05-26 02:11:29 +00:00
dateOfDeath
2020-05-17 23:22:56 +00:00
gender
entity {
2020-05-17 23:22:56 +00:00
id
name
slug
}
avatar: avatarMedia {
id
path
thumbnail
lazy
comment
credit
2020-05-17 23:22:56 +00:00
}
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
}
entity {
2020-05-17 23:22:56 +00:00
id
name
slug
}
avatar: avatarMedia {
id
path
thumbnail
lazy
comment
credit
2020-05-17 23:22:56 +00:00
}
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
}
}
`, {
query,
limit,
});
return {
releases: res.results.map(result => curateRelease(result.release)),
2020-05-17 23:22:56 +00:00
actors: res.actors.map(actor => curateActor(actor)),
};
}
2020-08-15 17:04:33 +00:00
async function fetchStats() {
const {
scenes,
movies,
actors,
networks,
channels,
} = await graphql(`
query Stats {
2021-02-10 03:20:58 +00:00
scenes: releasesConnection(
last: 1,
orderBy: BATCH_BY_CREATED_BATCH_ID__CREATED_AT_ASC
) {
totalCount
scenes: nodes {
batch: createdBatch {
createdAt
}
}
}
2020-08-15 17:04:33 +00:00
movies: moviesConnection { totalCount }
actors: actorsConnection { totalCount }
networks: entitiesConnection(filter: { type: { equalTo: "network" } }) { totalCount }
channels: entitiesConnection(filter: { type: { equalTo: "channel" } }) { totalCount }
}
`);
return {
totalScenes: scenes.totalCount,
totalMovies: movies.totalCount,
totalActors: actors.totalCount,
totalNetworks: networks.totalCount,
totalChannels: channels.totalCount,
2021-02-10 03:20:58 +00:00
lastScrape: new Date(scenes.scenes[0]?.batch.createdAt),
2020-08-15 17:04:33 +00:00
};
}
return {
2020-05-17 23:22:56 +00:00
search,
2021-01-03 21:53:51 +00:00
setTagFilter,
setRange,
setBatch,
setSfw,
setTheme,
2020-08-15 17:04:33 +00:00
fetchStats,
};
}
export default initUiActions;