Added trailers. Improved scene page scaling.

This commit is contained in:
2024-03-24 04:22:37 +01:00
parent 8a32febb8a
commit 08e4146d91
23 changed files with 3204 additions and 413 deletions

View File

@@ -1,7 +1,7 @@
import config from 'config';
import util from 'util'; /* eslint-disable-line no-unused-vars */
import { knexOwner 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';
@@ -20,6 +20,7 @@ function curateMedia(media) {
path: media.path,
thumbnail: media.thumbnail,
lazy: media.lazy,
hash: media.hash,
isS3: media.is_s3,
width: media.width,
height: media.height,
@@ -41,6 +42,7 @@ function curateScene(rawScene, assets) {
effectiveDate: rawScene.effective_date,
description: rawScene.description,
duration: rawScene.duration,
shootId: rawScene.shoot_id,
channel: {
id: assets.channel.id,
slug: assets.channel.slug,
@@ -71,6 +73,8 @@ function curateScene(rawScene, assets) {
name: tag.name,
})),
poster: curateMedia(assets.poster),
trailer: curateMedia(assets.trailer),
teaser: curateMedia(assets.teaser),
photos: assets.photos.map((photo) => curateMedia(photo)),
stashes: assets.stashes?.map((stash) => curateStash(stash)) || [],
createdBatchId: rawScene.created_batch_id,
@@ -88,6 +92,8 @@ export async function fetchScenesById(sceneIds, { reqUser, ...context } = {}) {
tags,
posters,
photos,
trailers,
teasers,
stashes,
lastBatch: { id: lastBatchId },
} = await promiseProps({
@@ -119,16 +125,40 @@ export async function fetchScenesById(sceneIds, { reqUser, ...context } = {}) {
posters: knex('releases_posters')
.whereIn('release_id', sceneIds)
.leftJoin('media', 'media.id', 'releases_posters.media_id'),
photos: knex('releases_photos')
.whereIn('release_id', sceneIds)
.leftJoin('media', 'media.id', 'releases_photos.media_id'),
photos: knex.transaction(async (trx) => {
if (reqUser) {
await trx.select(knex.raw('set_config(\'user.id\', :userId, true)', { userId: reqUser.id }));
}
return trx('releases_photos')
.whereIn('release_id', sceneIds)
.leftJoin('media', 'media.id', 'releases_photos.media_id');
}),
trailers: knex.transaction(async (trx) => {
if (reqUser) {
await trx.select(knex.raw('set_config(\'user.id\', :userId, true)', { userId: reqUser.id }));
}
return trx('releases_trailers')
.whereIn('release_id', sceneIds)
.leftJoin('media', 'media.id', 'releases_trailers.media_id');
}),
teasers: knex.transaction(async (trx) => {
if (reqUser) {
await trx.select(knex.raw('set_config(\'user.id\', :userId, true)', { userId: reqUser.id }));
}
return trx('releases_teasers')
.whereIn('release_id', sceneIds)
.leftJoin('media', 'media.id', 'releases_teasers.media_id');
}),
lastBatch: knex('batches')
.select('id')
.where('showcased', true)
.orderBy('created_at', 'desc')
.first(),
stashes: reqUser
? knex('stashes_scenes')
? knexOwner('stashes_scenes')
.leftJoin('stashes', 'stashes.id', 'stashes_scenes.stash_id')
.where('stashes.user_id', reqUser.id)
.whereIn('stashes_scenes.scene_id', sceneIds)
@@ -155,9 +185,13 @@ export async function fetchScenesById(sceneIds, { reqUser, ...context } = {}) {
const sceneTags = tags.filter((tag) => tag.release_id === sceneId);
const scenePoster = posters.find((poster) => poster.release_id === sceneId);
const scenePhotos = photos.filter((photo) => photo.release_id === sceneId);
const sceneTrailers = trailers.find((trailer) => trailer.release_id === sceneId);
const sceneTeasers = teasers.find((teaser) => teaser.release_id === sceneId);
const sceneStashes = stashes.filter((stash) => stash.scene_id === sceneId);
const sceneActorStashes = sceneActors.map((actor) => actorStashes.find((stash) => stash.actor_id === actor.id)).filter(Boolean);
console.log(sceneActors);
return curateScene(scene, {
channel: sceneChannel,
actors: sceneActors,
@@ -165,6 +199,8 @@ export async function fetchScenesById(sceneIds, { reqUser, ...context } = {}) {
tags: sceneTags,
poster: scenePoster,
photos: scenePhotos,
trailer: sceneTrailers,
teaser: sceneTeasers,
stashes: sceneStashes,
actorStashes: sceneActorStashes,
lastBatchId,