feat: get image from tmdb
This commit is contained in:
@ -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;
|
||||
|
@ -10,7 +10,7 @@ export type Movie = {
|
||||
description: string;
|
||||
hashtags: string[];
|
||||
meta: {
|
||||
published: Date;
|
||||
date: Date;
|
||||
image: string;
|
||||
author: string;
|
||||
rating: number;
|
||||
|
14
lib/tmdb.ts
14
lib/tmdb.ts
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user