embed controller
This commit is contained in:
parent
bbc92dc01c
commit
f60dc3b018
24
server/src/controllers/note/embeds/embeds.get.controller.ts
Normal file
24
server/src/controllers/note/embeds/embeds.get.controller.ts
Normal 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);
|
||||
}
|
||||
}
|
6
server/src/controllers/note/embeds/embeds.router.ts
Normal file
6
server/src/controllers/note/embeds/embeds.router.ts
Normal 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);
|
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user