diff --git a/pages/movies/@movieId/+Page.vue b/pages/movies/@movieId/+Page.vue index a19d519..112c4bb 100644 --- a/pages/movies/@movieId/+Page.vue +++ b/pages/movies/@movieId/+Page.vue @@ -28,12 +28,12 @@
diff --git a/src/movies.js b/src/movies.js index dc16a5c..f8313c9 100644 --- a/src/movies.js +++ b/src/movies.js @@ -56,6 +56,7 @@ function curateMovie(rawMovie, assets) { // poster: curateMedia(assets.poster), covers: assets.covers.map((cover) => curateMedia(cover)), photos: assets.photos.map((photo) => curateMedia(photo)), + caps: assets.caps.map((cap) => curateMedia(cap)), trailer: curateMedia(assets.trailer), stashes: assets.stashes?.map((stash) => curateStash(stash)) || [], createdBatchId: rawMovie.created_batch_id, @@ -73,6 +74,7 @@ export async function fetchMoviesById(movieIds, reqUser) { sceneTags, covers, photos, + caps, trailers, stashes, } = await promiseProps({ @@ -124,11 +126,30 @@ export async function fetchMoviesById(movieIds, reqUser) { .whereIn('movie_id', movieIds) .leftJoin('media', 'media.id', 'movies_covers.media_id') .orderBy('media.index'), - 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'), + photos: knex.transaction(async (trx) => { + if (reqUser) { + await trx.select(knex.raw('set_config(\'user.id\', :userId, true)', { userId: reqUser.id })); + } + + return trx('movies_scenes') + .select('media.*', 'movies_scenes.movie_id') + .whereIn('movies_scenes.movie_id', movieIds) + .whereNotNull('media.id') + .leftJoin('releases_photos', 'releases_photos.release_id', 'movies_scenes.scene_id') + .leftJoin('media', 'media.id', 'releases_photos.media_id'); + }), + caps: knex.transaction(async (trx) => { + if (reqUser) { + await trx.select(knex.raw('set_config(\'user.id\', :userId, true)', { userId: reqUser.id })); + } + + return trx('movies_scenes') + .select('media.*', 'movies_scenes.movie_id') + .whereIn('movies_scenes.movie_id', movieIds) + .whereNotNull('media.id') + .leftJoin('releases_caps', 'releases_caps.release_id', 'movies_scenes.scene_id') + .leftJoin('media', 'media.id', 'releases_caps.media_id'); + }), trailers: knex('movies_trailers') .whereIn('movie_id', movieIds) .leftJoin('media', 'media.id', 'movies_trailers.media_id'), @@ -154,7 +175,8 @@ export async function fetchMoviesById(movieIds, reqUser) { const movieTags = tags.filter((tag) => tag.movie_id === movieId); const movieSceneTags = sceneTags.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 moviePhotos = photos.filter((photo) => photo.movie_id === movieId); + const movieCaps = caps.filter((cap) => cap.movie_id === movieId); const movieTrailer = trailers.find((trailer) => trailer.movie_id === movieId); const movieStashes = stashes.filter((stash) => stash.movie_id === movieId); @@ -167,6 +189,7 @@ export async function fetchMoviesById(movieIds, reqUser) { tags: combinedTags, covers: movieCovers, photos: moviePhotos, + caps: movieCaps, trailer: movieTrailer, stashes: movieStashes, });