feat: move images to b2 and route through bunny
This commit is contained in:
parent
cb2d536189
commit
6a338ceb92
32 changed files with 322 additions and 375 deletions
|
@ -54,7 +54,7 @@ const fetchGenreMapping = async () => {
|
|||
|
||||
export default async function () {
|
||||
const genreMapping = await fetchGenreMapping()
|
||||
const artists = await fetchPaginatedData('artists', 'id, mbid, name_string, image, total_plays, country, description, favorite, tattoo, genres')
|
||||
const artists = await fetchPaginatedData('artists', 'id, mbid, name_string, art(filename_disk), total_plays, country, description, favorite, tattoo, genres')
|
||||
const albums = await fetchPaginatedData('albums', 'mbid, name, release_year, total_plays, artist')
|
||||
const albumsByArtist = albums.reduce((acc, album) => {
|
||||
if (!acc[album.artist]) acc[album.artist] = []
|
||||
|
@ -68,9 +68,10 @@ export default async function () {
|
|||
}, {})
|
||||
|
||||
for (const artist of artists) {
|
||||
artist.albums = albumsByArtist[artist.id]?.sort((a, b) => a['release_year'] - b['release_year']) || []
|
||||
artist.country = parseCountryField(artist.country)
|
||||
artist.genres = genreMapping[artist.genres] || ''
|
||||
artist.albums = albumsByArtist[artist['id']]?.sort((a, b) => a['release_year'] - b['release_year']) || []
|
||||
artist.image = `/${artist['art']['filename_disk']}`
|
||||
artist.country = parseCountryField(artist['country'])
|
||||
artist.genres = genreMapping[artist['genres']] || ''
|
||||
}
|
||||
|
||||
return artists
|
||||
|
|
30
src/_data/badges.js
Normal file
30
src/_data/badges.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||
|
||||
const fetchAllBadges = async () => {
|
||||
const { data, error } = await supabase
|
||||
.from('badges')
|
||||
.select(`
|
||||
*,
|
||||
image(filename_disk)
|
||||
`)
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching badge data:', error)
|
||||
return null
|
||||
}
|
||||
|
||||
const transformedData = data.map(badge => ({
|
||||
...badge,
|
||||
image: badge['image']['filename_disk'],
|
||||
}))
|
||||
|
||||
return transformedData
|
||||
}
|
||||
|
||||
export default async function () {
|
||||
return await fetchAllBadges()
|
||||
}
|
|
@ -28,7 +28,7 @@ async function fetchAllBooks() {
|
|||
while (true) {
|
||||
const { data, error } = await supabase
|
||||
.from('books')
|
||||
.select('*')
|
||||
.select(`*, art(filename_disk)`)
|
||||
.range(from, to)
|
||||
|
||||
if (error) {
|
||||
|
@ -60,7 +60,7 @@ export default async function () {
|
|||
review: book['review'],
|
||||
rating: book['star_rating'] !== 'unrated' ? book['star_rating'] : '',
|
||||
description: book['description'],
|
||||
image: book['thumbnail'],
|
||||
image: `/${book?.['art']?.['filename_disk']}`,
|
||||
url: `/books/${book['isbn']}`,
|
||||
date: book['date_finished'],
|
||||
status: book['read_status'],
|
||||
|
|
52
src/_data/globals.js
Normal file
52
src/_data/globals.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
const SUPABASE_URL = process.env['SUPABASE_URL']
|
||||
const SUPABASE_KEY = process.env['SUPABASE_KEY']
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||
|
||||
export default async function () {
|
||||
const { data, error } = await supabase
|
||||
.from('globals')
|
||||
.select(`
|
||||
*,
|
||||
favicon_ico(filename_disk),
|
||||
favicon_svg(filename_disk),
|
||||
opengraph_default(filename_disk),
|
||||
feed_image(filename_disk),
|
||||
apple_touch_icon(filename_disk),
|
||||
about(filename_disk),
|
||||
page_404(filename_disk),
|
||||
page_broken(filename_disk),
|
||||
page_not_allowed(filename_disk),
|
||||
page_stop(filename_disk),
|
||||
logo_the_claw(filename_disk)
|
||||
`)
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching globals:', error)
|
||||
return {}
|
||||
}
|
||||
|
||||
const globalData = data.pop()
|
||||
const keysToProcess = [
|
||||
'favicon_ico',
|
||||
'favicon_svg',
|
||||
'opengraph_default',
|
||||
'feed_image',
|
||||
'apple_touch_icon',
|
||||
'about',
|
||||
'page_404',
|
||||
'page_broken',
|
||||
'page_not_allowed',
|
||||
'page_stop',
|
||||
'logo_the_claw'
|
||||
]
|
||||
|
||||
keysToProcess.forEach(key => {
|
||||
if (globalData[key] && globalData[key].filename_disk) {
|
||||
globalData[key] = globalData[key].filename_disk
|
||||
}
|
||||
})
|
||||
|
||||
return globalData
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
export default async function () {
|
||||
return {
|
||||
"siteName": "Cory Dransfeldt",
|
||||
"siteDescription": "I'm a software developer in Camarillo, California. I write about software development, technology and music.",
|
||||
"author": "Cory Dransfeldt",
|
||||
"email": "hi@coryd.dev",
|
||||
"url": "https://coryd.dev",
|
||||
"themeColor": "#3b82f6",
|
||||
"siteType": "Person",
|
||||
"locale": "en_US",
|
||||
"lang": "en",
|
||||
"meta_data": {
|
||||
"opengraph_default": "https://cdn.coryd.dev/assets/avatar.png"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,7 +30,6 @@ const fetchAllMovies = async () => {
|
|||
.select(`
|
||||
id,
|
||||
tmdb_id,
|
||||
slug,
|
||||
last_watched,
|
||||
title,
|
||||
year,
|
||||
|
@ -39,7 +38,9 @@ const fetchAllMovies = async () => {
|
|||
favorite,
|
||||
star_rating,
|
||||
description,
|
||||
review
|
||||
review,
|
||||
art(filename_disk),
|
||||
backdrop(filename_disk)
|
||||
`)
|
||||
.order('last_watched', { ascending: false })
|
||||
.range(rangeStart, rangeStart + PAGE_SIZE - 1)
|
||||
|
@ -73,8 +74,8 @@ export default async function () {
|
|||
year: item['year'],
|
||||
url: `/watching/movies/${item['tmdb_id']}`,
|
||||
description: `${item['title']} (${item['year']})<br/>Watched at: ${DateTime.fromISO(item['last_watched'], { zone: 'utc' }).setZone('America/Los_Angeles').toFormat('MMMM d, yyyy, h:mma')}`,
|
||||
image: `/movies/poster-${item['tmdb_id']}.jpg`,
|
||||
backdrop: `/movies/backdrops/backdrop-${item['tmdb_id']}.jpg`,
|
||||
image: `/${item?.['art']?.['filename_disk']}`,
|
||||
backdrop: `/${item?.['backdrop']?.['filename_disk']}`,
|
||||
plays: item['plays'],
|
||||
collected: item['collected'],
|
||||
favorite: item['favorite'],
|
||||
|
|
|
@ -61,7 +61,7 @@ const aggregateData = async (data, groupByField, groupByType) => {
|
|||
plays: 0,
|
||||
mbid: item['albums']['mbid'],
|
||||
url: `/music/artists/${sanitizeMediaString(item['artist_name'])}-${sanitizeMediaString(parseCountryField(item['artists']['country']))}`,
|
||||
image: item['albums']?.['image'] || '',
|
||||
image: `/${item['albums']?.['art']?.['filename_disk']}` || '',
|
||||
timestamp: item['listened_at'],
|
||||
type: groupByType,
|
||||
genre: genreMapping[item['artists']['genres']] || ''
|
||||
|
@ -72,7 +72,7 @@ const aggregateData = async (data, groupByField, groupByType) => {
|
|||
plays: 0,
|
||||
mbid: item[groupByType]?.['mbid'] || '',
|
||||
url: `/music/artists/${sanitizeMediaString(item['artist_name'])}-${sanitizeMediaString(parseCountryField(item['artists']['country']))}`,
|
||||
image: item[groupByType]?.image || '',
|
||||
image: `/${item[groupByType]?.['art']?.['filename_disk']}` || '',
|
||||
type: groupByType,
|
||||
genre: genreMapping[item['artists']['genres']] || ''
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ const buildRecents = async (data) => {
|
|||
artist: listen['artist_name'],
|
||||
url: `/music/artists/${sanitizeMediaString(listen['artist_name'])}-${sanitizeMediaString(parseCountryField(listen['artists']['country']))}`,
|
||||
timestamp: listen['listened_at'],
|
||||
image: listen['albums']?.['image'] || ''
|
||||
image: `/${listen['albums']?.['art']?.['filename_disk']}` || ''
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -128,8 +128,8 @@ export default async function() {
|
|||
album_name,
|
||||
album_key,
|
||||
listened_at,
|
||||
artists (mbid, image, genres, country),
|
||||
albums (mbid, image)
|
||||
artists (mbid, art(filename_disk), genres, country),
|
||||
albums (mbid, art(filename_disk))
|
||||
`
|
||||
|
||||
for (const [period, startPeriod] of Object.entries(periods)) {
|
||||
|
|
|
@ -66,7 +66,10 @@ const fetchAllPosts = async () => {
|
|||
while (fetchMore) {
|
||||
const { data, error } = await supabase
|
||||
.from('posts')
|
||||
.select('*')
|
||||
.select(`
|
||||
*,
|
||||
image(filename_disk)
|
||||
`)
|
||||
.order('date', { ascending: false })
|
||||
.range(page * PAGE_SIZE, (page + 1) * PAGE_SIZE - 1)
|
||||
|
||||
|
@ -78,17 +81,17 @@ const fetchAllPosts = async () => {
|
|||
if (data.length < PAGE_SIZE) fetchMore = false
|
||||
|
||||
for (const post of data) {
|
||||
if (uniqueSlugs.has(post.slug)) continue
|
||||
if (uniqueSlugs.has(post['slug'])) continue
|
||||
|
||||
uniqueSlugs.add(post.slug)
|
||||
post.tags = await fetchTagsForPost(post.id)
|
||||
post.blocks = await fetchBlocksForPost(post.id)
|
||||
post['tags'] = await fetchTagsForPost(post['id'])
|
||||
post['blocks'] = await fetchBlocksForPost(post['id'])
|
||||
if (post?.['image']?.['filename_disk']) post['image'] = post['image']['filename_disk']
|
||||
posts.push(post)
|
||||
}
|
||||
|
||||
page++
|
||||
}
|
||||
|
||||
return posts
|
||||
}
|
||||
|
||||
|
|
129
src/_data/tv.js
129
src/_data/tv.js
|
@ -1,7 +1,7 @@
|
|||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
const SUPABASE_URL = process.env['SUPABASE_URL']
|
||||
const SUPABASE_KEY = process.env['SUPABASE_KEY']
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||
|
||||
const PAGE_SIZE = 1000
|
||||
|
@ -21,6 +21,8 @@ const fetchAllShows = async () => {
|
|||
year,
|
||||
description,
|
||||
review,
|
||||
art(filename_disk),
|
||||
backdrop(filename_disk),
|
||||
episodes (
|
||||
episode_number,
|
||||
season_number,
|
||||
|
@ -35,7 +37,6 @@ const fetchAllShows = async () => {
|
|||
}
|
||||
|
||||
shows = shows.concat(data)
|
||||
|
||||
if (data.length < PAGE_SIZE) break
|
||||
rangeStart += PAGE_SIZE
|
||||
}
|
||||
|
@ -43,38 +44,47 @@ const fetchAllShows = async () => {
|
|||
return shows
|
||||
}
|
||||
|
||||
const prepareShowData = (show) => {
|
||||
return {
|
||||
...show,
|
||||
image: show.art?.filename_disk ? show.art.filename_disk : '',
|
||||
backdrop: show.backdrop?.filename_disk ? show.backdrop.filename_disk : ''
|
||||
}
|
||||
}
|
||||
|
||||
const prepareEpisodeData = (show) => {
|
||||
return show.episodes.map(episode => ({
|
||||
...episode,
|
||||
show_title: show.title,
|
||||
show_tmdb_id: show.tmdb_id,
|
||||
collected: show.collected,
|
||||
favorite: show.favorite,
|
||||
image: show.image,
|
||||
backdrop: show.backdrop
|
||||
}))
|
||||
}
|
||||
|
||||
export default async function () {
|
||||
const shows = await fetchAllShows()
|
||||
const rawShows = await fetchAllShows()
|
||||
const shows = rawShows.map(prepareShowData)
|
||||
|
||||
let episodes = []
|
||||
shows.forEach(show => {
|
||||
show.episodes.forEach(episode => {
|
||||
episodes.push({
|
||||
...episode,
|
||||
show_title: show['title'],
|
||||
show_tmdb_id: show['tmdb_id'],
|
||||
collected: show['collected'],
|
||||
favorite: show['favorite'],
|
||||
year: show['year']
|
||||
})
|
||||
})
|
||||
})
|
||||
const episodes = shows.flatMap(prepareEpisodeData)
|
||||
|
||||
episodes.sort((a, b) => new Date(b.last_watched_at) - new Date(a.last_watched_at))
|
||||
|
||||
episodes.sort((a, b) => new Date(b['last_watched_at']) - new Date(a['last_watched_at']))
|
||||
const allEpisodes = episodes
|
||||
const recentlyWatchedEpisodes = episodes.slice(0, 225)
|
||||
const formatEpisodeData = (episodes) => {
|
||||
const episodeData = []
|
||||
const showEpisodesMap = {}
|
||||
|
||||
episodes.forEach((episode) => {
|
||||
const showTitle = episode['show_title']
|
||||
const showTmdbId = episode['show_tmdb_id']
|
||||
const episodeNumber = episode['episode_number']
|
||||
const seasonNumber = episode['season_number']
|
||||
const lastWatchedAt = episode['last_watched_at']
|
||||
const collected = episode['collected']
|
||||
const favorite = episode['favorite']
|
||||
episodes.forEach(episode => {
|
||||
const showTitle = episode.show_title
|
||||
const showTmdbId = episode.show_tmdb_id
|
||||
const episodeNumber = episode.episode_number
|
||||
const seasonNumber = episode.season_number
|
||||
const lastWatchedAt = episode.last_watched_at
|
||||
const collected = episode.collected
|
||||
const favorite = episode.favorite
|
||||
const image = episode.image
|
||||
const backdrop = episode.backdrop
|
||||
|
||||
if (!showEpisodesMap[showTmdbId]) {
|
||||
showEpisodesMap[showTmdbId] = {
|
||||
|
@ -84,7 +94,9 @@ export default async function () {
|
|||
favorite,
|
||||
dateAdded: lastWatchedAt,
|
||||
lastWatchedAt,
|
||||
episodes: []
|
||||
episodes: [],
|
||||
image,
|
||||
backdrop
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,41 +108,44 @@ export default async function () {
|
|||
season: seasonNumber,
|
||||
tmdbId: showTmdbId,
|
||||
type: 'tv',
|
||||
image: `/shows/poster-${showTmdbId}.jpg`,
|
||||
backdrop: `/shows/backdrops/backdrop-${showTmdbId}.jpg`,
|
||||
dateAdded: lastWatchedAt,
|
||||
lastWatchedAt
|
||||
lastWatchedAt,
|
||||
image,
|
||||
backdrop
|
||||
})
|
||||
})
|
||||
|
||||
const sortedShows = Object.values(showEpisodesMap).sort((a, b) => new Date(b['episodes'][0]['lastWatchedAt']) - new Date(a['episodes'][0]['lastWatchedAt']))
|
||||
const sortedShows = Object.values(showEpisodesMap).sort((a, b) => new Date(b.episodes[0].lastWatchedAt) - new Date(a.episodes[0].lastWatchedAt))
|
||||
|
||||
sortedShows.forEach((show) => {
|
||||
const startingEpisode = show['episodes'][show['episodes'].length - 1]['episode']
|
||||
const startingSeason = show['episodes'][show['episodes'].length - 1]['season']
|
||||
const endingEpisode = show['episodes'][0]['episode']
|
||||
const endingSeason = show['episodes'][0]['season']
|
||||
const episodeData = []
|
||||
sortedShows.forEach(show => {
|
||||
const startingEpisode = show.episodes[show.episodes.length - 1].episode
|
||||
const startingSeason = show.episodes[show.episodes.length - 1].season
|
||||
const endingEpisode = show.episodes[0].episode
|
||||
const endingSeason = show.episodes[0].season
|
||||
|
||||
if (show.episodes.length > 1) {
|
||||
episodeData.push({
|
||||
name: show['title'],
|
||||
url: `/watching/shows/${show['tmdbId']}`,
|
||||
name: show.title,
|
||||
url: `/watching/shows/${show.tmdbId}`,
|
||||
subtext: `S${startingSeason}E${startingEpisode} - S${endingSeason}E${endingEpisode}`,
|
||||
startingEpisode,
|
||||
startingSeason,
|
||||
episode: endingEpisode,
|
||||
season: endingSeason,
|
||||
tmdbId: show['tmdbId'],
|
||||
collected: show['collected'],
|
||||
favorite: show['favorite'],
|
||||
tmdbId: show.tmdbId,
|
||||
collected: show.collected,
|
||||
favorite: show.favorite,
|
||||
type: 'tv-range',
|
||||
image: `/shows/poster-${show['tmdbId']}.jpg`,
|
||||
backdrop: `/shows/backdrops/backdrop-${show['tmdbId']}.jpg`,
|
||||
image: show.image,
|
||||
backdrop: show.backdrop
|
||||
})
|
||||
} else {
|
||||
const singleEpisode = show['episodes'][0]
|
||||
singleEpisode['collected'] = show['collected']
|
||||
singleEpisode['favorite'] = show['favorite']
|
||||
const singleEpisode = show.episodes[0]
|
||||
singleEpisode.collected = show.collected
|
||||
singleEpisode.favorite = show.favorite
|
||||
singleEpisode.image = show.image
|
||||
singleEpisode.backdrop = show.backdrop
|
||||
episodeData.push(singleEpisode)
|
||||
}
|
||||
})
|
||||
|
@ -138,20 +153,12 @@ export default async function () {
|
|||
return episodeData
|
||||
}
|
||||
|
||||
const favoriteShows = shows.filter(show => show['favorite'])
|
||||
const collectedShows = shows.filter(show => show['collected'])
|
||||
const toWatch = shows.map(show => ({...show, url: `/watching/shows/${show['tmdb_id']}`})).filter(show => !show.episodes.some(episode => episode.last_watched_at)).sort((a, b) => a['title'].localeCompare(b['title']))
|
||||
const favoriteShows = shows.filter(show => show.favorite)
|
||||
|
||||
return {
|
||||
shows,
|
||||
watchHistory: formatEpisodeData(allEpisodes),
|
||||
recentlyWatched: formatEpisodeData(recentlyWatchedEpisodes),
|
||||
favorites: formatEpisodeData(favoriteShows.flatMap(show => show['episodes'].map(episode => ({
|
||||
...episode,
|
||||
show_title: show['title'],
|
||||
show_tmdb_id: show['tmdb_id'],
|
||||
collected: show['collected'],
|
||||
favorite: show['favorite']
|
||||
})))).sort((a, b) => a['name'].localeCompare(b['name']))
|
||||
watchHistory: formatEpisodeData(episodes),
|
||||
recentlyWatched: formatEpisodeData(episodes.slice(0, 225)),
|
||||
favorites: formatEpisodeData(favoriteShows.flatMap(prepareEpisodeData)).sort((a, b) => a.name.localeCompare(b.name))
|
||||
}
|
||||
}
|
Reference in a new issue