feat: add authentication

This commit is contained in:
2023-08-04 22:35:25 +02:00
parent f9638c35fc
commit 469db6525d
33 changed files with 492 additions and 100 deletions

View File

@ -5,6 +5,7 @@ import * as tmdb from "@lib/tmdb.ts";
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
import { safeFileName } from "@lib/string.ts";
import { createDocument } from "@lib/documents.ts";
import { AccessDeniedError } from "@lib/errors.ts";
export const handler: Handlers = {
async GET(_, ctx) {
@ -12,6 +13,11 @@ export const handler: Handlers = {
return json(movie);
},
async POST(_, ctx) {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
const tmdbId = parseInt(ctx.params.name);
const movieDetails = await tmdb.getMovie(tmdbId);

View File

@ -10,7 +10,7 @@ import * as tmdb from "@lib/tmdb.ts";
import { parse, stringify } from "https://deno.land/std@0.194.0/yaml/mod.ts";
import { formatDate, safeFileName } from "@lib/string.ts";
import { json } from "@lib/helpers.ts";
import { BadRequestError } from "@lib/errors.ts";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
async function updateMovieMetadata(
name: string,
@ -49,13 +49,18 @@ async function updateMovieMetadata(
}
const POST = async (
_req: Request,
_ctx: HandlerContext,
req: Request,
ctx: HandlerContext,
): Promise<Response> => {
const movie = await getMovie(_ctx.params.name);
const movie = await getMovie(ctx.params.name);
const body = await _req.json();
const name = _ctx.params.name;
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
const body = await req.json();
const name = ctx.params.name;
const { tmdbId } = body;
if (!name || !tmdbId) {
throw new BadRequestError();