From 4b73a7ea080cac88c8e58771d508de15f55abfc7 Mon Sep 17 00:00:00 2001 From: satori Date: Sun, 30 Jan 2022 17:36:22 +0800 Subject: [PATCH] avatar data --- README.md | 30 +++++++----------------------- index.js | 7 ++++--- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index c595163..b8ba8d9 100644 --- a/README.md +++ b/README.md @@ -179,22 +179,20 @@ fetch('/user/ApSXNLoUy', { #### 上传头像 -实际分为两步, -第一步先上传附件到自己的账户 - ```html - + ``` -第二步修改自己的头像路径为返回的图像路径, (!注意此处未作安全检查) -```javascript -fetch('/user/ApSXNLoUy', { - method: 'PATCH', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - avatar: '/xxxx.jpg' - }), -}).then(Response => Response.json()).then(data => { - console.log(data) -}) -``` - - #### 删除用户 diff --git a/index.js b/index.js index 07010ce..04a0f94 100644 --- a/index.js +++ b/index.js @@ -396,15 +396,16 @@ const uploadavatar = function (req, res) { if (!list[0]) return res.status(400).send('未获得图像') + let avatar = '/data/file/' + list[0].newFilename let query = { _id: req.session.account.uid } let data = { - $addToSet: { file: { $each: list } }, // 保存记录 - $set: { avatar: '/data/file/' + list[0].newFilename }, // 替换头像 + $addToSet: { file: { $each: list } }, // 保存记录 + $set: { avatar }, // 替换头像 } db('user').update(query, data, (err, count) => { if (!count) return res.status(500).send('附件挂载对象失败') - res.json(list[0]) // 返回唯一图像 + res.json({ ...list[0], avatar }) // 返回唯一图像 }) })