From ab862d08fd0552a2df3a7549683918266b9ad284 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 23:51:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 3 +-- views/index.pug | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index feb8c8c..5c18213 100644 --- a/server.js +++ b/server.js @@ -38,7 +38,7 @@ app.post('/upload', upload.single('file'), async (req, res) => { } fs.unlinkSync(file_temp_path) // 删除临时文件 // 写入数据库 - const filesharing = new Filesharing({ + const file = await Filesharing.create({ md5, size: req.file.size, encoding: req.file.encoding, @@ -47,7 +47,6 @@ app.post('/upload', upload.single('file'), async (req, res) => { filename: Buffer.from(req.file.originalname, 'latin1').toString('utf8'), password: req.body.password ? await bcrypt.hash(req.body.password, 16) : '', }) - const file = await filesharing.save() res.status(201).render('upload', { file }) }) app.get('/file/:id', async (req, res) => { diff --git a/views/index.pug b/views/index.pug index a523fe4..8973d6a 100644 --- a/views/index.pug +++ b/views/index.pug @@ -17,7 +17,7 @@ html(lang='zh') else for file in filesharing li - a(href=`/file/${file.id}` target='_blank')= file.filename + a(href=`/file/${file.id}`)= file.filename if file.password span   ㊙️ span.small   ( #{moment(file.createdAt).fromNow()}, #{file.downloads} 次下载 )