traxxx/assets/js/releases/actions.js

221 lines
3.9 KiB
JavaScript
Raw Normal View History

import { graphql } from '../api';
import { releasesFragment, releaseFragment, releaseFields } 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);
2020-05-22 02:32:16 +00:00
const { connection: { releases, totalCount } } = await graphql(`
2019-12-18 01:42:55 +00:00
query Releases(
$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: [ReleasesOrderBy!],
2020-01-30 22:41:10 +00:00
$exclude: [String!]
2019-12-18 01:42:55 +00:00
) {
${releasesFragment}
}
2019-12-15 22:01:48 +00:00
`, {
limit,
2020-05-22 02:32:16 +00:00
offset: Math.max(0, (pageNumber - 1)) * limit,
after,
before,
orderBy,
exclude: store.state.ui.filter,
});
2020-05-22 02:32:16 +00:00
return {
releases: releases.map(release => curateRelease(release)),
totalCount,
};
}
async function fetchReleaseById({ _commit }, releaseId) {
// const release = await get(`/releases/${releaseId}`);
const { release } = await graphql(`
query Release($releaseId:Int!) {
${releaseFragment}
}
`, {
releaseId: Number(releaseId),
});
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,
) {
connection: moviesConnection(
first: $limit
offset: $offset
orderBy: DATE_DESC
) {
movies: nodes {
id
title
url
slug
date
datePrecision
actors {
id
name
slug
}
tags {
id
name
slug
}
entity {
id
name
slug
type
parent {
id
name
slug
type
}
}
covers: moviesCovers {
media {
id
path
thumbnail
2020-09-08 00:20:15 +00:00
lazy
}
}
}
totalCount
}
}
`, {
limit,
offset: Math.max(0, (pageNumber - 1)) * limit,
});
return {
movies: movies.map(release => curateRelease(release)),
totalCount,
};
}
async function fetchMovieById({ _commit }, movieId) {
// const release = await get(`/releases/${releaseId}`);
const { movie } = await graphql(`
query Movie($movieId: Int!) {
movie(id: $movieId) {
id
title
slug
url
date
actors {
id
name
2020-09-08 00:20:15 +00:00
slug
age
dateOfBirth
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
avatar: avatarMedia {
id
path
thumbnail
lazy
}
}
covers: moviesCovers {
media {
id
path
thumbnail
2020-09-08 00:20:15 +00:00
lazy
}
}
trailer: moviesTrailerByMovieId {
media {
id
path
}
}
scenes: moviesScenes {
scene {
${releaseFields}
}
}
tags {
id
slug
name
}
2020-09-08 00:20:15 +00:00
photos {
id
index
path
thumbnail
lazy
comment
sfw: sfwMedia {
id
thumbnail
lazy
path
comment
}
}
entity {
id
name
slug
type
parent {
id
name
slug
type
}
}
}
}
`, {
movieId: Number(movieId),
});
2020-09-10 01:17:19 +00:00
if (!movie) {
router.replace('/not-found');
return null;
}
return curateRelease(movie);
}
return {
fetchReleases,
fetchReleaseById,
fetchMovies,
fetchMovieById,
};
}
export default initReleasesActions;