From 9f12482b304894704ac6d7680effe575ac925467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=91=AB?= <7176466@qq.com> Date: Fri, 26 Aug 2022 17:57:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BA=86=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server.js b/server.js index 45b97a8..0ad822f 100644 --- a/server.js +++ b/server.js @@ -45,6 +45,18 @@ app.post('/upload', upload.single('file'), async (req, res) => { console.table(file) res.status(201).render('index', { file }) }) +app.get('/file/:id', async (req, res) => { + const file = await Fileshare.findByIdAndUpdate(req.params.id, { $inc: { downloads: 1 } }) + if (file) { + const file_path = path.join(SAVE_PATH, file.md5) + if (file.password == '') { + res.status(200).download(file_path, file.filename) + } else { + } + } else { + res.sendStatus(404) + } +}) const server = app.listen(SERVER_PORT, SERVER_HOST, () => { console.info(`server is running at http://${SERVER_HOST}:${SERVER_PORT}`) })