From e5d9a4c125642f57a0d2524c37ad1c680cf5bb3d Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sat, 13 Jul 2013 22:25:34 -0400 Subject: [PATCH] A few small improvements --- api.js | 7 ++++ get-info.js | 101 +++++++++++++++++++-------------------------------- package.json | 2 +- server.js | 2 +- 4 files changed, 47 insertions(+), 65 deletions(-) diff --git a/api.js b/api.js index d4599499..31233f8a 100644 --- a/api.js +++ b/api.js @@ -275,6 +275,13 @@ function handlePasswordReset(params, req, res) { }); return; } + if(!email) { + sendJSON(res, { + success: false, + error: "You don't have a recovery email address set. Contact an administrator" + }); + return; + } var msg = [ "A password reset request was issued for your account `", name, diff --git a/get-info.js b/get-info.js index 88a83299..5b79e8ae 100644 --- a/get-info.js +++ b/get-info.js @@ -16,72 +16,47 @@ var Media = require("./media.js").Media; // Helper function for making an HTTP request and getting the result // as JSON +function getJSONInternal(transport, options, callback) { + var req = transport.request(options, function(res) { + var buffer = ""; + res.setEncoding("utf8"); + res.on("data", function (chunk) { + buffer += chunk; + }); + res.on("end", function() { + try { + var data = JSON.parse(buffer); + } + catch(e) { + var m = buffer.match(/([^<]+)<\/internalReason>/); + if(m === null) + m = buffer.match(/([^<]+)<\/code>/); + if(m === null) + m = buffer.match(/([0-9]+ not found)/); + Logger.errlog.log("Media request failed: "+options.host+options.path); + if(m) { + Logger.errlog.log("Reason: " + m[1]); + callback(m[1], res.statusCode, null); + } + else { + callback(true, res.statusCode, null); + } + return; + } + callback(false, res.statusCode, data); + }); + }); + + req.end(); +}; + function getJSON(options, callback) { - var req = http.request(options, function(res) { - var buffer = ""; - res.setEncoding("utf8"); - res.on("data", function (chunk) { - buffer += chunk; - }); - res.on("end", function() { - try { - var data = JSON.parse(buffer); - } - catch(e) { - Logger.errlog.log("JSON fail: " + options.path); - var m = buffer.match(/([^<]+)<\/internalReason>/); - if(m === null) - m = buffer.match(/([^<]+)<\/code>/); - if(m === null) - m = buffer.match(/([0-9]+ not found)/); - if(m) { - callback(m[1], res.statusCode, null); - } - else { - callback(true, res.statusCode, null); - } - return; - } - callback(false, res.statusCode, data); - }); - }); + getJSONInternal(http, options, callback); +} - req.end(); -}; - -// Dailymotion uses HTTPS for anonymous requests... [](/picard) function getJSONHTTPS(options, callback) { - var req = https.request(options, function(res) { - var buffer = ""; - res.setEncoding("utf8"); - res.on("data", function (chunk) { - buffer += chunk; - }); - res.on("end", function() { - try { - var data = JSON.parse(buffer); - } - catch(e) { - Logger.errlog.log("JSON fail: " + options.path); - var m = buffer.match(/([^<]+)<\/internalReason>/); - if(m === null) - m = buffer.match(/([^<]+)<\/code>/); - if(m === null) - m = buffer.match(/([0-9]+ not found)/); - if(m) { - callback(m[1], res.statusCode, null); - } - else { - callback(true, res.statusCode, null); - } - return; - } - callback(false, res.statusCode, data); - }); - }); - - req.end(); -}; + getJSONInternal(https, options, callback); +} // Look up YouTube metadata // Fairly straightforward diff --git a/package.json b/package.json index c296645f..95ac9023 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "2.0.4", + "version": "2.0.5", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/server.js b/server.js index d1c2c688..a2997403 100644 --- a/server.js +++ b/server.js @@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -const VERSION = "2.0.4"; +const VERSION = "2.0.5"; var fs = require("fs"); var Logger = require("./logger.js");