2021-04-25 01:08:50 +00:00
|
|
|
import { graphql, patch } from '../api';
|
2023-07-05 22:14:38 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
releaseFields,
|
|
|
|
batchFragment,
|
|
|
|
campaignFields,
|
|
|
|
actorStashesFields,
|
|
|
|
} from '../fragments';
|
|
|
|
|
2021-04-22 17:44:23 +00:00
|
|
|
import { curateRelease, curateActor, curateNotification } from '../curate';
|
2020-05-17 23:22:56 +00:00
|
|
|
|
2021-03-24 00:26:33 +00:00
|
|
|
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);
|
2020-05-14 02:26:05 +00:00
|
|
|
}
|
2019-11-15 01:37:17 +00:00
|
|
|
|
2022-11-28 02:33:46 +00:00
|
|
|
function setSummaryFormat({ commit }, summaryFormat) {
|
|
|
|
commit('setSummaryFormat', summaryFormat);
|
|
|
|
localStorage.setItem('summaryFormat', JSON.stringify(summaryFormat));
|
|
|
|
}
|
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
function setRange({ commit }, range) {
|
|
|
|
commit('setRange', range);
|
|
|
|
}
|
2019-11-15 01:37:17 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
function setBatch({ commit }, batch) {
|
|
|
|
commit('setBatch', batch);
|
|
|
|
localStorage.setItem('batch', batch);
|
|
|
|
}
|
2020-03-02 02:41:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
function setTheme({ commit }, theme) {
|
|
|
|
commit('setTheme', theme);
|
|
|
|
localStorage.setItem('theme', theme);
|
|
|
|
}
|
2020-03-23 00:43:49 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
async function setSfw({ commit }, sfw) {
|
|
|
|
commit('setSfw', sfw);
|
|
|
|
localStorage.setItem('sfw', sfw);
|
|
|
|
}
|
2020-03-23 00:43:49 +00:00
|
|
|
|
2021-05-08 22:23:10 +00:00
|
|
|
async function fetchNotifications(_context, { page = 1, limit = 10 } = {}) {
|
2021-04-22 17:44:23 +00:00
|
|
|
if (!store.state.auth.user) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2021-04-28 23:45:01 +00:00
|
|
|
const { notifications, unseenNotifications } = await graphql(`
|
2021-04-22 17:44:23 +00:00
|
|
|
query Notifications(
|
|
|
|
$hasAuth: Boolean!
|
|
|
|
$userId: Int
|
2021-05-08 22:23:10 +00:00
|
|
|
$limit: Int = 10
|
|
|
|
$offset: Int = 0
|
2021-04-22 17:44:23 +00:00
|
|
|
) {
|
2021-05-08 22:23:10 +00:00
|
|
|
notifications: notificationsConnection(
|
|
|
|
first: $limit
|
|
|
|
offset: $offset
|
2021-04-25 22:48:31 +00:00
|
|
|
orderBy: CREATED_AT_DESC
|
2021-04-25 01:08:50 +00:00
|
|
|
) {
|
2021-05-08 22:23:10 +00:00
|
|
|
nodes {
|
|
|
|
id
|
|
|
|
sceneId
|
|
|
|
userId
|
|
|
|
seen
|
|
|
|
createdAt
|
|
|
|
scene {
|
|
|
|
${releaseFields}
|
2021-04-22 17:44:23 +00:00
|
|
|
}
|
2021-05-08 22:23:10 +00:00
|
|
|
alert {
|
|
|
|
tags: alertsTags {
|
|
|
|
tag {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
2021-04-22 17:44:23 +00:00
|
|
|
}
|
2021-05-08 22:23:10 +00:00
|
|
|
actors: alertsActors {
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
2023-11-24 00:29:22 +00:00
|
|
|
entities: alertsEntities {
|
2021-05-08 22:23:10 +00:00
|
|
|
entity {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
independent
|
|
|
|
}
|
2021-04-27 01:56:38 +00:00
|
|
|
}
|
2023-11-24 00:29:22 +00:00
|
|
|
matches: alertsMatches {
|
|
|
|
property
|
|
|
|
expression
|
|
|
|
}
|
2021-04-27 01:56:38 +00:00
|
|
|
}
|
2021-04-22 17:44:23 +00:00
|
|
|
}
|
2021-05-08 22:23:10 +00:00
|
|
|
totalCount
|
|
|
|
}
|
2021-04-28 23:45:01 +00:00
|
|
|
unseenNotifications: notificationsConnection(
|
|
|
|
filter: { seen: { equalTo: false } }
|
|
|
|
) {
|
|
|
|
totalCount
|
|
|
|
}
|
2021-04-22 17:44:23 +00:00
|
|
|
}
|
|
|
|
`, {
|
|
|
|
hasAuth: !!store.state.auth.user,
|
|
|
|
userId: store.state.auth.user?.id,
|
2021-05-08 22:23:10 +00:00
|
|
|
limit,
|
|
|
|
offset: (page - 1) * limit,
|
2021-04-22 17:44:23 +00:00
|
|
|
});
|
|
|
|
|
2021-05-15 01:06:57 +00:00
|
|
|
if (!notifications) {
|
|
|
|
return {
|
|
|
|
notifications: [],
|
|
|
|
totalCount: 0,
|
|
|
|
unseenCount: 0,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-20 22:59:15 +00:00
|
|
|
const curatedNotifications = notifications.nodes.map((notification) => curateNotification(notification));
|
2021-04-28 23:45:01 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
notifications: curatedNotifications,
|
2021-05-08 22:23:10 +00:00
|
|
|
totalCount: notifications.totalCount,
|
2021-04-28 23:45:01 +00:00
|
|
|
unseenCount: unseenNotifications.totalCount,
|
|
|
|
};
|
2021-04-22 17:44:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-25 01:08:50 +00:00
|
|
|
async function checkNotification(context, notificationId) {
|
|
|
|
await patch(`/users/${store.state.auth.user?.id}/notifications/${notificationId}`, {
|
|
|
|
seen: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function checkNotifications() {
|
|
|
|
await patch(`/users/${store.state.auth.user?.id}/notifications`, {
|
|
|
|
seen: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
2021-03-24 00:26:33 +00:00
|
|
|
$hasAuth: Boolean!
|
|
|
|
$userId: Int
|
2020-05-17 23:22:56 +00:00
|
|
|
) {
|
2021-02-26 00:33:33 +00:00
|
|
|
results: searchReleases(
|
2020-05-17 23:22:56 +00:00
|
|
|
query: $query
|
|
|
|
first: $limit
|
2021-02-26 00:52:28 +00:00
|
|
|
orderBy: RANK_DESC
|
|
|
|
filter: {
|
|
|
|
rank: {
|
2021-03-18 18:44:23 +00:00
|
|
|
greaterThan: 0.015
|
2021-02-26 00:52:28 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-17 23:22:56 +00:00
|
|
|
) {
|
2021-02-26 16:22:54 +00:00
|
|
|
release {
|
2021-03-24 00:26:33 +00:00
|
|
|
${releaseFields}
|
2021-02-26 00:33:33 +00:00
|
|
|
}
|
|
|
|
rank
|
2020-05-17 23:22:56 +00:00
|
|
|
}
|
|
|
|
actors: searchActors(
|
2021-08-22 23:35:46 +00:00
|
|
|
query: $query,
|
2020-05-17 23:22:56 +00:00
|
|
|
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
|
2020-06-29 23:52:17 +00:00
|
|
|
entity {
|
2020-05-17 23:22:56 +00:00
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
avatar: avatarMedia {
|
|
|
|
id
|
|
|
|
path
|
|
|
|
thumbnail
|
|
|
|
lazy
|
2021-03-21 13:22:31 +00:00
|
|
|
isS3
|
|
|
|
width
|
|
|
|
height
|
2020-05-17 23:22:56 +00:00
|
|
|
comment
|
2020-07-15 03:12:29 +00:00
|
|
|
credit
|
2020-05-17 23:22:56 +00:00
|
|
|
}
|
|
|
|
birthCountry: countryByBirthCountryAlpha2 {
|
|
|
|
alpha2
|
|
|
|
name
|
|
|
|
alias
|
|
|
|
}
|
|
|
|
}
|
2020-06-29 23:52:17 +00:00
|
|
|
entity {
|
2020-05-17 23:22:56 +00:00
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
avatar: avatarMedia {
|
|
|
|
id
|
|
|
|
path
|
|
|
|
thumbnail
|
|
|
|
lazy
|
2021-03-21 14:14:28 +00:00
|
|
|
isS3
|
|
|
|
width
|
|
|
|
height
|
2020-05-17 23:22:56 +00:00
|
|
|
comment
|
2020-07-15 03:12:29 +00:00
|
|
|
credit
|
2020-05-17 23:22:56 +00:00
|
|
|
}
|
|
|
|
birthCountry: countryByBirthCountryAlpha2 {
|
|
|
|
alpha2
|
|
|
|
name
|
|
|
|
alias
|
|
|
|
}
|
2021-03-24 00:52:27 +00:00
|
|
|
${actorStashesFields}
|
2020-05-17 23:22:56 +00:00
|
|
|
}
|
2023-06-15 22:47:19 +00:00
|
|
|
${batchFragment}
|
2020-05-17 23:22:56 +00:00
|
|
|
}
|
|
|
|
`, {
|
|
|
|
query,
|
|
|
|
limit,
|
2021-03-24 00:26:33 +00:00
|
|
|
hasAuth: !!store.state.auth.user,
|
|
|
|
userId: store.state.auth.user?.id,
|
2020-05-17 23:22:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2023-06-15 22:47:19 +00:00
|
|
|
releases: res?.results.map((result) => curateRelease(result.release, 'scene', { lastBatch: res?.batches[0].id })) || [],
|
2021-11-20 22:59:15 +00:00
|
|
|
actors: res?.actors.map((actor) => curateActor(actor)) || [],
|
2020-05-17 23:22:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-18 00:42:30 +00:00
|
|
|
async function fetchRandomCampaign(context, { minRatio, maxRatio }) {
|
|
|
|
const { randomCampaign } = await graphql(`
|
|
|
|
query Campaign(
|
|
|
|
$minRatio: BigFloat
|
|
|
|
$maxRatio: BigFloat
|
|
|
|
) {
|
|
|
|
randomCampaign: getRandomCampaign(minRatio: $minRatio, maxRatio: $maxRatio) {
|
2023-07-05 22:14:38 +00:00
|
|
|
${campaignFields}
|
2022-07-18 00:42:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
minRatio,
|
|
|
|
maxRatio,
|
|
|
|
});
|
|
|
|
|
|
|
|
return randomCampaign;
|
|
|
|
}
|
|
|
|
|
2023-07-05 22:14:38 +00:00
|
|
|
async function fetchCampaign(context, campaignId) {
|
|
|
|
const { campaign } = await graphql(`
|
|
|
|
query Campaign(
|
|
|
|
$campaignId: Int!
|
|
|
|
) {
|
|
|
|
campaign(id: $campaignId) {
|
|
|
|
${campaignFields}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
campaignId: Number(campaignId),
|
|
|
|
});
|
|
|
|
|
|
|
|
return campaign;
|
|
|
|
}
|
|
|
|
|
2020-08-15 17:04:33 +00:00
|
|
|
async function fetchStats() {
|
|
|
|
const {
|
|
|
|
scenes,
|
|
|
|
movies,
|
|
|
|
actors,
|
|
|
|
networks,
|
|
|
|
channels,
|
2023-06-24 15:16:06 +00:00
|
|
|
batches: [batch],
|
2020-08-15 17:04:33 +00:00
|
|
|
} = await graphql(`
|
|
|
|
query Stats {
|
2023-06-24 15:16:06 +00:00
|
|
|
scenes: releasesConnection { totalCount }
|
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 }
|
2023-06-24 15:16:06 +00:00
|
|
|
batches(orderBy: CREATED_AT_DESC, first: 1) { createdAt }
|
2020-08-15 17:04:33 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
return {
|
|
|
|
totalScenes: scenes.totalCount,
|
|
|
|
totalMovies: movies.totalCount,
|
|
|
|
totalActors: actors.totalCount,
|
|
|
|
totalNetworks: networks.totalCount,
|
|
|
|
totalChannels: channels.totalCount,
|
2023-06-24 15:16:06 +00:00
|
|
|
lastScrape: new Date(batch.createdAt),
|
2020-08-15 17:04:33 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return {
|
2021-04-25 01:08:50 +00:00
|
|
|
checkNotification,
|
|
|
|
checkNotifications,
|
2020-05-17 23:22:56 +00:00
|
|
|
search,
|
2021-01-03 21:53:51 +00:00
|
|
|
setTagFilter,
|
2022-11-28 02:33:46 +00:00
|
|
|
setSummaryFormat,
|
2020-05-14 02:26:05 +00:00
|
|
|
setRange,
|
|
|
|
setBatch,
|
|
|
|
setSfw,
|
|
|
|
setTheme,
|
2023-07-05 22:14:38 +00:00
|
|
|
fetchCampaign,
|
2022-07-18 00:42:30 +00:00
|
|
|
fetchRandomCampaign,
|
2021-04-22 17:44:23 +00:00
|
|
|
fetchNotifications,
|
2020-08-15 17:04:33 +00:00
|
|
|
fetchStats,
|
2020-05-14 02:26:05 +00:00
|
|
|
};
|
2019-11-15 01:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default initUiActions;
|