feat: associate movies and artists
This commit is contained in:
parent
b2eb6112ec
commit
7e1a55754b
8 changed files with 99 additions and 37 deletions
|
@ -28,7 +28,8 @@ const fetchAllArtists = async () => {
|
|||
art,
|
||||
albums,
|
||||
concerts,
|
||||
books
|
||||
books,
|
||||
movies
|
||||
`)
|
||||
.range(rangeStart, rangeStart + PAGE_SIZE - 1)
|
||||
|
||||
|
@ -67,14 +68,20 @@ const processArtists = (artists) => {
|
|||
totalPlays: album['total_plays'],
|
||||
art: album.art ? `/${album['art']}` : ''
|
||||
})).sort((a, b) => a['release_year'] - b['release_year']),
|
||||
concerts: artist['concerts']?.[0]?.id ? artist['concerts'].sort((a, b) => new Date(b['date']) - new Date(a['date'])) : null,
|
||||
books: artist['books']?.[0]?.id ? artist['books'].map(book => ({
|
||||
concerts: artist['concerts']?.[0]?.['id'] ? artist['concerts'].sort((a, b) => new Date(b['date']) - new Date(a['date'])) : null,
|
||||
books: artist['books']?.[0]?.['id'] ? artist['books'].map(book => ({
|
||||
title: book['title'],
|
||||
author: book['author'],
|
||||
isbn: book['isbn'],
|
||||
description: book['description'],
|
||||
url: `/books/${book['isbn']}`,
|
||||
})).sort((a, b) => a['title'].localeCompare(b['title'])) : null
|
||||
})).sort((a, b) => a['title'].localeCompare(b['title'])) : null,
|
||||
movies: artist['movies']?.[0]?.['id'] ? artist['movies'].map(movie => ({
|
||||
title: movie['title'],
|
||||
year: movie['year'],
|
||||
tmdb_id: movie['tmdb_id'],
|
||||
url: `/watching/movies/${movie['tmdb_id']}`,
|
||||
})).sort((a, b) => b['year'] - a['year']) : null,
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
@ -49,10 +49,6 @@ const processBooks = (books) => {
|
|||
return books.map(book => {
|
||||
const dateFinished = new Date(book['date_finished'])
|
||||
const year = dateFinished.getUTCFullYear()
|
||||
const artists = book?.['artists']?.map(artist => {
|
||||
artist['url'] = `/music/artists/${sanitizeMediaString(artist['name'])}-${sanitizeMediaString(parseCountryField(artist['country']))}`
|
||||
return artist
|
||||
}).sort((a, b) => a['name'].localeCompare(b['name']))
|
||||
|
||||
return {
|
||||
title: book['title'],
|
||||
|
@ -69,7 +65,10 @@ const processBooks = (books) => {
|
|||
tags: Array.isArray(book['tags']) ? book['tags'] : book['tags']?.split(',') || [], // Ensure tags is an array
|
||||
isbn: book['isbn'],
|
||||
type: 'book',
|
||||
artists,
|
||||
artists: book['artists']?.[0]?.['id'] ? book['artists'].map(artist => {
|
||||
artist['url'] = `/music/artists/${sanitizeMediaString(artist['name'])}-${sanitizeMediaString(parseCountryField(artist['country']))}`
|
||||
return artist
|
||||
}).sort((a, b) => a['name'].localeCompare(b['name'])) : null,
|
||||
year,
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { createClient } from '@supabase/supabase-js'
|
||||
import { DateTime } from 'luxon'
|
||||
import { sanitizeMediaString, parseCountryField } from '../../config/utilities/index.js'
|
||||
|
||||
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
|
@ -27,7 +28,8 @@ const fetchAllMovies = async () => {
|
|||
review,
|
||||
art,
|
||||
backdrop,
|
||||
tags
|
||||
tags,
|
||||
artists
|
||||
`)
|
||||
.order('last_watched', { ascending: false })
|
||||
.range(rangeStart, rangeStart + PAGE_SIZE - 1)
|
||||
|
@ -47,29 +49,28 @@ const fetchAllMovies = async () => {
|
|||
}
|
||||
|
||||
const processMovies = (movies) => {
|
||||
return movies.map(item => {
|
||||
const lastWatched = DateTime.fromISO(item['last_watched'], { zone: 'utc' })
|
||||
const year = DateTime.now().year
|
||||
|
||||
return {
|
||||
title: item['title'],
|
||||
lastWatched: item['last_watched'],
|
||||
dateAdded: item['last_watched'],
|
||||
year: item['year'],
|
||||
url: `/watching/movies/${item['tmdb_id']}`,
|
||||
description: item['description'],
|
||||
image: item['art'] ? `/${item['art']}` : '',
|
||||
backdrop: item['backdrop'] ? `/${item['backdrop']}` : '',
|
||||
plays: item['plays'],
|
||||
collected: item['collected'],
|
||||
favorite: item['favorite'],
|
||||
rating: item['star_rating'],
|
||||
review: item['review'],
|
||||
id: item['tmdb_id'],
|
||||
type: 'movie',
|
||||
tags: item['tags'] ? item['tags'].split(',') : [],
|
||||
}
|
||||
})
|
||||
return movies.map(item => ({
|
||||
title: item['title'],
|
||||
lastWatched: item['last_watched'],
|
||||
dateAdded: item['last_watched'],
|
||||
year: item['year'],
|
||||
url: `/watching/movies/${item['tmdb_id']}`,
|
||||
description: item['description'],
|
||||
image: item['art'] ? `/${item['art']}` : '',
|
||||
backdrop: item['backdrop'] ? `/${item['backdrop']}` : '',
|
||||
plays: item['plays'],
|
||||
collected: item['collected'],
|
||||
favorite: item['favorite'],
|
||||
rating: item['star_rating'],
|
||||
review: item['review'],
|
||||
id: item['tmdb_id'],
|
||||
type: 'movie',
|
||||
tags: item['tags'] ? item['tags'].split(',') : [],
|
||||
artists: item['artists']?.[0]?.['name'] ? item['artists'].map(artist => {
|
||||
artist['url'] = `/music/artists/${sanitizeMediaString(artist['name'])}-${sanitizeMediaString(parseCountryField(artist['country']))}`
|
||||
return artist
|
||||
}).sort((a, b) => a['name'].localeCompare(b['name'])) : null,
|
||||
}))
|
||||
}
|
||||
|
||||
export default async function () {
|
||||
|
|
Reference in a new issue