简化附件上传
This commit is contained in:
parent
30ae6e0953
commit
6923434295
17
index.js
17
index.js
@ -92,7 +92,7 @@ function session_create(req, res) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 也许使用账号密码登录
|
// 也许使用账号密码登录
|
||||||
return db('user').findOne({ name }, function (err, doc) {
|
return db('user').findOne({ name }, function (err, doc) {
|
||||||
if (!doc) return res.status(400).send('账户不存在')
|
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 } })
|
db(req.params.name).update({ _id: req.params._id }, { $set: { views: doc.views ? doc.views + 1 : 1 } })
|
||||||
return res.json(doc)
|
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 res.status(403).send('没有权限上传')
|
||||||
}
|
}
|
||||||
return formidable({ multiples: true, uploadDir: 'data/file', keepExtensions: true, maxFieldsSize: 200 * 1024 * 1024 }).parse(req, function (err, fields, files) {
|
return formidable({ multiples: true, uploadDir: 'data/file', keepExtensions: true, maxFieldsSize: 200 * 1024 * 1024 }).parse(req, function (err, fields, files) {
|
||||||
let list = []
|
const list = Object.values(files).map(item => Array.isArray(item) ? item : [item]).flat().map(({ filepath, mimetype, mtime, newFilename, originalFilename, size }) => {
|
||||||
for (let key in files) {
|
return { filepath, mimetype, mtime, newFilename, originalFilename, size }
|
||||||
(Array.isArray(files[key]) ? files[key] : [files[key]]).map(({ filepath, mimetype, mtime, newFilename, originalFilename, size }) => list.push({
|
})
|
||||||
filepath, mimetype, mtime, newFilename, originalFilename, size
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
return db(req.params.name).update({ _id: req.params._id }, { $addToSet: { file: { $each: list } } }, function (err, count) {
|
return db(req.params.name).update({ _id: req.params._id }, { $addToSet: { file: { $each: list } } }, function (err, count) {
|
||||||
if (!count) return res.status(500).send('附件挂载对象失败')
|
if (!count) return res.status(500).send('附件挂载对象失败')
|
||||||
console.log(list)
|
console.log(list)
|
||||||
@ -574,11 +570,6 @@ function index_get(req, res) {
|
|||||||
res.json(list)
|
res.json(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 锁定对象列表
|
|
||||||
function index_patch(req, res) {
|
|
||||||
// 指定设定的目标类型
|
|
||||||
}
|
|
||||||
|
|
||||||
const app = expressWs(express()).app
|
const app = expressWs(express()).app
|
||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
app.use(express.urlencoded({ extended: false }))
|
app.use(express.urlencoded({ extended: false }))
|
||||||
|
Loading…
Reference in New Issue
Block a user