Added movie page. Added stash button to movies.
This commit is contained in:
+52
-36
@@ -1,11 +1,13 @@
|
||||
import config from 'config';
|
||||
|
||||
import { knexQuery as knex, knexManticore } from './knex.js';
|
||||
import { knexQuery as knex, knexOwner, knexManticore } from './knex.js';
|
||||
import { utilsApi } 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';
|
||||
import { curateStash } from './stashes.js';
|
||||
import promiseProps from '../utils/promise-props.js';
|
||||
|
||||
function curateMedia(media) {
|
||||
if (!media) {
|
||||
@@ -23,21 +25,21 @@ function curateMedia(media) {
|
||||
};
|
||||
}
|
||||
|
||||
function curateMovie(rawScene, assets) {
|
||||
if (!rawScene) {
|
||||
function curateMovie(rawMovie, assets) {
|
||||
if (!rawMovie) {
|
||||
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,
|
||||
id: rawMovie.id,
|
||||
title: rawMovie.title,
|
||||
slug: rawMovie.slug,
|
||||
url: rawMovie.url,
|
||||
date: rawMovie.date,
|
||||
createdAt: rawMovie.created_at,
|
||||
effectiveDate: rawMovie.effective_date,
|
||||
description: rawMovie.description,
|
||||
duration: rawMovie.duration,
|
||||
channel: {
|
||||
id: assets.channel.id,
|
||||
slug: assets.channel.slug,
|
||||
@@ -53,7 +55,7 @@ function curateMovie(rawScene, assets) {
|
||||
type: assets.channel.network_type,
|
||||
hasLogo: assets.channel.has_logo,
|
||||
} : null,
|
||||
actors: sortActorsByGender(assets.actors.map((actor) => curateActor(actor, { sceneDate: rawScene.effective_date }))),
|
||||
actors: sortActorsByGender(assets.actors.map((actor) => curateActor(actor, { sceneDate: rawMovie.effective_date }))),
|
||||
directors: assets.directors.map((director) => ({
|
||||
id: director.id,
|
||||
slug: director.slug,
|
||||
@@ -67,23 +69,36 @@ function curateMovie(rawScene, assets) {
|
||||
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,
|
||||
stashes: assets.stashes?.map((stash) => curateStash(stash)) || [],
|
||||
createdBatchId: rawMovie.created_batch_id,
|
||||
updatedBatchId: rawMovie.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')
|
||||
export async function fetchMoviesById(movieIds, reqUser) {
|
||||
const {
|
||||
movies,
|
||||
channels,
|
||||
actors,
|
||||
directors,
|
||||
tags,
|
||||
covers,
|
||||
photos,
|
||||
stashes,
|
||||
} = await promiseProps({
|
||||
movies: knex('movies')
|
||||
.select('movies.*', knex.raw('sum(releases.duration) as duration'))
|
||||
.leftJoin('movies_scenes', 'movies_scenes.movie_id', 'movies.id')
|
||||
.leftJoin('releases', 'releases.id', 'movies_scenes.scene_id')
|
||||
.whereIn('movies.id', movieIds)
|
||||
.groupBy('movies.id'),
|
||||
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')
|
||||
actors: knex('movies')
|
||||
.select(
|
||||
'actors.*',
|
||||
'actors_meta.*',
|
||||
@@ -97,14 +112,12 @@ export async function fetchMoviesById(movieIds) {
|
||||
.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')
|
||||
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')
|
||||
tags: knex('movies')
|
||||
.select('tags.id', 'tags.slug', 'tags.name', 'tags.priority', 'movies.id as movie_id')
|
||||
.distinct()
|
||||
.whereIn('movies.id', movieIds)
|
||||
@@ -113,17 +126,21 @@ export async function fetchMoviesById(movieIds) {
|
||||
.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')
|
||||
covers: knex('movies_covers')
|
||||
.whereIn('movie_id', movieIds)
|
||||
.leftJoin('media', 'media.id', 'movies_covers.media_id'),
|
||||
// photos
|
||||
knex('movies')
|
||||
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'),
|
||||
]);
|
||||
stashes: reqUser
|
||||
? knexOwner('stashes_movies')
|
||||
.leftJoin('stashes', 'stashes.id', 'stashes_movies.stash_id')
|
||||
.where('stashes.user_id', reqUser.id)
|
||||
.whereIn('stashes_movies.movie_id', movieIds)
|
||||
: [],
|
||||
});
|
||||
|
||||
return movieIds.map((movieId) => {
|
||||
const movie = movies.find((movieEntry) => movieEntry.id === movieId);
|
||||
@@ -139,6 +156,7 @@ export async function fetchMoviesById(movieIds) {
|
||||
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);
|
||||
const movieStashes = stashes.filter((stash) => stash.movie_id === movieId);
|
||||
|
||||
return curateMovie(movie, {
|
||||
channel: movieChannel,
|
||||
@@ -147,6 +165,7 @@ export async function fetchMoviesById(movieIds) {
|
||||
tags: movieTags,
|
||||
covers: movieCovers,
|
||||
photos: moviePhotos,
|
||||
stashes: movieStashes,
|
||||
});
|
||||
}).filter(Boolean);
|
||||
}
|
||||
@@ -499,7 +518,7 @@ function countAggregations(buckets) {
|
||||
return Object.fromEntries(buckets.map((bucket) => [bucket.key, { count: bucket.doc_count }]));
|
||||
}
|
||||
|
||||
export async function fetchMovies(filters, rawOptions) {
|
||||
export async function fetchMovies(filters, rawOptions, reqUser) {
|
||||
const options = curateOptions(rawOptions);
|
||||
|
||||
console.log(options);
|
||||
@@ -517,11 +536,8 @@ export async function fetchMovies(filters, rawOptions) {
|
||||
options.aggregateChannels ? fetchEntitiesById(result.aggregations.channelIds.map((bucket) => bucket.key), { order: ['name', 'asc'], append: channelCounts }) : [],
|
||||
]);
|
||||
|
||||
console.log(result.aggregations);
|
||||
console.log(aggActors);
|
||||
|
||||
const movieIds = result.movies.map((movie) => Number(movie.id));
|
||||
const movies = await fetchMoviesById(movieIds);
|
||||
const movies = await fetchMoviesById(movieIds, reqUser);
|
||||
|
||||
return {
|
||||
movies,
|
||||
|
||||
+5
-1
@@ -442,7 +442,7 @@ async function queryManticoreSql(filters, options, _reqUser) {
|
||||
if (filters.entityId) {
|
||||
builder.whereRaw('any(entity_ids) = ?', filters.entityId);
|
||||
|
||||
/* manticore does not support OR if both left and right table are queried https://github.com/manticoresoftware/manticoresearch/issues/1978#issuecomment-2010470068
|
||||
/* manticore does not currently support OR if both left and right table are queried https://github.com/manticoresoftware/manticoresearch/issues/1978#issuecomment-2010470068
|
||||
builder.where((whereBuilder) => {
|
||||
whereBuilder
|
||||
.where('scenes.channel_id', filters.entityId)
|
||||
@@ -451,6 +451,10 @@ async function queryManticoreSql(filters, options, _reqUser) {
|
||||
*/
|
||||
}
|
||||
|
||||
if (filters.movieId) {
|
||||
builder.whereRaw('any(movie_ids) = ?', filters.movieId);
|
||||
}
|
||||
|
||||
if (typeof filters.isShowcased === 'boolean') {
|
||||
builder.where('is_showcased', filters.isShowcased);
|
||||
}
|
||||
|
||||
+31
-2
@@ -289,11 +289,25 @@ export async function unstashScene(sceneId, stashId, sessionUser) {
|
||||
export async function stashMovie(movieId, stashId, sessionUser) {
|
||||
const stash = await fetchStashById(stashId, sessionUser);
|
||||
|
||||
await knex('stashes_movies')
|
||||
const [stashed] = await knex('stashes_movies')
|
||||
.insert({
|
||||
stash_id: stash.id,
|
||||
movie_id: movieId,
|
||||
});
|
||||
})
|
||||
.returning(['id', 'created_at']);
|
||||
|
||||
await indexApi.replace({
|
||||
index: 'movies_stashed',
|
||||
id: stashed.id,
|
||||
doc: {
|
||||
movie_id: movieId,
|
||||
user_id: sessionUser.id,
|
||||
stash_id: stashId,
|
||||
created_at: Math.round(stashed.created_at.getTime() / 1000),
|
||||
},
|
||||
});
|
||||
|
||||
logger.verbose(`${sessionUser.username} (${sessionUser.id}) stashed movie ${movieId} to stash ${stash.id} (${stash.name})`);
|
||||
|
||||
return fetchStashes('movie', movieId, sessionUser);
|
||||
}
|
||||
@@ -309,5 +323,20 @@ export async function unstashMovie(movieId, stashId, sessionUser) {
|
||||
.where('stashes.user_id', sessionUser.id))
|
||||
.delete();
|
||||
|
||||
await indexApi.callDelete({
|
||||
index: 'movies_stashed',
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
{ equals: { movie_id: movieId } },
|
||||
{ equals: { stash_id: stashId } },
|
||||
{ equals: { user_id: sessionUser.id } },
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
logger.verbose(`${sessionUser.username} (${sessionUser.id}) unstashed movie ${movieId} from stash ${stashId}`);
|
||||
|
||||
return fetchStashes('movie', movieId, sessionUser);
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ export async function fetchMoviesApi(req, res) {
|
||||
} = await fetchMovies(await curateMoviesQuery(req.query), {
|
||||
page: Number(req.query.page) || 1,
|
||||
limit: Number(req.query.limit) || 30,
|
||||
});
|
||||
}, req.user);
|
||||
|
||||
res.send(stringify({
|
||||
movies,
|
||||
|
||||
@@ -11,6 +11,7 @@ export async function curateScenesQuery(query) {
|
||||
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,
|
||||
movieId: Number(query.movieId) || null,
|
||||
stashId: Number(query.stashId) || null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user