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} 次下载 )