chore: feeds

This commit is contained in:
Cory Dransfeldt 2024-06-07 17:09:23 -07:00
parent 1e106320c1
commit d32e976329
No known key found for this signature in database
8 changed files with 25 additions and 14090 deletions

View file

@ -1,8 +0,0 @@
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const mastodonCache = require('../../cache/jsonfeed-to-mastodon.json')
export default async function () {
return mastodonCache
}

View file

@ -6,6 +6,20 @@ const SUPABASE_KEY = process.env.SUPABASE_KEY
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
const PAGE_SIZE = 1000
const fetchTagsForMovie = async (movieId) => {
const { data, error } = await supabase
.from('movies_tags')
.select('tags(id, name)')
.eq('movies_id', movieId)
if (error) {
console.error(`Error fetching tags for movie ${movieId}:`, error)
return []
}
return data.map(mt => mt.tags.name)
}
const fetchAllMovies = async () => {
let movies = []
let rangeStart = 0
@ -14,6 +28,7 @@ const fetchAllMovies = async () => {
const { data, error } = await supabase
.from('movies')
.select(`
id,
tmdb_id,
slug,
last_watched,
@ -34,6 +49,10 @@ const fetchAllMovies = async () => {
break
}
for (const movie of data) {
movie.tags = await fetchTagsForMovie(movie.id)
}
movies = movies.concat(data)
if (data.length < PAGE_SIZE) break
@ -62,8 +81,10 @@ export default async function () {
description: item['description'],
review: item['review'],
id: item['tmdb_id'],
type: 'movie'
type: 'movie',
tags: item['tags']
}
return movie
}).filter(movie => watched ? movie['lastWatched'] : !movie['lastWatched'])
const favoriteMovies = movies.filter(movie => movie['favorite'])