More sanity checking on passed IDs
This commit is contained in:
parent
a33570e1d0
commit
ff698cff14
4 changed files with 22 additions and 2 deletions
|
@ -24,6 +24,7 @@ module.exports.match = function(url, type) {
|
||||||
|
|
||||||
module.exports.lookupId = function(id) {
|
module.exports.lookupId = function(id) {
|
||||||
var deferred = Q.defer();
|
var deferred = Q.defer();
|
||||||
|
|
||||||
if (id.substr(0,2) == "al") {
|
if (id.substr(0,2) == "al") {
|
||||||
request.get(apiRoot + "/albums/" + id + "/images/default?size=medium&client_id=" + credentials.key).redirects(0).end(function(res) {
|
request.get(apiRoot + "/albums/" + id + "/images/default?size=medium&client_id=" + credentials.key).redirects(0).end(function(res) {
|
||||||
var artwork = res.headers.location;
|
var artwork = res.headers.location;
|
||||||
|
@ -65,6 +66,10 @@ module.exports.lookupId = function(id) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
var error = new Error("Not Found");
|
||||||
|
error.status = 404;
|
||||||
|
deferred.reject(error);
|
||||||
}
|
}
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,12 @@ module.exports.lookupId = function(id, type) {
|
||||||
|
|
||||||
request.get(apiRoot + path, function(res) {
|
request.get(apiRoot + path, function(res) {
|
||||||
var result = res.body;
|
var result = res.body;
|
||||||
|
if (res.body.error) {
|
||||||
|
var error = new Error("Not Found");
|
||||||
|
error.status = 404;
|
||||||
|
deferred.reject(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var cover = result.cover || result.album.cover;
|
var cover = result.cover || result.album.cover;
|
||||||
request.get(cover).redirects(0).end(function(res) {
|
request.get(cover).redirects(0).end(function(res) {
|
||||||
var artwork = res.headers.location.replace("120x120", "200x200");
|
var artwork = res.headers.location.replace("120x120", "200x200");
|
||||||
|
|
|
@ -19,8 +19,11 @@ module.exports.lookupId = function(id, type) {
|
||||||
request.get(apiRoot + path, function(res) {
|
request.get(apiRoot + path, function(res) {
|
||||||
var data = JSON.parse(res.text);
|
var data = JSON.parse(res.text);
|
||||||
|
|
||||||
if (!data.results[0].collectionId) {
|
if (!data.results || !data.results[0].collectionId) {
|
||||||
deferred.resolve({service: "itunes"});
|
var error = new Error("Not Found");
|
||||||
|
error.status = 404;
|
||||||
|
deferred.reject(error);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
var result = data.results[0];
|
var result = data.results[0];
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,12 @@ module.exports.lookupId = function(id) {
|
||||||
method: 'getObjectFromShortCode',
|
method: 'getObjectFromShortCode',
|
||||||
short_code: id,
|
short_code: id,
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
|
if (err || !JSON.parse(results).result) {
|
||||||
|
var error = new Error("Not Found");
|
||||||
|
error.status = 404;
|
||||||
|
deferred.reject(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var result = JSON.parse(results).result;
|
var result = JSON.parse(results).result;
|
||||||
var parsed = parse(result.shortUrl)
|
var parsed = parse(result.shortUrl)
|
||||||
var id = parsed.path.replace("/x/", "").replace("/", "");
|
var id = parsed.path.replace("/x/", "").replace("/", "");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue