Skip to content

Instantly share code, notes, and snippets.

@WoolDoughnut310
Created October 28, 2022 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WoolDoughnut310/3a03fe913be96731c62c84fb729375e4 to your computer and use it in GitHub Desktop.
Save WoolDoughnut310/3a03fe913be96731c62c84fb729375e4 to your computer and use it in GitHub Desktop.
router.post(
"/",
upload.single("song"),
asyncHandler(async (req: Request, res: Response) => {
const db = getDb();
const collection = db.collection<Song>("song");
if (!req.file?.filename) {
res.status(400).send("File not uploaded");
return;
}
const result = await collection.insertOne({
userId: req.auth.id,
filename: req.file.filename,
mimeType: req.file.mimetype,
title: req.body.title,
duration: req.body.duration,
genre: req.body.genre,
lyrics: req.body.lyrics,
uploaded: new Date(),
});
res.status(200).json(result);
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment