Skip to content

Commit

Permalink
fix(logs): Remove or clarify old production + unit test logs (#365)
Browse files Browse the repository at this point in the history
Also fixes `[DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues.`
  • Loading branch information
adrienjoly committed Sep 6, 2020
1 parent 5130817 commit b22d871
Show file tree
Hide file tree
Showing 21 changed files with 68 additions and 172 deletions.
1 change: 0 additions & 1 deletion app/controllers/admin/tests/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ exports.makeTests = function (p) {
'/api/playlist',
{ body: { action: 'delete', id: testVars.pl.id } },
function (res) {
console.log('RES', res);
cb(true);
}
);
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/tests/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports.makeTests = function (p) {
//console.time("fetchByAuthors_v1");
postModel.fetchByAuthorsOld(testVars.uidList, OPTIONS, function (res) {
//console.timeEnd("fetchByAuthors_v1");
console.log('=> fetched', res.length, 'posts');
console.log('=> fetchedByAuthorsOld: ', res.length, 'posts');
testVars.hashedResult = hashPosts(res);
cb(true);
});
Expand All @@ -48,7 +48,7 @@ exports.makeTests = function (p) {
//console.time("fetchByAuthors_v2");
postModel.fetchByAuthors(testVars.uidList, OPTIONS, function (res) {
//console.timeEnd("fetchByAuthors_v2");
console.log('=> fetched', res.length, 'posts');
console.log('=> fetchedByAuthors:', res.length, 'posts');
cb(testVars.hashedResult === hashPosts(res));
});
},
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/tests/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ exports.makeTests = function (p) {
},
},
function (res, response) {
log('/register result:', res);
// log('/register result:', res);
testVars.registeredUid = res.uId;
testVars.cookie = response.headers['set-cookie'][0].split(';')[0];
cb(res.redirect && res.uId);
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/api/follow.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ exports.controller = function (request, reqParams, response) {

var sendResult = function (error, result) {
result = result && result._id ? { _id: result._id } : {};
if (error) result.error = error;
//console.log("follow API error: " + error);
console.log('follow API result: ', result);
if (error) {
result.error = error;
console.log('follow API error: ' + error);
}

if (reqParams.redirect) response.redirect(reqParams.redirect);
else response.renderJSON(result);
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/private/contentType.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.controller = function (request, reqParams, response) {
title: title,
images: images,
};
console.log('contentType result:', result);
// console.log('contentType result:', result);
response.legacyRender(result);
}

Expand Down
2 changes: 1 addition & 1 deletion app/lib/get/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function getPage(address, callback) {
length += chunk.length;
});
res.on('end', function () {
var buffer = new Buffer(length);
var buffer = Buffer.alloc(length);
var bufferPos = 0;
var i, chunk, text, charset;
for (i = 0; (chunk = chunks[i]); i++) {
Expand Down
2 changes: 1 addition & 1 deletion app/models/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var config = require('./config');
var users = require('./user');

var emailModule = config.emailModule || 'emailFake.js';
console.log('loading EMAIL module: ' + emailModule + '...');
// console.log('loading EMAIL module: ' + emailModule + '...');
var emailImpl = require('./' + emailModule);

// http://www.regular-expressions.info/email.html
Expand Down
3 changes: 2 additions & 1 deletion app/models/emailFake.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ exports.email = function (
userName,
callback
) {
/*
console.log('FAKE EMAIL', {
to: emailAddr,
subject: subject,
text: textContent,
html: !!htmlContent,
});
*/
setTimeout(function () {
var result = 'FAKE EMAIL => success';
console.log(result);
if (callback) callback(result);
}, fakeDeliveryDuration);
};
Expand Down
2 changes: 1 addition & 1 deletion app/models/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ http.IncomingMessage.prototype.getFacebookCookie = function () {
// https://developers.facebook.com/docs/authentication/signed_request/
try {
let cookie = cookies[i].split('.')[1];
cookie = new Buffer(cookie /*|| ""*/, 'base64').toString('ascii');
cookie = Buffer.from(cookie /*|| ""*/, 'base64').toString('ascii');
cookie = JSON.parse(cookie);
console.log('found secure facebook cookie'); //, cookie);
return cookie;
Expand Down
10 changes: 6 additions & 4 deletions app/models/mongodb-shell-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var vm = require('vm');
var async = require('async');
var mongodb = require('mongodb');

const PRINT_ACTIVE = false;
const VERBOSE = false; // true to display debug logs (for diagnostics and testing)
const LOG_PREFIX = '[mongo shell]';

Expand All @@ -16,10 +17,11 @@ function buildContext(db, nextCommand, callback) {

var context = {
print: function () {
console.log.apply(
console,
[LOG_PREFIX].concat(Array.prototype.slice.call(arguments))
);
PRINT_ACTIVE &&
console.log.apply(
console,
[LOG_PREFIX].concat(Array.prototype.slice.call(arguments))
);
nextCommand();
},
db: {
Expand Down
10 changes: 9 additions & 1 deletion app/models/notif.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,19 @@ function makeLink(text /*, url*/) {

// main methods

const extractObjectID = (str) => str.match(/[0-9a-f]{24}/)[0];

exports.clearUserNotifsForPost = function (uId, pId) {
if (!uId || !pId) return;
var idList = [pId];
try {
idList.push(mongodb.ObjectID.createFromHexString(pId));
idList.push(
mongodb.ObjectID.createFromHexString(
typeof pId === 'string'
? extractObjectID(pId) // strip the eventual "/u/" prefix or "/reposts" suffix (e.g. in notif-tests.js)
: pId
)
);
} catch (e) {
console.error('error in clearUserNotifsForPost:', e);
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/notifEmails.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function submitNotif(recipient, type, immediateNotifHandler, noNotifHandler) {
);
//console.log("notifEmails.submitNotif, type:", type, (recipient.pref || {})[type]);
if (recipient.pref && recipient.pref[type] == -1) {
console.log('no email notification will be sent (disabled by user)');
// console.log('no email notification will be sent (disabled by user)');
noNotifHandler && noNotifHandler();
} else if (recipient.pref && recipient.pref[type] > 0) {
userModel.incrementNotificationCounter(recipient._id, noNotifHandler);
Expand Down
5 changes: 2 additions & 3 deletions app/models/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ var FCTS_OPTIONAL = {

function makeNoImplHandler(methodName, cbPos) {
return function () {
console.log('models.search: NO IMPLEMENTATION for ' + methodName);
if (config.searchModule)
console.log('models.search: NO IMPLEMENTATION for ' + methodName);
var callback = arguments[cbPos];
callback && callback();
};
}

for (let methodName in FCTS_REQUIRED) {
if (!searchImpl[methodName])
console.error('models.search: NO IMPLEMENTATION for ' + methodName);
exports[methodName] =
searchImpl[methodName] ||
makeNoImplHandler(methodName, FCTS_REQUIRED[methodName]);
Expand Down
2 changes: 1 addition & 1 deletion app/models/searchAlgolia.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ exports.query = function (q = {}, cb) {
else
searchByType[type](q, function (res) {
if (res.hits) {
console.log('=>', res.hits.length, 'hits');
console.log('searchAlgolia.query =>', res.hits.length, 'hits');
hits = hits.concat(res.hits);
} else {
console.error(
Expand Down
2 changes: 1 addition & 1 deletion app/models/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function save(track, cb, replace) {

function remove(q, cb) {
mongodb.collections['track'].remove(q, function (error, result) {
console.log('=> removed hot track:', result);
console.log('=> removed hot track:', q);
if (error) console.error('track.remove() error: ' + error.stack);
if (cb) cb(result);
});
Expand Down
20 changes: 4 additions & 16 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,9 @@ var TESTING_DIGEST = config.digestImmediate;

(function parseHandlesFromRouteFile(routeFile) {
var nb = 0;
console.log('Parsing reserved usernames from', routeFile, '...');
// console.log('Parsing reserved usernames from', routeFile, '...');
snip.forEachFileLine(routeFile, function (line) {
if (typeof line != 'string')
return console.log(
'=> Parsed',
nb,
'handles from:',
routeFile /*, " : ", USERNAME_RESERVED*/
);
if (typeof line != 'string') return; // console.log('=> Parsed', nb, 'handles from:', routeFile);
line = line.substr(line.indexOf('/') + 1);
var end = line.search(/[\t/]/);
if (end > -1) {
Expand All @@ -138,15 +132,9 @@ var TESTING_DIGEST = config.digestImmediate;

(function parseHandlesFromTextFile(fileName) {
var nb = 0;
console.log('Parsing reserved usernames from', fileName, '...');
// console.log('Parsing reserved usernames from', fileName, '...');
snip.forEachFileLine(fileName, function (line) {
if (typeof line != 'string')
return console.log(
'=> Parsed',
nb,
'handles from:',
fileName /*, " : ", USERNAME_RESERVED*/
);
if (typeof line != 'string') return; // console.log('=> Parsed', nb, 'handles from:', fileName);
if (!line.length || line[0] == '#') return;
USERNAME_RESERVED[line] = true;
++nb;
Expand Down
104 changes: 0 additions & 104 deletions app/serverTestRunner.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/templates/invitePage.html
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ <h2>Join Openwhyd</h2>
$('input[type=submit]').removeClass('loading');
res = res.substring(res.indexOf('{'), res.lastIndexOf('}') + 1);
res = JSON.parse(res);
console.log('response', res);
// console.log('response', res);
if (res.error) {
console.log('error', res.error);
console.log('invitePage error', res.error);
if (res.error.indexOf('name') != -1) $name.each(error);
else if (res.error.indexOf('email') != -1) $email.each(error);
else if (res.error.indexOf('password') != -1)
Expand Down
16 changes: 8 additions & 8 deletions config/initdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ db.createCollection('featured');
db.createCollection('plContest');
db.createCollection('comment');

print('indexing post collection...');
// print('indexing post collection...');
db.post.ensureIndex({ uId: 1 });
db.post.ensureIndex({ uId: 1, 'pl.id': 1 }, { sparse: true });
db.post.ensureIndex({ 'pl.id': 1 }, { sparse: true });
Expand All @@ -28,11 +28,11 @@ db.post.ensureIndex({ lov: 1 }, { sparse: true });
db.post.ensureIndex({ 'repost.pId': 1 }, { sparse: true });
db.post.ensureIndex({ 'repost.uId': 1 }, { sparse: true });

print('indexing follow collection...');
// print('indexing follow collection...');
db.follow.ensureIndex({ uId: 1 });
db.follow.ensureIndex({ tId: 1 });

print('indexing user collection...');
// print('indexing user collection...');
db.user.ensureIndex({ email: 1 });
db.user.ensureIndex({ handle: 1 }, { sparse: true });
db.user.ensureIndex({ fbId: 1 }, { sparse: true });
Expand All @@ -42,24 +42,24 @@ db.user.ensureIndex({ 'pref.pendEN': 1 }, { sparse: true });
db.user.ensureIndex({ 'pref.nextEN': 1 }, { sparse: true });
db.user.ensureIndex({ 'sp.id': 1 }, { sparse: true }); // spotify id

print('indexing activity collection...');
// print('indexing activity collection...');
db.activity.ensureIndex({ id: 1 }, { sparse: true }); /*poster.id*/
db.activity.ensureIndex({ 'like.id': 1 }, { sparse: true });
db.activity.ensureIndex({ 'like.pId': 1 }, { sparse: true });

print('indexing track collection...');
// print('indexing track collection...');
db.track.ensureIndex({ eId: 1 });
db.track.ensureIndex({ score: 1 });

print('indexing plContest collection...');
// print('indexing plContest collection...');
db.plContest.ensureIndex({ uri: 1 });
db.plContest.ensureIndex({ title: 1 });
db.plContest.dropIndex({ pId: 1 }); // to solve the accidental index made in previous version of this file

print('indexing comment collection...');
// print('indexing comment collection...');
db.comment.ensureIndex({ pId: 1 });

print('indexing notif collection...');
// print('indexing notif collection...');
db.notif.ensureIndex({ uId: 1 });

print('done! :-)');
Loading

0 comments on commit b22d871

Please sign in to comment.