feat: cache marka api responses

This commit is contained in:
Max Richter
2025-11-04 12:09:17 +01:00
parent bb4e895770
commit fea9b69d4d
9 changed files with 163 additions and 98 deletions

View File

@@ -39,15 +39,16 @@ const POST = async (
const movieCredits = !movie.content?.author &&
await tmdb.getMovieCredits(tmdbId);
const releaseDate = movieDetails.release_date;
if (releaseDate && !movie.content?.datePublished) {
movie.content = movie.content || {};
movie.content.datePublished = formatDate(new Date(releaseDate));
}
const director = movieCredits &&
movieCredits?.crew?.filter?.((person) => person.job === "Director")[0];
movie.content ??= {
_type: "Review",
};
movie.content.datePublished ??= formatDate(movieDetails.release_date);
if (director && !movie.content?.author) {
movie.content = movie.content || {};
movie.content.author = {
_type: "Person",
name: director.name,
@@ -65,18 +66,15 @@ const POST = async (
];
}
if (!movie.name) {
movie.name = tmdbId;
}
movie.content.tmdbId ??= tmdbId;
let finalPath = "";
const posterPath = movieDetails.poster_path;
if (posterPath && !movie.content?.image) {
if (posterPath && !movie.content.image) {
const poster = await tmdb.getMoviePoster(posterPath);
const extension = fileExtension(posterPath);
finalPath = `movies/images/${safeFileName(name)}_cover.${extension}`;
await createResource(finalPath, poster);
movie.content = movie.content || {};
movie.content.image = finalPath;
}