feat: get image from tmdb

This commit is contained in:
2023-07-31 17:21:17 +02:00
parent 79975905d1
commit 3a5c5b4404
12 changed files with 148 additions and 29 deletions

View File

@ -38,6 +38,26 @@ export async function getDocuments(): Promise<Document[]> {
return documents;
}
export async function createDocument(
name: string,
content: string | ArrayBuffer,
mediaType?: string,
) {
const headers = new Headers();
if (mediaType) {
headers.append("Content-Type", mediaType);
}
const response = await fetch(SILVERBULLET_SERVER + "/" + name, {
body: content,
method: "PUT",
headers,
});
return response;
}
export async function getDocument(name: string): Promise<string> {
const cachedDocument = await cache.getDocument(name);
if (cachedDocument) return cachedDocument;

View File

@ -10,7 +10,7 @@ export type Movie = {
description: string;
hashtags: string[];
meta: {
published: Date;
date: Date;
image: string;
author: string;
rating: number;

View File

@ -1,3 +1,4 @@
import * as cache from "@lib/cache/cache.ts";
import { MovieDb } from "https://esm.sh/moviedb-promise@3.4.1";
const moviedb = new MovieDb(Deno.env.get("TMDB_API_KEY") || "");
@ -12,3 +13,16 @@ export function getMovie(id: number) {
export function getMovieCredits(id: number) {
return moviedb.movieCredits(id);
}
export async function getMoviePoster(id: string): Promise<ArrayBuffer> {
const cachedPoster = await cache.get("posters/" + id);
if (cachedPoster) return cachedPoster as ArrayBuffer;
const posterUrl = `https://image.tmdb.org/t/p/original/${id}`;
const response = await fetch(posterUrl);
const poster = await response.arrayBuffer();
cache.set(`posters/${id}`, new Uint8Array());
return poster;
}