From 15c9af805724019680685379747f06844588ee05 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sun, 27 Mar 2022 23:42:03 +0200 Subject: [PATCH] Added dedicated movie photo table, renamed scene photo function. --- assets/components/releases/banner.vue | 4 +-- assets/components/releases/release.vue | 2 +- assets/js/curate.js | 1 + assets/js/fragments.js | 30 +++++++++++++--------- assets/js/releases/actions.js | 26 +++++-------------- migrations/20220304233846_series.js | 2 -- migrations/20220327230125_movie_photos.js | 31 +++++++++++++++++++++++ src/argv.js | 1 + 8 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 migrations/20220327230125_movie_photos.js diff --git a/assets/components/releases/banner.vue b/assets/components/releases/banner.vue index 0a18bcb0..46c8a400 100644 --- a/assets/components/releases/banner.vue +++ b/assets/components/releases/banner.vue @@ -164,8 +164,8 @@ function poster() { function photos() { const clips = this.release.clips || []; const clipPostersById = clips.reduce((acc, clip) => ({ ...acc, [clip.poster.id]: clip.poster }), {}); - const uniqueClipPosters = Array.from(new Set(clips.map(clip => clip.poster.id) || [])).map(posterId => clipPostersById[posterId]); - const photosWithClipPosters = (this.release.photos || []).concat(uniqueClipPosters); + const uniqueClipPosters = Array.from(new Set(clips.map((clip) => clip.poster.id) || [])).map((posterId) => clipPostersById[posterId]); + const photosWithClipPosters = (this.release.photos || []).concat(this.release.scenesPhotos || []).concat(uniqueClipPosters); if (this.release.trailer || (this.release.teaser && this.release.teaser.mime !== 'image/gif')) { // poster will be on trailer video diff --git a/assets/components/releases/release.vue b/assets/components/releases/release.vue index 2fb1c652..38a1852b 100644 --- a/assets/components/releases/release.vue +++ b/assets/components/releases/release.vue @@ -28,7 +28,7 @@ curateRelease(serie, 'serie')); if (release.chapters) curatedRelease.chapters = release.chapters.filter(Boolean).map((chapter) => curateRelease(chapter)); if (release.photos) curatedRelease.photos = release.photos.filter(Boolean).map((photo) => photo.media || photo); + if (release.scenesPhotos) curatedRelease.scenesPhotos = release.scenesPhotos.filter(Boolean).map((photo) => photo.media || photo); if (release.covers) curatedRelease.covers = release.covers.filter(Boolean).map(({ media }) => media); if (release.trailer) curatedRelease.trailer = release.trailer.media; if (release.teaser) curatedRelease.teaser = release.teaser.media; diff --git a/assets/js/fragments.js b/assets/js/fragments.js index 682e2628..a94ae0d2 100644 --- a/assets/js/fragments.js +++ b/assets/js/fragments.js @@ -442,22 +442,26 @@ const releasesFragment = ` } `; -const mediaFragment = ` - media { +const mediaFields = ` + id + index + path + thumbnail + lazy + isS3 + comment + sfw: sfwMedia { id - index - path thumbnail lazy - isS3 + path comment - sfw: sfwMedia { - id - thumbnail - lazy - path - comment - } + } +`; + +const mediaFragment = ` + media { + ${mediaFields} } `; @@ -656,6 +660,8 @@ export { actorFields, actorStashesFields, campaignsFragment, + mediaFields, + mediaFragment, movieFields, releaseActorsFragment, releaseFields, diff --git a/assets/js/releases/actions.js b/assets/js/releases/actions.js index efc6cf90..1b293c99 100644 --- a/assets/js/releases/actions.js +++ b/assets/js/releases/actions.js @@ -4,6 +4,8 @@ import { releaseFragment, releaseFields, movieFields, + mediaFragment, + mediaFields, } from '../fragments'; import { curateRelease } from '../curate'; import getDateRange from '../get-date-range'; @@ -225,25 +227,11 @@ function initReleasesActions(store, router) { slug name } - photos { - id - index - path - thumbnail - lazy - width - height - thumbnailWidth - thumbnailHeight - isS3 - comment - sfw: sfwMedia { - id - thumbnail - lazy - path - comment - } + photos: moviesPhotos { + ${mediaFragment} + } + scenesPhotos { + ${mediaFields} } entity { id diff --git a/migrations/20220304233846_series.js b/migrations/20220304233846_series.js index d6de405c..db441199 100644 --- a/migrations/20220304233846_series.js +++ b/migrations/20220304233846_series.js @@ -183,8 +183,6 @@ exports.up = async (knex) => Promise.resolve() ORDER BY media.index ASC $$ LANGUAGE SQL STABLE; - COMMENT ON FUNCTION search_movies IS E'@sortable'; - GRANT ALL ON ALL TABLES IN SCHEMA public TO :visitor; GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO :visitor; diff --git a/migrations/20220327230125_movie_photos.js b/migrations/20220327230125_movie_photos.js new file mode 100644 index 00000000..ee5b8638 --- /dev/null +++ b/migrations/20220327230125_movie_photos.js @@ -0,0 +1,31 @@ +const config = require('config'); + +exports.up = async (knex) => Promise.resolve() + .then(() => knex.raw(` + ALTER FUNCTION movies_photos(movie movies) RENAME TO movies_scenes_photos; + `)) + .then(() => knex.schema.createTable('movies_photos', (table) => { + table.integer('movie_id', 16) + .notNullable() + .references('id') + .inTable('movies') + .onDelete('cascade'); + + table.text('media_id', 21) + .notNullable() + .references('id') + .inTable('media'); + + table.unique(['movie_id', 'media_id']); + })) + .then(() => knex.raw(` + GRANT ALL ON ALL TABLES IN SCHEMA public TO :visitor; + GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO :visitor; + `, { + visitor: knex.raw(config.database.query.user), + })); + +exports.down = async (knex) => knex.raw(` + DROP TABLE IF EXISTS movies_photos CASCADE; + ALTER FUNCTION movies_scenes_photos(movie movies) RENAME TO movies_photos; +`); diff --git a/src/argv.js b/src/argv.js index 17e38a5e..78b8f0dd 100644 --- a/src/argv.js +++ b/src/argv.js @@ -238,6 +238,7 @@ const { argv } = yargs default: false, }) .option('level', { + alias: 'log-level', describe: 'Log level', type: 'string', default: process.env.NODE_ENV === 'development' ? 'silly' : 'info',