Editing Redis database (User avatar paths)

General Discussion
  • Hey,

    I'm in a big trouble xD Basically, I've been using my own modified version of the gravatar way of pulling the avatars from a custom API. However, the service has recently been overloaded & avatars are constantly not showing. I'd like to change the service, but I have no idea how to change the paths of all registered users' avatars as the paths are defined in the database. The file I modified for this hack was /src/user/create.js & changed the following values:

    var userData = {
    		'picture': 'https://minotar.net/avatar/'+userData.username,
    		'gravatarpicture': 'https://minotar.net/avatar/'+userData.username,
    		'uploadedpicture': 'https://minotar.net/avatar/'+userData.username,
    	};
    

    Any ideas how to change the service URL for the existing users? 😄

  • You need to write a server side script to go through all the users and update their urls.

    Something like the following should work.

    var db = require('./database'),
          user = require('./user'),
          async = require('async');
    
    db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) {
        async.eachLimit(uids, 50, updateUserImage, function(err) {
             console.log('done');
        });
    });
    
    function updateUserImage(uid, next) {
         user.getUserFields(uid, ['image', 'gravatarpicture', 'uploadedpicture'], function(err, userData) {
                // do your update here, can check current data from userData
                user.setUserField(uid, 'gravatarpicture', 'some_new_url', next); 
         });
    }
    

Suggested Topics