mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 02:36:16 +01:00
refactor: deprecate picture update socket call, new API routes for picture update
This commit is contained in:
@@ -3,42 +3,13 @@
|
||||
const user = require('../../user');
|
||||
const plugins = require('../../plugins');
|
||||
|
||||
const websockets = require('../index');
|
||||
const api = require('../../api');
|
||||
|
||||
module.exports = function (SocketUser) {
|
||||
SocketUser.changePicture = async function (socket, data) {
|
||||
if (!socket.uid) {
|
||||
throw new Error('[[error:invalid-uid]]');
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
const { type } = data;
|
||||
let picture = '';
|
||||
await user.isAdminOrGlobalModOrSelf(socket.uid, data.uid);
|
||||
if (type === 'default') {
|
||||
picture = '';
|
||||
} else if (type === 'uploaded') {
|
||||
picture = await user.getUserField(data.uid, 'uploadedpicture');
|
||||
} else {
|
||||
const returnData = await plugins.hooks.fire('filter:user.getPicture', {
|
||||
uid: socket.uid,
|
||||
type: type,
|
||||
picture: undefined,
|
||||
});
|
||||
picture = returnData && returnData.picture;
|
||||
}
|
||||
|
||||
const validBackgrounds = await user.getIconBackgrounds(socket.uid);
|
||||
if (!validBackgrounds.includes(data.bgColor)) {
|
||||
data.bgColor = validBackgrounds[0];
|
||||
}
|
||||
|
||||
await user.updateProfile(socket.uid, {
|
||||
uid: data.uid,
|
||||
picture: picture,
|
||||
'icon:bgColor': data.bgColor,
|
||||
}, ['picture', 'icon:bgColor']);
|
||||
websockets.warnDeprecated(socket, 'PUT /api/v3/users/:uid/picture');
|
||||
await api.users.changePicture(socket, data);
|
||||
};
|
||||
|
||||
SocketUser.removeUploadedPicture = async function (socket, data) {
|
||||
|
||||
Reference in New Issue
Block a user