feat: initial commit

This commit is contained in:
Cory Dransfeldt 2025-03-27 16:46:02 -07:00
commit e214116e40
No known key found for this signature in database
253 changed files with 17406 additions and 0 deletions

62
src/data/movies.js Normal file
View file

@ -0,0 +1,62 @@
import EleventyFetch from "@11ty/eleventy-fetch";
const { POSTGREST_URL, POSTGREST_API_KEY } = process.env;
const fetchAllMovies = async () => {
try {
return await EleventyFetch(`${POSTGREST_URL}/optimized_movies?select=*`, {
duration: "1h",
type: "json",
fetchOptions: {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${POSTGREST_API_KEY}`,
},
},
});
} catch (error) {
console.error("Error fetching movies:", error);
return [];
}
};
export default async function () {
try {
const movies = await fetchAllMovies();
const favoriteMovies = movies.filter((movie) => movie.favorite);
const now = new Date();
const recentlyWatchedMovies = movies.filter((movie) => {
const lastWatched = movie.last_watched;
if (!lastWatched) return false;
const lastWatchedDate = new Date(lastWatched);
if (isNaN(lastWatchedDate.getTime())) return false;
const sixMonthsAgo = new Date();
sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
return lastWatchedDate >= sixMonthsAgo;
});
return {
movies,
watchHistory: movies.filter((movie) => movie.last_watched),
recentlyWatched: recentlyWatchedMovies,
favorites: favoriteMovies.sort((a, b) =>
a.title.localeCompare(b.title),
),
feed: movies.filter((movie) => movie.feed),
};
} catch (error) {
console.error("Error fetching and processing movies data:", error);
return {
movies: [],
watchHistory: [],
recentlyWatched: [],
favorites: [],
feed: [],
};
}
}