Code cleanup
This commit is contained in:
parent
a74ccfa575
commit
be00516521
18 changed files with 209 additions and 202 deletions
|
@ -1,41 +1,40 @@
|
|||
"use strict";
|
||||
var parse = require('url').parse;
|
||||
var path = require('path');
|
||||
var lookup = require('../lib/lookup');
|
||||
var services = require('../lib/services');
|
||||
var parse = require("url").parse;
|
||||
var lookup = require("../lib/lookup");
|
||||
var services = require("../lib/services");
|
||||
|
||||
module.exports = function(req, res, next) {
|
||||
module.exports = function(req, res) {
|
||||
var url = parse(req.body.url);
|
||||
if (!url.host) {
|
||||
return res.json({error:{message:"You need to submit a url."}});
|
||||
return res.json({error: {message: "You need to submit a url."}});
|
||||
}
|
||||
|
||||
|
||||
var promise = lookup(req.body.url);
|
||||
|
||||
|
||||
if (!promise) {
|
||||
return res.json({error: {message: "No supported music found at that link :("}});
|
||||
}
|
||||
|
||||
|
||||
promise.then(function(item) {
|
||||
if (!item) {
|
||||
return res.json({error: {message: "No supported music found at that link :("}});
|
||||
}
|
||||
item.matched_at = new Date();
|
||||
item.matched_at = new Date(); // eslint-disable-line camelcase
|
||||
var matches = {};
|
||||
matches[item.service] = item;
|
||||
services.forEach(function(service) {
|
||||
if (service.id == item.service) {
|
||||
if (service.id === item.service) {
|
||||
return;
|
||||
}
|
||||
matches[service.id] = {service: service.id};
|
||||
service.search(item).then(function(match) {
|
||||
match.matched_at = new Date();
|
||||
match.matched_at = new Date(); // eslint-disable-line camelcase
|
||||
var update = {};
|
||||
update["services." + match.service] = match;
|
||||
req.db.matches.update({_id: item.service + "$$" + item.id}, {"$set": update});
|
||||
});
|
||||
});
|
||||
return req.db.matches.save({_id: item.service + "$$" + item.id, created_at: new Date(), services:matches}).then(function() {
|
||||
return req.db.matches.save({_id: item.service + "$$" + item.id, "created_at": new Date(), services: matches}).then(function() {
|
||||
res.json(item);
|
||||
});
|
||||
}, function(error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue