move profile icons into the database
This commit is contained in:
51
src/users.js
51
src/users.js
@@ -31,10 +31,9 @@ exports = module.exports = {
|
||||
sendPasswordResetByIdentifier,
|
||||
|
||||
setupAccount,
|
||||
getAvatarUrlSync,
|
||||
getAvatarFileSync,
|
||||
getAvatarUrl,
|
||||
setAvatar,
|
||||
clearAvatar,
|
||||
getAvatar,
|
||||
|
||||
count,
|
||||
|
||||
@@ -62,11 +61,9 @@ let assert = require('assert'),
|
||||
debug = require('debug')('box:user'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
externalLdap = require('./externalldap.js'),
|
||||
fs = require('fs'),
|
||||
groups = require('./groups.js'),
|
||||
hat = require('./hat.js'),
|
||||
mailer = require('./mailer.js'),
|
||||
path = require('path'),
|
||||
paths = require('./paths.js'),
|
||||
qrcode = require('qrcode'),
|
||||
safe = require('safetydance'),
|
||||
@@ -816,38 +813,34 @@ function delAppPassword(id, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getAvatarFileSync(id) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
|
||||
return path.join(paths.PROFILE_ICONS_DIR, id);
|
||||
}
|
||||
|
||||
function getAvatarUrlSync(user) {
|
||||
function getAvatarUrl(user, callback) {
|
||||
assert.strictEqual(typeof user, 'object');
|
||||
|
||||
if (fs.existsSync(path.join(paths.PROFILE_ICONS_DIR, user.id))) return `${settings.adminOrigin()}/api/v1/profile/avatar/${user.id}`;
|
||||
|
||||
const emailHash = require('crypto').createHash('md5').update(user.email).digest('hex');
|
||||
return `https://www.gravatar.com/avatar/${emailHash}.jpg`;
|
||||
}
|
||||
|
||||
function setAvatar(id, filename, callback) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof filename, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
// rename() was failing on some servers with EXDEV
|
||||
fs.copyFile(filename, path.join(paths.PROFILE_ICONS_DIR, id), function (error) {
|
||||
if (error) return callback(new BoxError(BoxError.FS_ERROR, error.message));
|
||||
userdb.getAvatar(user.id, function (error, avatar) {
|
||||
if (error) return callback(error);
|
||||
if (avatar) return callback(null, `${settings.adminOrigin()}/api/v1/profile/avatar/${user.id}`);
|
||||
|
||||
fs.unlink(filename, () => callback()); // ignore any unlink error
|
||||
const emailHash = require('crypto').createHash('md5').update(user.email).digest('hex');
|
||||
return callback(null, `https://www.gravatar.com/avatar/${emailHash}.jpg`);
|
||||
});
|
||||
}
|
||||
|
||||
function clearAvatar(id, callback) {
|
||||
function getAvatar(id, callback) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
safe.fs.unlinkSync(path.join(paths.PROFILE_ICONS_DIR, id));
|
||||
callback();
|
||||
userdb.getAvatar(id, function (error, avatar) {
|
||||
if (error) return callback(error);
|
||||
|
||||
return callback(null, avatar);
|
||||
});
|
||||
}
|
||||
|
||||
function setAvatar(id, avatar, callback) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert(avatar === null || Buffer.isBuffer(avatar));
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
userdb.setAvatar(id, avatar, callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user