From 692343429579096c19bbc38bd016dfb7dba95150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Wed, 24 Apr 2024 01:38:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E9=99=84=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index c5f3587..8fb0a5c 100644 --- a/index.js +++ b/index.js @@ -92,7 +92,7 @@ function session_create(req, res) { }) }) } - + // 也许使用账号密码登录 return db('user').findOne({ name }, function (err, doc) { if (!doc) return res.status(400).send('账户不存在') @@ -471,7 +471,6 @@ const object_load = function (req, res) { } db(req.params.name).update({ _id: req.params._id }, { $set: { views: doc.views ? doc.views + 1 : 1 } }) return res.json(doc) - //return res.json({ user: await user_load(doc.uid), ...doc }) }) } @@ -483,12 +482,9 @@ const file_upload = function (req, res) { return res.status(403).send('没有权限上传') } return formidable({ multiples: true, uploadDir: 'data/file', keepExtensions: true, maxFieldsSize: 200 * 1024 * 1024 }).parse(req, function (err, fields, files) { - let list = [] - for (let key in files) { - (Array.isArray(files[key]) ? files[key] : [files[key]]).map(({ filepath, mimetype, mtime, newFilename, originalFilename, size }) => list.push({ - filepath, mimetype, mtime, newFilename, originalFilename, size - })) - } + const list = Object.values(files).map(item => Array.isArray(item) ? item : [item]).flat().map(({ filepath, mimetype, mtime, newFilename, originalFilename, size }) => { + return { filepath, mimetype, mtime, newFilename, originalFilename, size } + }) return db(req.params.name).update({ _id: req.params._id }, { $addToSet: { file: { $each: list } } }, function (err, count) { if (!count) return res.status(500).send('附件挂载对象失败') console.log(list) @@ -574,11 +570,6 @@ function index_get(req, res) { res.json(list) } -// 锁定对象列表 -function index_patch(req, res) { - // 指定设定的目标类型 -} - const app = expressWs(express()).app app.use(express.json()) app.use(express.urlencoded({ extended: false }))