embed controller

This commit is contained in:
Maxime Cannoodt 2022-08-30 13:52:52 +02:00
parent bbc92dc01c
commit f60dc3b018
4 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import express, {
type NextFunction,
type Request,
type Response,
} from "express";
import { getEmbed } from "../../../db/embed.dao";
export async function getNoteController(
req: Request,
res: Response,
next: NextFunction
): Promise<void> {
const { id: note_id, embed_id } = req.params;
try {
const embed = await getEmbed(note_id, embed_id);
if (embed != null) {
res.status(200).json(embed).send();
} else {
res.status(404).send();
}
} catch (err) {
next(err);
}
}

View File

@ -0,0 +1,6 @@
import express from "express";
import { getNoteController } from "../note.get.controller";
export const embedsRoute = express.Router({ mergeParams: true });
embedsRoute.get("/:embed_id", getNoteController);

View File

@ -3,6 +3,7 @@ import { getExpiredNoteFilter } from "../../lib/expiredNoteFilter";
import EventLogger from "../../logging/EventLogger";
import { getConnectingIp } from "../../util";
import { getNote } from "../../db/note.dao";
export async function getNoteController(
req: Request,
res: Response,

View File

@ -1,6 +1,7 @@
import bodyParser from "body-parser";
import express from "express";
import rateLimit from "express-rate-limit";
import { embedsRoute } from "./embeds/embeds.router";
import { getNoteController } from "./note.get.controller";
import { postNoteController } from "./note.post.controller";
@ -28,3 +29,4 @@ notesRoute.use(uploadLimit);
notesRoute.use(jsonParser);
notesRoute.post("", postRateLimit, postNoteController);
notesRoute.get("/:id", getRateLimit, getNoteController);
notesRoute.use("/:id/embeds/", embedsRoute);