简化附件上传

This commit is contained in:
2024-04-24 01:38:25 +08:00
parent 30ae6e0953
commit 6923434295

View File

@ -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 }))