From e0233f2899a3206a817d2dd3b80da83d51c7a726 Mon Sep 17 00:00:00 2001 From: jomo Date: Sun, 29 Mar 2020 20:13:24 +0200 Subject: [PATCH] document undocumented functions --- README.md | 4 ++-- lib/helpers.js | 6 +++--- lib/logging.js | 4 ++++ lib/networking.js | 2 ++ lib/routes/index.js | 1 + lib/server.js | 2 ++ 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1fd6e22..79779fb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# Crafatar [![travis](https://img.shields.io/travis/crafatar/crafatar/master.svg?style=flat-square)](https://travis-ci.org/crafatar/crafatar/) [![Coverage Status](https://img.shields.io/coveralls/crafatar/crafatar.svg?style=flat-square)](https://coveralls.io/r/crafatar/crafatar) [![Code Climate](https://img.shields.io/codeclimate/github/crafatar/crafatar.svg?style=flat-square)](https://codeclimate.com/github/crafatar/crafatar) -[![dependency status](https://img.shields.io/david/crafatar/crafatar.svg?style=flat-square)](https://david-dm.org/crafatar/crafatar) [![devDependency status](https://img.shields.io/david/dev/crafatar/crafatar.svg?style=flat-square)](https://david-dm.org/crafatar/crafatar#info=devDependencies) [![docs status](https://inch-ci.org/github/crafatar/crafatar.svg?branch=master&style=flat-square)](https://inch-ci.org/github/crafatar/crafatar) +# Crafatar +[![travis](https://img.shields.io/travis/crafatar/crafatar/master.svg?style=flat-square)](https://travis-ci.org/crafatar/crafatar/) [![Coverage Status](https://img.shields.io/coveralls/crafatar/crafatar.svg?style=flat-square)](https://coveralls.io/r/crafatar/crafatar) [![Code Climate](https://img.shields.io/codeclimate/github/crafatar/crafatar.svg?style=flat-square)](https://codeclimate.com/github/crafatar/crafatar) [![dependency status](https://img.shields.io/david/crafatar/crafatar.svg?style=flat-square)](https://david-dm.org/crafatar/crafatar) [![devDependency status](https://img.shields.io/david/dev/crafatar/crafatar.svg?style=flat-square)](https://david-dm.org/crafatar/crafatar#info=devDependencies) [![docs status](https://inch-ci.org/github/crafatar/crafatar.svg?branch=master&style=flat-square)](https://inch-ci.org/github/crafatar/crafatar) logo diff --git a/lib/helpers.js b/lib/helpers.js index 65beef1..d863a24 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -122,13 +122,14 @@ var requests = { cape: {} }; -function push_request(userId, type, fun) { +// add a request for +userId+ and +type+ to the queue +function push_request(userId, type, callback) { // avoid special properties (e.g. 'constructor') var userId_safe = "!" + userId; if (!requests[type][userId_safe]) { requests[type][userId_safe] = []; } - requests[type][userId_safe].push(fun); + requests[type][userId_safe].push(callback); } // calls back all queued requests that match userId and type @@ -162,7 +163,6 @@ function store_images(rid, userId, cache_details, type, callback) { logging.debug(rid, "adding to request queue"); push_request(userId, type, callback); } else { - // add request to the queue push_request(userId, type, callback); networking.get_profile(rid, userId, function(err, profile) { diff --git a/lib/logging.js b/lib/logging.js index c517930..ff98ace 100644 --- a/lib/logging.js +++ b/lib/logging.js @@ -23,15 +23,19 @@ function log(level, args, logger) { } } +// log with INFO level exp.log = function() { log(" INFO", arguments); }; +// log with WARN level exp.warn = function() { log(" WARN", arguments, console.warn); }; +// log with ERROR level exp.error = function() { log("ERROR", arguments, console.error); }; +// log with DEBUG level if debug logging is enabled if (config.server.debug_enabled) { exp.debug = function() { log("DEBUG", arguments); diff --git a/lib/networking.js b/lib/networking.js index 47ae317..ffb502b 100644 --- a/lib/networking.js +++ b/lib/networking.js @@ -13,6 +13,7 @@ var session_requests = []; var exp = {}; +// returns the amount of outgoing session requests made in the last 1000ms function req_count() { var index = session_requests.findIndex((i) => i >= Date.now() - 1000); if (index >= 0) { @@ -22,6 +23,7 @@ function req_count() { } } +// deletes all entries in session_requests older than a second exp.resetCounter = function() { var count = req_count(); if (count) { diff --git a/lib/routes/index.js b/lib/routes/index.js index 6c22a04..5a663b7 100644 --- a/lib/routes/index.js +++ b/lib/routes/index.js @@ -7,6 +7,7 @@ var ejs = require("ejs"); var str; var index; +// pre-compile the index page function compile() { logging.log("Compiling index page"); str = read(path.join(__dirname, "..", "views", "index.html.ejs"), "utf-8"); diff --git a/lib/server.js b/lib/server.js index 5507daa..a6a4c64 100644 --- a/lib/server.js +++ b/lib/server.js @@ -135,6 +135,7 @@ function requestHandler(req, res) { var exp = {}; +// Start the server exp.boot = function(callback) { var port = config.server.port; var bind_ip = config.server.bind; @@ -163,6 +164,7 @@ exp.boot = function(callback) { }); }; +// Close the server exp.close = function(callback) { server.close(callback); };