Added movies overview page. Fixed channel filter duplicates.

This commit is contained in:
DebaucheryLibrarian 2024-02-27 01:20:15 +01:00
parent ae36a951a0
commit f29246050b
25 changed files with 993 additions and 48 deletions

View File

@ -0,0 +1,6 @@
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<title>clapboard</title>
<path d="M1 2c-0.552 0-1 0.448-1 1v4h16v-5h-15zM1 6v-0.5l2.5-2.5h2l-3 3h-1.5zM4.5 6l3-3h2l-3 3h-2zM8.5 6l3-3h2l-3 3h-2zM15 5.5l-0.5 0.5h-2l2.5-2.5v2z"></path>
<path d="M0 8h16v8h-16v-8z"></path>
</svg>

After

Width:  |  Height:  |  Size: 358 B

View File

@ -0,0 +1,5 @@
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<title>movie</title>
<path d="M8 0c-4.418 0-8 3.582-8 8s3.582 8 8 8 8-3.582 8-8-3.582-8-8-8zM8 1.775c0.943 0 1.708 0.765 1.708 1.708s-0.765 1.708-1.708 1.708c-0.943 0-1.708-0.765-1.708-1.708s0.765-1.708 1.708-1.708zM1.806 6.48c0-0.943 0.765-1.708 1.708-1.708s1.708 0.765 1.708 1.708c0 0.943-0.765 1.708-1.708 1.708s-1.708-0.765-1.708-1.708zM5.288 13.208c-0.943 0-1.708-0.765-1.708-1.708s0.765-1.708 1.708-1.708c0.943 0 1.708 0.765 1.708 1.708s-0.765 1.708-1.708 1.708zM8 9c-0.552 0-1-0.448-1-1s0.448-1 1-1c0.552 0 1 0.448 1 1s-0.448 1-1 1zM10.712 13.218c-0.943 0-1.708-0.765-1.708-1.708s0.765-1.708 1.708-1.708c0.943 0 1.708 0.765 1.708 1.708s-0.765 1.708-1.708 1.708zM12.486 8.198c-0.943 0-1.708-0.765-1.708-1.708s0.765-1.708 1.708-1.708c0.943 0 1.708 0.765 1.708 1.708s-0.765 1.708-1.708 1.708z"></path>
</svg>

After

Width:  |  Height:  |  Size: 944 B

View File

@ -0,0 +1,5 @@
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<title>play2</title>
<path d="M6 5.654v4.692l4.064-2.346zM0 4v10h16v-10h-16zM15 13h-14v-1h14v1zM15 11h-14v-6h14v6z"></path>
</svg>

After

Width:  |  Height:  |  Size: 262 B

View File

@ -0,0 +1,5 @@
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<title>video-camera</title>
<path d="M6 4.5c0-1.381 1.119-2.5 2.5-2.5s2.5 1.119 2.5 2.5c0 1.381-1.119 2.5-2.5 2.5s-2.5-1.119-2.5-2.5zM0 4.5c0-1.381 1.119-2.5 2.5-2.5s2.5 1.119 2.5 2.5c0 1.381-1.119 2.5-2.5 2.5s-2.5-1.119-2.5-2.5zM12 9.5v-1.5c0-0.55-0.45-1-1-1h-10c-0.55 0-1 0.45-1 1v5c0 0.55 0.45 1 1 1h10c0.55 0 1-0.45 1-1v-1.5l4 2.5v-7l-4 2.5zM10 12h-8v-3h8v3z"></path>
</svg>

After

Width:  |  Height:  |  Size: 510 B

View File

@ -118,8 +118,8 @@ const entities = computed(() => {
|| (channel.parent && searchRegexp.value.test(channel.parent.name))
|| (channel.parent && searchRegexp.value.test(channel.parent.slug))));
return Object.values(filteredChannels.reduce((acc, channel) => {
if (!channel.parent || channel.isIndependent) {
const networks = Object.values(filteredChannels.reduce((acc, channel) => {
if (!acc[channel.id] && (channel.type === 'network' || !channel.parent || channel.isIndependent)) { // network may have already been created by a child
acc[channel.id] = {
...channel,
children: [],
@ -128,14 +128,16 @@ const entities = computed(() => {
return acc;
}
if (!acc[channel.parent.id]) {
if (!acc[channel.parent.id] && channel.type === 'channel') {
acc[channel.parent.id] = {
...channel.parent,
children: [],
};
}
acc[channel.parent.id].children.push(channel);
if (channel.type === 'channel') {
acc[channel.parent.id].children.push(channel);
}
return acc;
}, {}))
@ -146,6 +148,8 @@ const entities = computed(() => {
}))
.sort(sort)
.flatMap((network) => [network, ...(network.children || [])]);
return networks;
});
</script>

View File

@ -97,6 +97,10 @@ defineProps({
background: var(--background-base);
border-radius: .25rem;
box-shadow: 0 0 3px var(--shadow-weak-30);
&:hover {
box-shadow: 0 0 3px var(--shadow-weak-20);
}
}
.poster {

View File

@ -139,7 +139,9 @@ const scrollable = computed(() => children.value?.scrollWidth > children.value?.
.logo {
height: 2.5rem;
max-width: 15rem;
padding: .75rem 1rem;
object-fit: contain;
}
.link-parent {

404
pages/movies/+Page.vue Normal file
View File

@ -0,0 +1,404 @@
<template>
<div class="page">
<Filters
v-if="showFilters"
:class="{ loading }"
>
<div class="filter">
<input
v-model="filters.search"
type="search"
placeholder="Search movies"
class="search input"
@search="search"
>
</div>
<TagsFilter
:filters="filters"
:tags="aggTags"
@update="updateFilter"
/>
<ChannelsFilter
:filters="filters"
:channels="aggChannels"
@update="updateFilter"
/>
<ActorsFilter
:filters="filters"
:actors="aggActors"
@update="updateFilter"
/>
</Filters>
<ul class="movies nolist">
<li
v-for="movie in movies"
:key="`movie-${movie.id}`"
class="movie"
>
<a
:href="`/movie/${movie.id}/${movie.slug}`"
:title="movie.title"
class="cover-container"
>
<img
v-if="movie.covers[0]"
:src="movie.covers[0].isS3 ? `https://cdndev.traxxx.me/${movie.covers[0].thumbnail}` : `/media/${movie.covers[0].thumbnail}`"
:style="{ 'background-image': movie.covers[0].isS3 ? `url(https://cdndev.traxxx.me/${movie.covers[0].lazy})` : `url(/media/${movie.covers[0].lazy})` }"
class="cover"
loading="lazy"
>
<img
v-else
src="/public/img/icons/movie.svg"
class="nocover"
>
</a>
<div class="meta">
<div class="channel">
<Link
:href="movie.channel.isIndependent || !movie.network ? `/${movie.channel.type}/${movie.channel.slug}` : `/${movie.network.type}/${movie.network.slug}`"
class="favicon-link"
>
<img
:src="movie.channel.isIndependent || !movie.network ? `/logos/${movie.channel.slug}/favicon.png` : `/logos/${movie.network.slug}/favicon.png`"
class="favicon"
>
</Link>
<Link
:href="`/${movie.channel.type}/${movie.channel.slug}`"
class="nolink channel-link"
>{{ movie.channel.name }}</Link>
</div>
<time
:datetime="movie.effectiveDate.toISOString()"
class="date"
:class="{ nodate: !movie.date }"
>{{ format(movie.effectiveDate, movie.effectiveDate.getFullYear() === currentYear ? 'MMM d' : 'MMM d, y') }}</time>
</div>
<a
:href="`/movie/${movie.id}/${movie.slug}`"
:title="movie.title"
class="title nolink"
>{{ movie.title }}</a>
<ul
:title="movie.actors.map((actor) => actor.name).join(', ')"
class="actors nolist"
>
<li
v-for="actor in movie.actors"
:key="`actor-${movie.id}-${actor.slug}`"
class="actor-item"
>
<a
:href="`/actor/${actor.id}/${actor.slug}`"
class="actor nolink"
>{{ actor.name }}</a>
</li>
</ul>
<ul
:title="movie.tags.map((tag) => tag.name).join(', ')"
class="tags nolist"
>
<li
v-for="tag in movie.tags"
:key="`tag-${movie.id}-${tag.slug}`"
>
<a
:href="`/tag/${tag.slug}`"
class="tag nolink"
>{{ tag.name }}</a>
</li>
</ul>
</li>
</ul>
</div>
</template>
<script setup>
import { ref, inject } from 'vue';
import { format } from 'date-fns';
import { parse } from 'path-to-regexp';
import navigate from '#/src/navigate.js';
import { get } from '#/src/api.js';
import { getActorIdentifier, parseActorIdentifier } from '#/src/query.js';
import events from '#/src/events.js';
import Filters from '#/components/filters/filters.vue';
import ActorsFilter from '#/components/filters/actors.vue';
import TagsFilter from '#/components/filters/tags.vue';
import ChannelsFilter from '#/components/filters/channels.vue';
const pageContext = inject('pageContext');
const { pageProps, routeParams, urlParsed } = pageContext;
const {
actor: pageActor,
tag: pageTag,
entity: pageEntity,
} = pageProps;
const movies = ref(pageProps.movies);
const aggActors = ref(pageProps.aggActors || []);
const aggTags = ref(pageProps.aggTags || []);
const aggChannels = ref(pageProps.aggChannels || []);
const currentPage = ref(Number(routeParams.page));
const scope = ref(routeParams.scope);
const total = ref(Number(pageProps.total));
const loading = ref(false);
const showFilters = ref(true);
const currentYear = new Date().getFullYear();
const actorIds = urlParsed.search.actors?.split(',').map((identifier) => parseActorIdentifier(identifier)?.id).filter(Boolean) || [];
const queryActors = actorIds.map((urlActorId) => aggActors.value.find((aggActor) => aggActor.id === urlActorId)).filter(Boolean);
const networks = Object.fromEntries(aggChannels.value.map((channel) => (channel.type === 'network' ? channel : channel.parent)).filter(Boolean).map((parent) => [`_${parent.slug}`, parent]));
const channels = Object.fromEntries(aggChannels.value.filter((channel) => channel.type === 'channel').map((channel) => [channel.slug, channel]));
const queryEntity = networks[urlParsed.search.e] || channels[urlParsed.search.e];
const filters = ref({
search: urlParsed.search.q,
tags: urlParsed.search.tags?.split(',').filter(Boolean) || [],
entity: queryEntity,
actors: queryActors,
});
function getPath(targetScope, preserveQuery) {
const path = parse(routeParams.path).map((segment) => {
if (segment.name === 'scope') {
return `${segment.prefix}${targetScope}`;
}
if (segment.name === 'page') {
return `${segment.prefix}${1}`;
}
return `${segment.prefix || ''}${routeParams[segment.name] || segment}`;
}).join('');
if (preserveQuery && urlParsed.searchOriginal) {
return `${path}${urlParsed.searchOriginal}`;
}
return path;
}
async function search(options = {}) {
if (options.resetPage !== false) {
currentPage.value = 1;
}
if (options.autoScope !== false) {
if (filters.value.search) {
scope.value = 'results';
}
if (!filters.value.search && scope.value === 'results') {
scope.value = 'latest';
}
}
const query = {
q: filters.value.search || undefined,
};
const entity = filters.value.entity || pageEntity;
const entitySlug = entity?.type === 'network' ? `_${entity.slug}` : entity?.slug;
loading.value = true;
navigate(getPath(scope.value, false), {
...query,
actors: filters.value.actors.map((filterActor) => getActorIdentifier(filterActor)).join(',') || undefined, // don't include page actor ID in query, already a parameter
tags: filters.value.tags.join(',') || undefined,
e: filters.value.entity?.type === 'network' ? `_${filters.value.entity.slug}` : (filters.value.entity?.slug || undefined),
}, { redirect: false });
const res = await get('/movies', {
...query,
actors: [pageActor, ...filters.value.actors].filter(Boolean).map((filterActor) => getActorIdentifier(filterActor)).join(','), // if we're on an actor page, that actor ID needs to be included
tags: [pageTag?.slug, ...filters.value.tags].filter(Boolean).join(','),
e: entitySlug,
scope: scope.value,
page: currentPage.value, // client uses param rather than query pagination
});
movies.value = res.movies;
aggActors.value = res.aggActors;
aggTags.value = res.aggTags;
aggChannels.value = res.aggChannels;
total.value = res.total;
loading.value = false;
events.emit('scrollUp');
}
function updateFilter(prop, value, reload = true) {
filters.value[prop] = value;
if (reload) {
search();
}
}
</script>
<style scoped>
.page {
display: flex;
background: var(--background-base-10);
}
.movies {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
gap: 1rem;
padding: 1rem;
}
.movie {
max-height: 30rem;
display: flex;
flex-direction: column;
box-shadow: 0 0 3px var(--shadow-weak-30);
border-radius: .25rem;
overflow: hidden;
background: var(--background-base);
&:hover {
box-shadow: 0 0 3px var(--shadow-weak-20);
}
}
.cover-container {
display: flex;
align-items: center;
justify-content: center;
flex-grow: 1;
background: var(--shadow-weak-30);
aspect-ratio: 5/7;
}
.cover {
width: 100%;
height: 100%;
object-fit: cover;
background-size: cover;
background-position: center;
}
.nocover {
width: 25%;
opacity: .1;
}
.meta {
display: flex;
justify-content: space-between;
align-items: center;
padding: .4rem .5rem;
border-radius: 0 0 .25rem .25rem;
margin-bottom: .5rem;
background: var(--shadow-strong-30);
color: var(--text-light);
font-size: .8rem;
}
.channel {
display: inline-flex;
align-items: center;
margin-right: .5rem;
white-space: nowrap;
overflow: hidden;
}
.channel-link {
overflow: hidden;
text-overflow: ellipsis;
font-weight: bold;
}
.favicon-link {
display: inline-flex;
}
.favicon {
width: 1rem;
height: 1rem;
margin-right: .5rem;
object-fit: contain;
}
.date {
flex-shrink: 0;
}
.nodate {
color: var(--highlight-strong-10);
}
.title {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-weight: bold;
padding: 0 .5rem;
margin-bottom: .25rem;
}
.actors {
height: 2.4rem;
display: flex;
flex-wrap: wrap;
overflow: hidden;
font-size: .9rem;
padding: 0 .5rem;
margin-bottom: .35rem;
line-height: 1.35;
}
.actor-item:not(:last-child):after {
content: ',\00a0';
}
.actor {
&:hover {
color: var(--primary);
}
}
.tags {
height: 1rem;
display: flex;
flex-wrap: wrap;
gap: .5rem;
overflow: hidden;
padding: 0 .5rem;
margin-bottom: .25rem;
color: var(--shadow-strong-10);
font-size: .75rem;
}
.tag {
flex-shrink: 0;
&:hover {
color: var(--primary);
}
}
</style>

View File

@ -0,0 +1,36 @@
import { fetchMovies } from '#/src/movies.js';
import { curateMoviesQuery } from '#/src/web/movies.js';
export async function onBeforeRender(pageContext) {
const movieResults = await fetchMovies(await curateMoviesQuery({
...pageContext.urlQuery,
scope: pageContext.routeParams.scope || 'latest',
}), {
page: Number(pageContext.routeParams.page) || 1,
limit: Number(pageContext.urlParsed.search.limit) || 50,
aggregate: true,
});
const {
movies,
aggActors,
aggTags,
aggChannels,
total,
limit,
} = movieResults;
return {
pageContext: {
title: 'Movies',
pageProps: {
movies,
aggActors,
aggTags,
aggChannels,
limit,
total,
},
},
};
}

21
pages/movies/+route.js Normal file
View File

@ -0,0 +1,21 @@
import { match } from 'path-to-regexp';
// import { resolveRoute } from 'vike/routing'; // eslint-disable-line import/extensions
const path = '/movies/:scope?/:page?';
const urlMatch = match(path, { decode: decodeURIComponent });
export default (pageContext) => {
const matched = urlMatch(pageContext.urlPathname);
if (matched) {
return {
routeParams: {
scope: matched.params.scope || 'latest',
page: matched.params.page || '1',
path,
},
};
}
return false;
};

View File

@ -4,10 +4,10 @@ const tagSlugs = {
popular: [
'anal',
'lesbian',
'interracial',
// 'interracial',
'mff',
'mfm',
'teen',
// 'teen',
'milf',
'blowjob',
'gay',
@ -38,21 +38,13 @@ const tagSlugs = {
],
oral: [
'blowjob',
'pussy-eating',
'ass-eating',
'deepthroat',
'facefucking',
'pussy-eating',
'ass-eating',
'69',
'atm',
],
manual: [
'handjob',
'fingering',
'anal-fingering',
'titty-fucking',
'fisting',
'anal-fisting',
],
group: [
'mfm',
'mff',
@ -62,14 +54,14 @@ const tagSlugs = {
],
cumshot: [
'facial',
'bukkake',
'creampie',
'anal-creampie',
'oral-creampie',
'cum-in-mouth',
'cum-on-boobs',
'cum-on-butt',
'cum-on-pussy',
'anal-creampie',
'oral-creampie',
'bukkake',
'fake-cum',
],
roleplay: [
@ -78,7 +70,6 @@ const tagSlugs = {
'schoolgirl',
'nurse',
'maid',
'nun',
],
extreme: [
'dp',
@ -97,6 +88,14 @@ const tagSlugs = {
'latex',
'blindfold',
],
manual: [
'handjob',
'fingering',
'anal-fingering',
'titty-fucking',
'fisting',
'anal-fisting',
],
toys: [
'toys',
'toy-anal',

View File

@ -0,0 +1,5 @@
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<title>clapboard-play</title>
<path d="M1.223 4.102l13.523-3.623 0.776 2.898-13.523 3.623zM2 7v9h14v-9h-14zM7 14v-5l4 2.5-4 2.5z"></path>
</svg>

After

Width:  |  Height:  |  Size: 276 B

View File

@ -0,0 +1,6 @@
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<title>clapboard</title>
<path d="M1 2c-0.552 0-1 0.448-1 1v4h16v-5h-15zM1 6v-0.5l2.5-2.5h2l-3 3h-1.5zM4.5 6l3-3h2l-3 3h-2zM8.5 6l3-3h2l-3 3h-2zM15 5.5l-0.5 0.5h-2l2.5-2.5v2z"></path>
<path d="M0 8h16v8h-16v-8z"></path>
</svg>

After

Width:  |  Height:  |  Size: 358 B

5
public/img/icons/film2.svg Executable file
View File

@ -0,0 +1,5 @@
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<title>film2</title>
<path d="M0 1v14h16v-14h-16zM3 14h-2v-2h2v2zM3 11h-2v-2h2v2zM3 7h-2v-2h2v2zM3 4h-2v-2h2v2zM12 14h-8v-5h8v5zM12 7h-8v-5h8v5zM15 14h-2v-2h2v2zM15 11h-2v-2h2v2zM15 7h-2v-2h2v2zM15 4h-2v-2h2v2z"></path>
</svg>

After

Width:  |  Height:  |  Size: 358 B

5
public/img/icons/film3.svg Executable file
View File

@ -0,0 +1,5 @@
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<title>film3</title>
<path d="M0 2v12h16v-12h-16zM3 13h-2v-2h2v2zM3 9h-2v-2h2v2zM3 5h-2v-2h2v2zM12 13h-8v-10h8v10zM15 13h-2v-2h2v2zM15 9h-2v-2h2v2zM15 5h-2v-2h2v2z"></path>
</svg>

After

Width:  |  Height:  |  Size: 311 B

View File

@ -0,0 +1,5 @@
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<title>movie</title>
<path d="M8 0c-4.418 0-8 3.582-8 8s3.582 8 8 8 8-3.582 8-8-3.582-8-8-8zM8 1.775c0.943 0 1.708 0.765 1.708 1.708s-0.765 1.708-1.708 1.708c-0.943 0-1.708-0.765-1.708-1.708s0.765-1.708 1.708-1.708zM1.806 6.48c0-0.943 0.765-1.708 1.708-1.708s1.708 0.765 1.708 1.708c0 0.943-0.765 1.708-1.708 1.708s-1.708-0.765-1.708-1.708zM5.288 13.208c-0.943 0-1.708-0.765-1.708-1.708s0.765-1.708 1.708-1.708c0.943 0 1.708 0.765 1.708 1.708s-0.765 1.708-1.708 1.708zM8 9c-0.552 0-1-0.448-1-1s0.448-1 1-1c0.552 0 1 0.448 1 1s-0.448 1-1 1zM10.712 13.218c-0.943 0-1.708-0.765-1.708-1.708s0.765-1.708 1.708-1.708c0.943 0 1.708 0.765 1.708 1.708s-0.765 1.708-1.708 1.708zM12.486 8.198c-0.943 0-1.708-0.765-1.708-1.708s0.765-1.708 1.708-1.708c0.943 0 1.708 0.765 1.708 1.708s-0.765 1.708-1.708 1.708z"></path>
</svg>

After

Width:  |  Height:  |  Size: 944 B

View File

@ -74,17 +74,19 @@ export function sortActorsByGender(actors) {
export async function fetchActorsById(actorIds, options = {}) {
const [actors] = await Promise.all([
knex('actors_meta')
knex('actors')
.select(
'actors.*',
'actors_meta.*',
'birth_countries.alpha2 as birth_country_alpha2',
knex.raw('COALESCE(birth_countries.alias, birth_countries.name) as birth_country_name'),
'residence_countries.alpha2 as residence_country_alpha2',
knex.raw('COALESCE(residence_countries.alias, residence_countries.name) as residence_country_name'),
)
.leftJoin('countries as birth_countries', 'birth_countries.alpha2', 'actors_meta.birth_country_alpha2')
.leftJoin('countries as residence_countries', 'residence_countries.alpha2', 'actors_meta.residence_country_alpha2')
.whereIn('actors_meta.id', actorIds)
.leftJoin('actors_meta', 'actors_meta.actor_id', 'actors.id')
.leftJoin('countries as birth_countries', 'birth_countries.alpha2', 'actors.birth_country_alpha2')
.leftJoin('countries as residence_countries', 'residence_countries.alpha2', 'actors.residence_country_alpha2')
.whereIn('actors.id', actorIds)
.modify((builder) => {
if (options.order) {
builder.orderBy(...options.order);

19
src/cache.js Normal file
View File

@ -0,0 +1,19 @@
import redis from './redis.js';
export async function getIdsBySlug(slugs, domain) {
const ids = await Promise.all(slugs.map(async (slug) => {
if (!slug) {
return null;
}
if (Number(slug)) {
return Number(slug); // already an ID or missing
}
const id = await redis.hGet(`traxxx:${domain}:id_by_slug`, slug);
return Number(id);
}));
return ids.filter(Boolean);
}

View File

@ -86,6 +86,24 @@ export async function fetchEntitiesById(entityIds, options = {}) {
return curatedEntities;
}
export async function getEntityIdsBySlug(slugs, domain) {
const ids = await Promise.all(slugs.map(async (slug) => {
if (!slug) {
return null;
}
if (Number(slug)) {
return Number(slug); // already an ID or missing
}
const id = await redis.hGet(`traxxx:${domain}:id_by_slug`, slug);
return Number(id);
}));
return ids.filter(Boolean);
}
export async function cacheEntityIds() {
const entities = await knex('entities').select('id', 'slug', 'type');

365
src/movies.js Normal file
View File

@ -0,0 +1,365 @@
import knex from './knex.js';
import { searchApi } from './manticore.js';
import { HttpError } from './errors.js';
import { fetchActorsById, curateActor, sortActorsByGender } from './actors.js';
import { fetchTagsById } from './tags.js';
import { fetchEntitiesById } from './entities.js';
function curateMedia(media) {
if (!media) {
return null;
}
return {
id: media.id,
path: media.path,
thumbnail: media.thumbnail,
lazy: media.lazy,
isS3: media.is_s3,
width: media.width,
height: media.height,
};
}
function curateMovie(rawScene, assets) {
if (!rawScene) {
return null;
}
return {
id: rawScene.id,
title: rawScene.title,
slug: rawScene.slug,
url: rawScene.url,
date: rawScene.date,
createdAt: rawScene.created_at,
effectiveDate: rawScene.effective_date,
description: rawScene.description,
duration: rawScene.duration,
channel: {
id: assets.channel.id,
slug: assets.channel.slug,
name: assets.channel.name,
type: assets.channel.type,
isIndependent: assets.channel.independent,
hasLogo: assets.channel.has_logo,
},
network: assets.channel.network_id ? {
id: assets.channel.network_id,
slug: assets.channel.network_slug,
name: assets.channel.network_name,
type: assets.channel.network_type,
hasLogo: assets.channel.has_logo,
} : null,
actors: sortActorsByGender(assets.actors.map((actor) => curateActor(actor, { sceneDate: rawScene.effective_date }))),
directors: assets.directors.map((director) => ({
id: director.id,
slug: director.slug,
name: director.name,
})),
tags: assets.tags.map((tag) => ({
id: tag.id,
slug: tag.slug,
name: tag.name,
})),
poster: curateMedia(assets.poster),
covers: assets.covers.map((cover) => curateMedia(cover)),
photos: assets.photos.map((photo) => curateMedia(photo)),
createdBatchId: rawScene.created_batch_id,
updatedBatchId: rawScene.updated_batch_id,
};
}
export async function fetchMoviesById(movieIds) {
const [movies, channels, actors, directors, tags, covers, photos] = await Promise.all([
knex('movies').whereIn('id', movieIds),
// channels
knex('movies')
.select('channels.*', 'networks.id as network_id', 'networks.slug as network_slug', 'networks.name as network_name', 'networks.type as network_type')
.whereIn('movies.id', movieIds)
.leftJoin('entities as channels', 'channels.id', 'movies.entity_id')
.leftJoin('entities as networks', 'networks.id', 'channels.parent_id')
.groupBy('channels.id', 'networks.id'),
// actors
knex('movies')
.select(
'actors.*',
'actors_meta.*',
'releases_actors.release_id',
'movies.id as movie_id',
)
.distinctOn('actors.id', 'movies.id') // cannot distinct on JSON column avatar, must specify
.whereIn('movies.id', movieIds)
.whereNotNull('actors.id')
.leftJoin('movies_scenes', 'movies_scenes.movie_id', 'movies.id')
.leftJoin('releases_actors', 'releases_actors.release_id', 'movies_scenes.scene_id')
.leftJoin('actors', 'actors.id', 'releases_actors.actor_id')
.leftJoin('actors_meta', 'actors_meta.actor_id', 'actors.id'),
// directors
knex('movies')
.whereIn('movies.id', movieIds)
.leftJoin('movies_scenes', 'movies_scenes.movie_id', 'movies.id')
.leftJoin('releases_directors', 'releases_directors.release_id', 'movies_scenes.scene_id')
.leftJoin('actors as directors', 'directors.id', 'releases_directors.director_id'),
// tags
knex('movies')
.select('tags.id', 'tags.slug', 'tags.name', 'tags.priority', 'movies.id as movie_id')
.distinct()
.whereIn('movies.id', movieIds)
.whereNotNull('tags.id')
.leftJoin('movies_scenes', 'movies_scenes.movie_id', 'movies.id')
.leftJoin('releases_tags', 'releases_tags.release_id', 'movies_scenes.scene_id')
.leftJoin('tags', 'tags.id', 'releases_tags.tag_id')
.orderBy('priority', 'desc'),
// covers
knex('movies_covers')
.whereIn('movie_id', movieIds)
.leftJoin('media', 'media.id', 'movies_covers.media_id'),
// photos
knex('movies')
.whereIn('movies.id', movieIds)
.leftJoin('movies_scenes', 'movies_scenes.movie_id', 'movies.id')
.leftJoin('releases_photos', 'releases_photos.release_id', 'movies_scenes.scene_id')
.leftJoin('media', 'media.id', 'releases_photos.media_id'),
]);
return movieIds.map((movieId) => {
const movie = movies.find((movieEntry) => movieEntry.id === movieId);
if (!movie) {
console.warn('cannot find movie', movieId);
return null;
}
const movieChannel = channels.find((entity) => entity.id === movie.entity_id);
const movieActors = actors.filter((actor) => actor.movie_id === movieId);
const movieDirectors = directors.filter((director) => director.release_id === movieId);
const movieTags = tags.filter((tag) => tag.movie_id === movieId);
const movieCovers = covers.filter((cover) => cover.movie_id === movieId);
const moviePhotos = photos.filter((photo) => photo.release_id === movieId);
return curateMovie(movie, {
channel: movieChannel,
actors: movieActors,
directors: movieDirectors,
tags: movieTags,
covers: movieCovers,
photos: moviePhotos,
});
}).filter(Boolean);
}
function curateOptions(options) {
if (options?.limit > 100) {
throw new HttpError('Limit must be <= 100', 400);
}
return {
limit: options?.limit || 30,
page: Number(options?.page) || 1,
aggregate: options.aggregate ?? true,
aggregateActors: (options.aggregate ?? true) && (options.aggregateActors ?? true),
aggregateTags: (options.aggregate ?? true) && (options.aggregateTags ?? true),
aggregateChannels: (options.aggregate ?? true) && (options.aggregateChannels ?? true),
};
}
function buildQuery(filters = {}) {
const query = {
bool: {
must: [],
},
};
let sort = [{ effective_date: 'desc' }];
if (!filters.scope || filters.scope === 'latest') {
query.bool.must.push({
range: {
effective_date: {
lte: Math.round(Date.now() / 1000),
},
},
});
}
if (filters.scope === 'upcoming') {
query.bool.must.push({
range: {
effective_date: {
gt: Math.round(Date.now() / 1000),
},
},
});
sort = [{ effective_date: 'asc' }];
}
if (filters.scope === 'new') {
sort = [{ created_at: 'desc' }, { effective_date: 'asc' }];
}
if (filters.scope === 'likes') {
sort = [{ stashed: 'desc' }, { effective_date: 'desc' }];
}
if (filters.scope === 'results') {
sort = [{ _score: 'desc' }, { effective_date: 'desc' }];
}
if (filters.query) {
query.bool.must.push({
bool: {
should: [
{ match: { title_filtered: filters.query } },
{ match: { actors: filters.query } },
{ match: { tags: filters.query } },
{ match: { channel_name: filters.query } },
{ match: { network_name: filters.query } },
{ match: { channel_slug: filters.query } },
{ match: { network_slug: filters.query } },
{ match: { meta: filters.query } }, // date
],
},
});
}
if (filters.tagIds) {
filters.tagIds.forEach((tagId) => {
query.bool.must.push({ equals: { 'any(tag_ids)': tagId } });
});
}
if (filters.entityId) {
query.bool.must.push({
bool: {
should: [
{ equals: { channel_id: filters.entityId } },
{ equals: { network_id: filters.entityId } },
],
},
});
}
if (filters.actorIds) {
filters.actorIds.forEach((actorId) => {
query.bool.must.push({ equals: { 'any(actor_ids)': actorId } });
});
}
if (filters.requireCover) {
query.bool.must.push({
equals: {
has_cover: 1,
},
});
}
/* tag filter
must_not: [
{
in: {
'any(tag_ids)': [101, 180, 32],
},
},
],
*/
return { query, sort };
}
function buildAggregates(options) {
const aggregates = {};
if (options.aggregateActors) {
aggregates.actorIds = {
terms: {
field: 'actor_ids',
size: 5000,
},
// sort: [{ doc_count: { order: 'asc' } }],
};
}
if (options.aggregateTags) {
aggregates.tagIds = {
terms: {
field: 'tag_ids',
size: 1000,
},
};
}
if (options.aggregateChannels) {
aggregates.channelIds = {
terms: {
field: 'channel_id',
size: 1000,
},
};
}
return aggregates;
}
function countAggregations(buckets) {
if (!buckets) {
return null;
}
return Object.fromEntries(buckets.map((bucket) => [bucket.key, { count: bucket.doc_count }]));
}
export async function fetchMovies(filters, rawOptions) {
const options = curateOptions(rawOptions);
const { query, sort } = buildQuery(filters);
console.log('filters', filters);
console.log('options', options);
console.log('query', query.bool.must);
const result = await searchApi.search({
index: 'movies',
query,
limit: options.limit,
offset: (options.page - 1) * options.limit,
sort,
aggs: buildAggregates(options),
options: {
max_matches: 1000,
max_query_time: 10000,
field_weights: {
title_filtered: 7,
actors: 10,
tags: 9,
meta: 6,
channel_name: 2,
channel_slug: 3,
network_name: 1,
network_slug: 1,
},
},
});
const actorCounts = options.aggregateActors && countAggregations(result.aggregations?.actorIds?.buckets);
const tagCounts = options.aggregateTags && countAggregations(result.aggregations?.tagIds?.buckets);
const channelCounts = options.aggregateChannels && countAggregations(result.aggregations?.channelIds?.buckets);
const [aggActors, aggTags, aggChannels] = await Promise.all([
options.aggregateActors ? fetchActorsById(result.aggregations.actorIds.buckets.map((bucket) => bucket.key), { order: ['name', 'asc'], append: actorCounts }) : [],
options.aggregateTags ? fetchTagsById(result.aggregations.tagIds.buckets.map((bucket) => bucket.key), { order: ['name', 'asc'], append: tagCounts }) : [],
options.aggregateChannels ? fetchEntitiesById(result.aggregations.channelIds.buckets.map((bucket) => bucket.key), { order: ['name', 'asc'], append: channelCounts }) : [],
]);
const movieIds = result.hits.hits.map((hit) => Number(hit._id));
const movies = await fetchMoviesById(movieIds);
return {
movies,
aggActors,
aggTags,
aggChannels,
total: result.hits.total,
limit: options.limit,
};
}

View File

@ -80,6 +80,7 @@ export async function fetchScenesById(sceneIds) {
.groupBy('channels.id', 'networks.id'),
knex('releases_actors')
.select(
'actors.*',
'actors_meta.*',
'releases_actors.release_id',
/* why would we need this for scenes?
@ -90,7 +91,8 @@ export async function fetchScenesById(sceneIds) {
*/
)
.whereIn('release_id', sceneIds)
.leftJoin('actors_meta', 'actors_meta.id', 'releases_actors.actor_id'),
.leftJoin('actors', 'actors.id', 'releases_actors.actor_id')
.leftJoin('actors_meta', 'actors_meta.actor_id', 'actors.id'),
/*
.leftJoin('countries as birth_countries', 'birth_countries.alpha2', 'actors_meta.birth_country_alpha2')
.leftJoin('countries as residence_countries', 'residence_countries.alpha2', 'actors_meta.residence_country_alpha2'),
@ -321,8 +323,6 @@ export async function fetchScenes(filters, rawOptions) {
},
});
console.log(result.hits.hits);
const actorCounts = options.aggregateActors && countAggregations(result.aggregations?.actorIds?.buckets);
const tagCounts = options.aggregateTags && countAggregations(result.aggregations?.tagIds?.buckets);
const channelCounts = options.aggregateChannels && countAggregations(result.aggregations?.channelIds?.buckets);

39
src/web/movies.js Normal file
View File

@ -0,0 +1,39 @@
import { stringify } from '@brillout/json-serializer/stringify'; /* eslint-disable-line import/extensions */
import { fetchMovies } from '../movies.js';
import { parseActorIdentifier } from '../query.js';
import { getIdsBySlug } from '../cache.js';
export async function curateMoviesQuery(query) {
return {
scope: query.scope || 'latest',
query: query.q,
actorIds: [query.actorId, ...(query.actors?.split(',') || []).map((identifier) => parseActorIdentifier(identifier)?.id)].filter(Boolean),
tagIds: await getIdsBySlug([query.tagSlug, ...(query.tags?.split(',') || [])], 'tags'),
entityId: query.e ? await getIdsBySlug([query.e], 'entities').then(([id]) => id) : query.entityId,
requireCover: query.cover,
};
}
export async function fetchMoviesApi(req, res) {
const {
movies,
aggActors,
aggTags,
aggChannels,
limit,
total,
} = await fetchMovies(await curateMoviesQuery(req.query), {
page: Number(req.query.page) || 1,
limit: Number(req.query.limit) || 30,
});
res.send(stringify({
movies,
aggActors,
aggTags,
aggChannels,
limit,
total,
}));
}

View File

@ -2,25 +2,7 @@ import { stringify } from '@brillout/json-serializer/stringify'; /* eslint-disab
import { fetchScenes } from '../scenes.js';
import { parseActorIdentifier } from '../query.js';
import redis from '../redis.js';
async function getIdsBySlug(slugs, domain) {
const ids = await Promise.all(slugs.map(async (slug) => {
if (!slug) {
return null;
}
if (Number(slug)) {
return Number(slug); // already an ID or missing
}
const id = await redis.hGet(`traxxx:${domain}:id_by_slug`, slug);
return Number(id);
}));
return ids.filter(Boolean);
}
import { getIdsBySlug } from '../cache.js';
export async function curateScenesQuery(query) {
return {

View File

@ -22,6 +22,7 @@ import { renderPage } from 'vike/server'; // eslint-disable-line import/extensio
import { fetchScenesApi } from './scenes.js';
import { fetchActorsApi } from './actors.js';
import { fetchMoviesApi } from './movies.js';
import initLogger from '../logger.js';
@ -62,9 +63,11 @@ export default async function initServer() {
router.use(viteDevMiddleware);
}
router.get('/api/scenes', fetchScenesApi);
router.get('/api/actors', fetchActorsApi);
router.get('/api/scenes', fetchScenesApi);
router.get('/api/movies', fetchMoviesApi);
// ...
// Other middlewares (e.g. some RPC middleware such as Telefunc)

2
static

@ -1 +1 @@
Subproject commit 62c8a043692d973e6aadb45f3ca3dfc78466f3b6
Subproject commit a501e96b89785229e447456bfaf2b17954139121