traxxx/assets/js/releases/actions.js

300 lines
6.3 KiB
JavaScript
Raw Normal View History

import { graphql } from '../api';
import {
2023-06-15 22:47:19 +00:00
batchFragment,
releasesFragment,
releaseFragment,
releaseFields,
movieFields,
mediaFragment,
mediaFields,
} from '../fragments';
import { curateRelease } from '../curate';
import getDateRange from '../get-date-range';
2020-09-10 01:17:19 +00:00
function initReleasesActions(store, router) {
2020-05-22 02:32:16 +00:00
async function fetchReleases({ _commit }, { limit = 10, pageNumber = 1, range = 'latest' }) {
const { before, after, orderBy } = getDateRange(range);
2023-06-15 22:47:19 +00:00
const { connection: { releases, totalCount }, batches: [lastBatch] } = await graphql(`
2019-12-18 01:42:55 +00:00
query Releases(
$hasAuth: Boolean!
$userId: Int
2019-12-18 01:42:55 +00:00
$limit:Int = 1000,
2020-05-22 02:32:16 +00:00
$offset:Int = 0,
2020-08-19 19:48:55 +00:00
$after:Datetime = "1900-01-01 00:00:00",
$before:Datetime = "2100-01-01 00:00:00",
$orderBy: [ReleasesSummariesOrderBy!],
$exclude: [String!],
$batchShowcased: [Boolean!]
2019-12-18 01:42:55 +00:00
) {
${releasesFragment}
2023-06-15 22:47:19 +00:00
${batchFragment}
}
2019-12-15 22:01:48 +00:00
`, {
hasAuth: !!store.state.auth.user,
userId: store.state.auth.user?.id,
limit,
2020-05-22 02:32:16 +00:00
offset: Math.max(0, (pageNumber - 1)) * limit,
after,
before,
2023-01-16 15:49:47 +00:00
orderBy,
2021-01-03 21:53:51 +00:00
exclude: store.state.ui.tagFilter,
batchShowcased: range === 'new' ? true : [true, false],
});
2020-05-22 02:32:16 +00:00
return {
2023-06-15 22:47:19 +00:00
releases: releases.map((release) => curateRelease(release.release || release, 'scene', { lastBatch: lastBatch.id })),
2020-05-22 02:32:16 +00:00
totalCount,
};
}
async function fetchReleaseById({ _commit }, releaseId) {
// const release = await get(`/releases/${releaseId}`);
const { release } = await graphql(`
2021-03-17 01:09:34 +00:00
query Release(
$releaseId: Int!
$hasAuth: Boolean!
$userId: Int
) {
${releaseFragment}
}
`, {
releaseId: Number(releaseId),
2021-03-17 01:09:34 +00:00
hasAuth: !!store.state.auth.user,
userId: store.state.auth.user?.id,
});
2020-09-10 01:17:19 +00:00
if (!release) {
router.replace('/not-found');
return null;
}
return curateRelease(release);
}
async function fetchMovies({ _commit }, { limit = 10, pageNumber = 1 }) {
const { connection: { movies, totalCount } } = await graphql(`
query Movies(
$limit:Int = 1000,
$offset:Int = 0,
$hasAuth: Boolean!
$userId: Int
) {
connection: moviesConnection(
first: $limit
offset: $offset
2023-07-02 03:07:38 +00:00
orderBy: EFFECTIVE_DATE_DESC
) {
movies: nodes {
${movieFields}
}
totalCount
}
}
`, {
hasAuth: !!store.state.auth.user,
userId: store.state.auth.user?.id,
limit,
offset: Math.max(0, (pageNumber - 1)) * limit,
});
return {
movies: movies.map((release) => curateRelease(release)),
totalCount,
};
}
async function searchMovies({ _commit }, { query, limit = 20, pageNumber = 1 }) {
const { connection: { movies, totalCount } } = await graphql(`
query SearchMovies(
$query: String!
$limit:Int = 20
$offset:Int = 0
$hasAuth: Boolean!
$userId: Int
) {
connection: searchMoviesConnection(
query: $query
first: $limit
offset: $offset
orderBy: RANK_DESC
) {
movies: nodes {
movie {
${movieFields}
}
}
totalCount
}
}
`, {
hasAuth: !!store.state.auth.user,
userId: store.state.auth.user?.id,
query,
limit,
offset: Math.max(0, (pageNumber - 1)) * limit,
});
return {
movies: movies.map(({ movie }) => curateRelease(movie)),
totalCount,
};
}
2022-03-26 16:40:20 +00:00
async function fetchCollectionById({ _commit }, movieId, type = 'movie') {
// const release = await get(`/releases/${releaseId}`);
2022-03-26 16:40:20 +00:00
const result = await graphql(`
query Movie(
$movieId: Int!
$hasAuth: Boolean!
$userId: Int
) {
2022-03-26 16:40:20 +00:00
${type}(id: $movieId) {
id
title
description
slug
url
date
createdBatchId
actors {
id
name
2020-09-08 00:20:15 +00:00
slug
age
2020-12-17 02:48:38 +00:00
ageFromBirth
dateOfBirth
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
avatar: avatarMedia {
id
path
thumbnail
width
height
thumbnailWidth
thumbnailHeight
lazy
2021-02-23 00:30:38 +00:00
isS3
}
}
2022-03-26 16:40:20 +00:00
poster: ${type === 'series' ? 'seriesPosterBySerieId' : 'moviesPoster'} {
2021-02-23 00:30:38 +00:00
media {
id
path
thumbnail
lazy
width
height
thumbnailWidth
thumbnailHeight
2021-02-23 00:30:38 +00:00
isS3
}
}
2022-03-26 16:40:20 +00:00
covers: ${type === 'series' ? 'seriesCoversBySerieId' : 'moviesCovers'}(orderBy: MEDIA_BY_MEDIA_ID__INDEX_ASC) {
media {
id
path
thumbnail
width
height
thumbnailWidth
thumbnailHeight
2020-09-08 00:20:15 +00:00
lazy
2021-02-23 00:30:38 +00:00
isS3
}
}
2022-03-26 16:40:20 +00:00
trailer: ${type === 'series' ? 'seriesTrailerBySerieId' : 'moviesTrailer'} {
media {
id
path
2021-02-23 00:30:38 +00:00
isS3
}
}
2022-03-26 16:40:20 +00:00
scenes: ${type === 'series' ? 'seriesScenesBySerieId' : 'moviesScenes'} {
scene {
${releaseFields}
}
}
tags {
id
slug
name
}
photos: ${type === 'series' ? 'seriesPhotosBySerieId' : 'moviesPhotos'} {
${mediaFragment}
}
scenesPhotos {
${mediaFields}
2020-09-08 00:20:15 +00:00
}
entity {
id
name
slug
type
hasLogo
parent {
id
name
slug
type
hasLogo
}
}
2022-03-26 16:40:20 +00:00
stashes: ${type === 'series' ? 'stashesSeriesBySerieId' : 'stashesMovies'}(
filter: {
stash: {
userId: {
equalTo: $userId
}
}
}
) @include(if: $hasAuth) {
stash {
id
name
slug
primary
}
}
}
}
`, {
movieId: Number(movieId),
hasAuth: !!store.state.auth.user,
userId: store.state.auth.user?.id,
});
2022-03-26 16:40:20 +00:00
if (!result[type]) {
2020-09-10 01:17:19 +00:00
router.replace('/not-found');
return null;
}
2022-03-26 16:40:20 +00:00
return curateRelease(result[type]);
}
async function fetchMovieById(context, movieId) {
return fetchCollectionById(context, movieId, 'movie');
}
async function fetchSerieById(context, serieId) {
return fetchCollectionById(context, serieId, 'series');
}
return {
fetchReleases,
fetchReleaseById,
fetchMovies,
fetchMovieById,
2022-03-26 16:40:20 +00:00
fetchSerieById,
searchMovies,
};
}
export default initReleasesActions;