A few small improvements

This commit is contained in:
Calvin Montgomery 2013-07-13 22:25:34 -04:00
parent f2b6534d0a
commit e5d9a4c125
4 changed files with 47 additions and 65 deletions

7
api.js
View file

@ -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,

View file

@ -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>([^<]+)<\/internalReason>/);
if(m === null)
m = buffer.match(/<code>([^<]+)<\/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>([^<]+)<\/internalReason>/);
if(m === null)
m = buffer.match(/<code>([^<]+)<\/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>([^<]+)<\/internalReason>/);
if(m === null)
m = buffer.match(/<code>([^<]+)<\/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

View file

@ -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"
},

View file

@ -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");