Created
October 28, 2022 15:12
-
-
Save WoolDoughnut310/3a03fe913be96731c62c84fb729375e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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