Code cleanup
This commit is contained in:
parent
a74ccfa575
commit
be00516521
18 changed files with 209 additions and 202 deletions
93
app.js
93
app.js
|
@ -1,90 +1,91 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var express = require('express');
|
var express = require("express");
|
||||||
var helmet = require('helmet');
|
var helmet = require("helmet");
|
||||||
var path = require('path');
|
var path = require("path");
|
||||||
var favicon = require('serve-favicon');
|
var favicon = require("serve-favicon");
|
||||||
var logger = require('morgan');
|
var logger = require("morgan");
|
||||||
var session = require('express-session');
|
var session = require("express-session");
|
||||||
var cookieParser = require('cookie-parser');
|
var cookieParser = require("cookie-parser");
|
||||||
var flash = require('connect-flash');
|
var flash = require("connect-flash");
|
||||||
var compress = require('compression');
|
var compress = require("compression");
|
||||||
var bodyParser = require('body-parser');
|
var bodyParser = require("body-parser");
|
||||||
var pmongo = require('promised-mongo');
|
var pmongo = require("promised-mongo");
|
||||||
|
|
||||||
var index = require('./routes/index');
|
var index = require("./routes/index");
|
||||||
var search = require('./routes/search');
|
var search = require("./routes/search");
|
||||||
var share = require('./routes/share');
|
var share = require("./routes/share");
|
||||||
var itunesProxy = require('./routes/itunes-proxy');
|
var itunesProxy = require("./routes/itunes-proxy");
|
||||||
|
|
||||||
var React = require('react');
|
var React = require("react");
|
||||||
var nodejsx = require('node-jsx').install({extension: '.jsx'});
|
require("node-jsx").install({extension: ".jsx"});
|
||||||
var ErrorView = React.createFactory(require('./views/error.jsx'));
|
|
||||||
|
|
||||||
var browserify = require('connect-browserify');
|
var ErrorView = React.createFactory(require("./views/error.jsx"));
|
||||||
|
|
||||||
|
var browserify = require("connect-browserify");
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
var development = process.env.NODE_ENV !== 'production';
|
var development = process.env.NODE_ENV !== "production";
|
||||||
|
|
||||||
// view engine setup
|
// view engine setup
|
||||||
app.set('views', path.join(__dirname, 'views'));
|
app.set("views", path.join(__dirname, "views"));
|
||||||
app.set('view engine', 'ejs');
|
app.set("view engine", "ejs");
|
||||||
|
|
||||||
app.use(compress());
|
app.use(compress());
|
||||||
app.use(favicon(__dirname + '/public/images/favicon.png'));
|
app.use(favicon(path.join(__dirname, "/public/images/favicon.png")));
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
app.use(logger('dev'));
|
app.use(logger("dev"));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(bodyParser.urlencoded({ extended: false }));
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(session({
|
app.use(session({
|
||||||
secret: 'keyboard catz',
|
secret: "keyboard catz",
|
||||||
resave: false,
|
resave: false,
|
||||||
saveUninitialized: true
|
saveUninitialized: true
|
||||||
}));
|
}));
|
||||||
app.use(flash());
|
app.use(flash());
|
||||||
app.use(express.static(path.join(__dirname, 'public')));
|
app.use(express.static(path.join(__dirname, "public")));
|
||||||
|
|
||||||
var dbUrl = process.env.MONGOHQ_URL || "mongodb://localhost/match-audio";
|
var dbUrl = process.env.MONGOHQ_URL || "mongodb://localhost/match-audio";
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
req.db = res.db = pmongo(dbUrl, ['matches']);
|
req.db = res.db = pmongo(dbUrl, ["matches"]);
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (development) {
|
if (development) {
|
||||||
app.get('/javascript/bundle.js',
|
app.get("/javascript/bundle.js",
|
||||||
browserify('./views/app.jsx', {
|
browserify("./views/app.jsx", {
|
||||||
debug: true,
|
debug: true,
|
||||||
watch: true
|
watch: true
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('*', function(req,res,next) {
|
app.get("*", function(req, res, next) {
|
||||||
// force SSL
|
// force SSL
|
||||||
if (req.headers['cf-visitor'] && req.headers['cf-visitor'] != '{"scheme":"https"}') {
|
if (req.headers["cf-visitor"] && req.headers["cf-visitor"] !== "{\"scheme\":\"https\"}") {
|
||||||
return res.redirect("https://" + req.headers.host + req.url);
|
return res.redirect("https://" + req.headers.host + req.url);
|
||||||
} else if (req.headers['cf-visitor']) {
|
} else if (req.headers["cf-visitor"]) {
|
||||||
req.userProtocol = "https";
|
req.userProtocol = "https";
|
||||||
} else {
|
} else {
|
||||||
req.userProtocol = "http";
|
req.userProtocol = "http";
|
||||||
}
|
}
|
||||||
// redirect www
|
// redirect www
|
||||||
if (req.headers.host.match(/^www/) !== null ) {
|
if (req.headers.host.match(/^www/) !== null ) {
|
||||||
return res.redirect(req.userProtocol + '://' + req.headers.host.replace(/^www\./, '') + req.url);
|
return res.redirect(req.userProtocol + "://" + req.headers.host.replace(/^www\./, "") + req.url);
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/', index);
|
app.get("/", index);
|
||||||
app.post('/search', search);
|
app.post("/search", search);
|
||||||
app.get('/:service/:type/:id.:format?', share);
|
app.get("/:service/:type/:id.:format?", share);
|
||||||
app.get('/itunes/*', itunesProxy);
|
app.get("/itunes/*", itunesProxy);
|
||||||
app.get('/recent', function(req, res, next) {
|
app.get("/recent", function(req, res, next) {
|
||||||
req.db.matches.find().sort({created_at:-1}).limit(6).toArray().then(function(docs){
|
req.db.matches.find().sort({"created_at": -1}).limit(6).toArray().then(function(docs){
|
||||||
var recents = [];
|
var recents = [];
|
||||||
docs.forEach(function(doc) {
|
docs.forEach(function(doc) {
|
||||||
recents.push(doc.services[doc._id.split("$$")[0]]);
|
recents.push(doc.services[doc._id.split("$$")[0]]); // eslint-disable-line no-underscore-dangle
|
||||||
});
|
});
|
||||||
res.json({recents: recents});
|
res.json({recents: recents});
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
|
@ -94,7 +95,7 @@ app.get('/recent', function(req, res, next) {
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
var err = new Error('Not Found');
|
var err = new Error("Not Found");
|
||||||
err.status = 404;
|
err.status = 404;
|
||||||
next(err);
|
next(err);
|
||||||
});
|
});
|
||||||
|
@ -103,23 +104,23 @@ app.use(function(req, res, next) {
|
||||||
|
|
||||||
// development error handler
|
// development error handler
|
||||||
// will print stacktrace
|
// will print stacktrace
|
||||||
if (app.get('env') === 'development') {
|
if (app.get("env") === "development") {
|
||||||
app.use(function(err, req, res, next) {
|
app.use(function(err, req, res) {
|
||||||
console.log(err.stack);
|
console.log(err.stack);
|
||||||
res.status(err.status || 500);
|
res.status(err.status || 500);
|
||||||
|
|
||||||
var content = React.renderToString(new ErrorView({status: err.status || 500, message: err.message, error: err}));
|
var content = React.renderToString(new ErrorView({status: err.status || 500, message: err.message, error: err}));
|
||||||
res.send('<!doctype html>\n' + content);
|
res.send("<!doctype html>\n" + content);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// production error handler
|
// production error handler
|
||||||
// no stacktraces leaked to user
|
// no stacktraces leaked to user
|
||||||
app.use(function(err, req, res, next) {
|
app.use(function(err, req, res) {
|
||||||
res.status(err.status || 500);
|
res.status(err.status || 500);
|
||||||
|
|
||||||
var content = React.renderToString(new ErrorView({status: err.status || 500, message: err.message, error: {status: err.status || 500}}));
|
var content = React.renderToString(new ErrorView({status: err.status || 500, message: err.message, error: {status: err.status || 500}}));
|
||||||
res.send('<!doctype html>\n' + content);
|
res.send("<!doctype html>\n" + content);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
2
bin/www
2
bin/www
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
"use strict";
|
"use strict";
|
||||||
var debug = require('debug')('unify.audio');
|
var debug = require('debug')('match.audio');
|
||||||
var app = require('../app');
|
var app = require('../app');
|
||||||
|
|
||||||
app.set('port', process.env.PORT || 3000);
|
app.set('port', process.env.PORT || 3000);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var path = require('path');
|
var path = require("path");
|
||||||
|
|
||||||
var services = [];
|
var services = [];
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var path = require('path');
|
var path = require("path");
|
||||||
var Promise = require("bluebird");
|
|
||||||
|
|
||||||
module.exports = [];
|
module.exports = [];
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var parse = require('url').parse;
|
var parse = require("url").parse;
|
||||||
var Promise = require('bluebird');
|
var request = require("superagent");
|
||||||
var request = require('superagent');
|
require("superagent-bluebird-promise");
|
||||||
require('superagent-bluebird-promise');
|
|
||||||
|
|
||||||
module.exports.id = "beats";
|
module.exports.id = "beats";
|
||||||
|
|
||||||
|
@ -29,10 +28,10 @@ module.exports.parseUrl = function(url) {
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Url does not match");
|
throw new Error("Url does not match");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports.lookupId = function(id, type) {
|
module.exports.lookupId = function(id, type) {
|
||||||
if (type == "album") {
|
if (type === "album") {
|
||||||
return request.get(apiRoot + "/albums/" + id + "/images/default?size=large&client_id=" + credentials.key).redirects(0).promise().then(function(res) {
|
return request.get(apiRoot + "/albums/" + id + "/images/default?size=large&client_id=" + credentials.key).redirects(0).promise().then(function(res) {
|
||||||
var artwork = {large: res.headers.location.replace("http:", "https:")};
|
var artwork = {large: res.headers.location.replace("http:", "https:")};
|
||||||
return request.get(apiRoot + "/albums/" + id + "/images/default?client_id=" + credentials.key).redirects(0).promise().then(function(res) {
|
return request.get(apiRoot + "/albums/" + id + "/images/default?client_id=" + credentials.key).redirects(0).promise().then(function(res) {
|
||||||
|
@ -59,7 +58,7 @@ module.exports.lookupId = function(id, type) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if (type == "track") {
|
} else if (type === "track") {
|
||||||
return request.get(apiRoot + "/tracks/" + id + "?client_id=" + credentials.key).promise().then(function(res) {
|
return request.get(apiRoot + "/tracks/" + id + "?client_id=" + credentials.key).promise().then(function(res) {
|
||||||
if (!res.body.data) {
|
if (!res.body.data) {
|
||||||
var error = new Error("Not Found");
|
var error = new Error("Not Found");
|
||||||
|
@ -99,16 +98,20 @@ module.exports.lookupId = function(id, type) {
|
||||||
module.exports.search = function(data) {
|
module.exports.search = function(data) {
|
||||||
var cleanParam = function(str) {
|
var cleanParam = function(str) {
|
||||||
return str.replace(/[\:\?\&]+/, "");
|
return str.replace(/[\:\?\&]+/, "");
|
||||||
}
|
};
|
||||||
var query, album;
|
var query, album;
|
||||||
var type = data.type;
|
var type = data.type;
|
||||||
|
|
||||||
if (type == "album") {
|
if (type === "album") {
|
||||||
query = '"' + cleanParam(data.artist.name) + '" "' + cleanParam(data.name) + '"';
|
query = "'" + cleanParam(data.artist.name) + "' '" + cleanParam(data.name) + "'";
|
||||||
album = data.name;
|
album = data.name;
|
||||||
} else if (type == "track") {
|
} else if (type === "track") {
|
||||||
query = '"' + cleanParam(data.artist.name) + '" "' + cleanParam(data.name) + '"';
|
query = "'" + cleanParam(data.artist.name) + "' '" + cleanParam(data.name) + "'";
|
||||||
album = data.album.name
|
if (data.album) {
|
||||||
|
album = data.album.name;
|
||||||
|
} else {
|
||||||
|
album = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = "/search?q=" + encodeURIComponent(query) + "&type=" + type + "&client_id=" + credentials.key;
|
var path = "/search?q=" + encodeURIComponent(query) + "&type=" + type + "&client_id=" + credentials.key;
|
||||||
|
@ -118,7 +121,7 @@ module.exports.search = function(data) {
|
||||||
return {service: "beats"};
|
return {service: "beats"};
|
||||||
} else {
|
} else {
|
||||||
var found;
|
var found;
|
||||||
var choppedAlbum = data.type == "album" ? cleanParam(data.name) : cleanParam(data.album.name);
|
var choppedAlbum = data.type === "album" ? cleanParam(data.name) : cleanParam(data.album.name);
|
||||||
var choppedArtist = cleanParam(data.artist.name);
|
var choppedArtist = cleanParam(data.artist.name);
|
||||||
|
|
||||||
res.body.data.forEach(function(item) {
|
res.body.data.forEach(function(item) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var parse = require('url').parse;
|
var parse = require("url").parse;
|
||||||
|
|
||||||
module.exports.match = function(url) {
|
module.exports.match = function(url) {
|
||||||
var parsed = parse(url);
|
var parsed = parse(url);
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var React = require('react');
|
var React = require("react");
|
||||||
var nodejsx = require('node-jsx').install({extension: '.jsx'});
|
var Router = require("react-router");
|
||||||
var Router = require('react-router');
|
require("node-jsx").install({extension: ".jsx"});
|
||||||
var routes = require('../views/app.jsx').routes;
|
var routes = require("../views/app.jsx").routes;
|
||||||
|
|
||||||
module.exports = function(req, res, next) {
|
module.exports = function(req, res, next) {
|
||||||
|
|
||||||
req.db.matches.find().sort({created_at:-1}).limit(6).toArray().then(function(docs){
|
req.db.matches.find().sort({"created_at": -1}).limit(6).toArray().then(function(docs){
|
||||||
var recents = [];
|
var recents = [];
|
||||||
docs.forEach(function(doc) {
|
docs.forEach(function(doc) {
|
||||||
var shares = Object.keys(doc.services).map(function (key) {return doc.services[key]});
|
var shares = Object.keys(doc.services).map(function (key) {return doc.services[key]; });
|
||||||
shares.some(function(item) {
|
shares.some(function(item) {
|
||||||
if (item.service == doc._id.split("$$")[0]) {
|
if (item.service === doc._id.split("$$")[0]) { // eslint-disable-line no-underscore-dangle
|
||||||
recents.push(item);
|
recents.push(item);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ module.exports = function(req, res, next) {
|
||||||
Router.run(routes, req.url, function (Handler) {
|
Router.run(routes, req.url, function (Handler) {
|
||||||
var App = React.createFactory(Handler);
|
var App = React.createFactory(Handler);
|
||||||
var content = React.renderToString(new App({recents: recents}));
|
var content = React.renderToString(new App({recents: recents}));
|
||||||
res.send('<!doctype html>\n' + content.replace("</body></html>", "<script>var recents = " + JSON.stringify(recents) + "</script></body></html>"));
|
res.send("<!doctype html>\n" + content.replace("</body></html>", "<script>var recents = " + JSON.stringify(recents) + "</script></body></html>"));
|
||||||
});
|
});
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
next(error);
|
next(error);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var parse = require('url').parse;
|
var parse = require("url").parse;
|
||||||
var request = require('superagent');
|
var request = require("superagent");
|
||||||
|
|
||||||
module.exports = function(req, res) {
|
module.exports = function(req, res) {
|
||||||
var url = "http://" + req.url.substr(8);
|
var url = "http://" + req.url.substr(8);
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var parse = require('url').parse;
|
var parse = require("url").parse;
|
||||||
var path = require('path');
|
var lookup = require("../lib/lookup");
|
||||||
var lookup = require('../lib/lookup');
|
var services = require("../lib/services");
|
||||||
var services = require('../lib/services');
|
|
||||||
|
|
||||||
module.exports = function(req, res, next) {
|
module.exports = function(req, res) {
|
||||||
var url = parse(req.body.url);
|
var url = parse(req.body.url);
|
||||||
if (!url.host) {
|
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."}});
|
||||||
|
@ -20,22 +19,22 @@ module.exports = function(req, res, next) {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return res.json({error: {message: "No supported music found at that link :("}});
|
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 = {};
|
var matches = {};
|
||||||
matches[item.service] = item;
|
matches[item.service] = item;
|
||||||
services.forEach(function(service) {
|
services.forEach(function(service) {
|
||||||
if (service.id == item.service) {
|
if (service.id === item.service) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
matches[service.id] = {service: service.id};
|
matches[service.id] = {service: service.id};
|
||||||
service.search(item).then(function(match) {
|
service.search(item).then(function(match) {
|
||||||
match.matched_at = new Date();
|
match.matched_at = new Date(); // eslint-disable-line camelcase
|
||||||
var update = {};
|
var update = {};
|
||||||
update["services." + match.service] = match;
|
update["services." + match.service] = match;
|
||||||
req.db.matches.update({_id: item.service + "$$" + item.id}, {"$set": update});
|
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);
|
res.json(item);
|
||||||
});
|
});
|
||||||
}, function(error) {
|
}, function(error) {
|
||||||
|
|
|
@ -1,25 +1,21 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var path = require('path');
|
|
||||||
var Promise = require('bluebird');
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var browserify = require('connect-browserify');
|
var React = require("react");
|
||||||
var React = require('react');
|
var Router = require("react-router");
|
||||||
var Router = require('react-router');
|
require("node-jsx").install();
|
||||||
var nodejsx = require('node-jsx').install();
|
var routes = require("../views/app.jsx").routes;
|
||||||
var routes = require('../views/app.jsx').routes;
|
|
||||||
|
|
||||||
var services = require('../lib/services');
|
var services = require("../lib/services");
|
||||||
|
|
||||||
var formatAndSort = function(matches, serviceId) {
|
var formatAndSort = function(matches, serviceId) {
|
||||||
matches = Object.keys(matches).map(function (key) {return matches[key]});
|
matches = Object.keys(matches).map(function (key) {return matches[key]; });
|
||||||
matches.sort(function(a, b) {
|
matches.sort(function(a, b) {
|
||||||
return a.id && !b.id;
|
return a.id && !b.id;
|
||||||
}).sort(function(a, b) {
|
}).sort(function(a) {
|
||||||
return a.service != serviceId;
|
return a.service !== serviceId;
|
||||||
});
|
});
|
||||||
return matches;
|
return matches;
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = function(req, res, next) {
|
module.exports = function(req, res, next) {
|
||||||
var serviceId = req.params.service;
|
var serviceId = req.params.service;
|
||||||
|
@ -28,11 +24,11 @@ module.exports = function(req, res, next) {
|
||||||
|
|
||||||
var matchedService;
|
var matchedService;
|
||||||
services.some(function(service) {
|
services.some(function(service) {
|
||||||
matchedService = serviceId == service.id ? service : null;
|
matchedService = serviceId === service.id ? service : null;
|
||||||
return matchedService;
|
return matchedService;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!matchedService || (type != "album" && type != "track")) {
|
if (!matchedService || (type !== "album" && type !== "track")) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,38 +36,38 @@ module.exports = function(req, res, next) {
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
return matchedService.lookupId(itemId, type).then(function(item) {
|
return matchedService.lookupId(itemId, type).then(function(item) {
|
||||||
var matches = {};
|
var matches = {};
|
||||||
item.matched_at = new Date();
|
item.matched_at = new Date(); // eslint-disable-line camelcase
|
||||||
matches[item.service] = item;
|
matches[item.service] = item;
|
||||||
services.forEach(function(service) {
|
services.forEach(function(service) {
|
||||||
if (service.id == item.service) {
|
if (service.id === item.service) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
matches[service.id] = {service: service.id};
|
matches[service.id] = {service: service.id};
|
||||||
service.search(item).then(function(match) {
|
service.search(item).then(function(match) {
|
||||||
match.matched_at = new Date();
|
match.matched_at = new Date(); // eslint-disable-line camelcase
|
||||||
var update = {};
|
var update = {};
|
||||||
update["services." + match.service] = match;
|
update["services." + match.service] = match;
|
||||||
req.db.matches.update({_id: item.service + "$$" + item.id}, {"$set": update});
|
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() {
|
||||||
var shares = formatAndSort(matches, serviceId);
|
var newShares = formatAndSort(matches, serviceId);
|
||||||
Router.run(routes, req.url, function (Handler) {
|
Router.run(routes, req.url, function (Handler) {
|
||||||
var App = React.createFactory(Handler);
|
var App = React.createFactory(Handler);
|
||||||
var content = React.renderToString(new App({shares: shares}));
|
var content = React.renderToString(new App({shares: newShares}));
|
||||||
res.send('<!doctype html>\n' + content.replace("</body></html>", "<script>var shares = " + JSON.stringify(shares) + "</script></body></html>"));
|
res.send("<!doctype html>\n" + content.replace("</body></html>", "<script>var shares = " + JSON.stringify(newShares) + "</script></body></html>"));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
|
||||||
}
|
}
|
||||||
var shares = formatAndSort(doc.services, serviceId);
|
var shares = formatAndSort(doc.services, serviceId);
|
||||||
if (req.params.format == "json") {
|
if (req.params.format === "json") {
|
||||||
return res.json({shares: shares});
|
return res.json({shares: shares});
|
||||||
}
|
}
|
||||||
Router.run(routes, req.url, function (Handler) {
|
Router.run(routes, req.url, function (Handler) {
|
||||||
var App = React.createFactory(Handler);
|
var App = React.createFactory(Handler);
|
||||||
var content = React.renderToString(new App({shares: shares}));
|
var content = React.renderToString(new App({shares: shares}));
|
||||||
res.send('<!doctype html>\n' + content.replace("</body></html>", "<script>var shares = " + JSON.stringify(shares) + "</script></body></html>"));
|
res.send("<!doctype html>\n" + content.replace("</body></html>", "<script>var shares = " + JSON.stringify(shares) + "</script></body></html>"));
|
||||||
});
|
});
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
return next(error);
|
return next(error);
|
||||||
|
|
11
views/.eslintrc
Normal file
11
views/.eslintrc
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"jsx": true
|
||||||
|
},
|
||||||
|
"plugins": [
|
||||||
|
"react"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"browser": true
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,23 +1,19 @@
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var request = require('superagent');
|
var React = require("react");
|
||||||
var React = require('react');
|
var Router = require("react-router");
|
||||||
var Router = require('react-router');
|
var Route = require("react-router").Route;
|
||||||
var Route = require('react-router').Route;
|
var DefaultRoute = require("react-router").DefaultRoute;
|
||||||
var DefaultRoute = require('react-router').DefaultRoute;
|
var NotFoundRoute = require("react-router").NotFoundRoute;
|
||||||
var NotFoundRoute = require('react-router').NotFoundRoute;
|
var RouteHandler = require("react-router").RouteHandler;
|
||||||
var RouteHandler = require('react-router').RouteHandler;
|
var Home = require("./home.jsx");
|
||||||
var Home = require('./home.jsx');
|
var Share = require("./share.jsx");
|
||||||
var Share = require('./share.jsx');
|
var Head = require("./head.jsx");
|
||||||
var Error = require('./error.jsx');
|
var ga = require("react-google-analytics");
|
||||||
var Head = require('./head.jsx');
|
|
||||||
var ga = require('react-google-analytics');
|
|
||||||
var GAInitiailizer = ga.Initializer;
|
var GAInitiailizer = ga.Initializer;
|
||||||
|
|
||||||
var App = React.createClass({
|
var App = React.createClass({
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<Head {...this.props} />
|
<Head {...this.props} />
|
||||||
|
@ -47,16 +43,16 @@ var routes = (
|
||||||
|
|
||||||
module.exports.routes = routes;
|
module.exports.routes = routes;
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== "undefined") {
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
Router.run(routes, Router.HistoryLocation, function (Handler) {
|
Router.run(routes, Router.HistoryLocation, function (Handler) {
|
||||||
if (typeof recents !== "undefined") {
|
if (typeof window.recents !== "undefined") {
|
||||||
React.render(<Handler recents={recents} />, document);
|
React.render(<Handler recents={window.recents} />, document);
|
||||||
} else if (typeof shares !== "undefined") {
|
} else if (typeof shares !== "undefined") {
|
||||||
React.render(<Handler shares={shares} />, document);
|
React.render(<Handler shares={window.shares} />, document);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ga('create', 'UA-66209-8', 'auto');
|
ga("create", "UA-66209-8", "auto");
|
||||||
ga('send', 'pageview');
|
ga("send", "pageview");
|
||||||
}
|
};
|
||||||
}
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var React = require('react');
|
var React = require("react");
|
||||||
var Head = require('./head.jsx');
|
var Head = require("./head.jsx");
|
||||||
var Foot = require('./foot.jsx');
|
var Foot = require("./foot.jsx");
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var React = require('react');
|
var React = require("react");
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var React = require('react');
|
var React = require("react");
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ module.exports = React.createClass({
|
||||||
<footer>
|
<footer>
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className={this.props.page == "home" || this.props.page == "error" ? "col-md-6 col-md-offset-3" : "col-md-12"}>
|
<div className={this.props.page === "home" || this.props.page === "error" ? "col-md-6 col-md-offset-3" : "col-md-12"}>
|
||||||
<a href="https://twitter.com/MatchAudio">Tweet</a> or <a href="https://github.com/kudos/match.audio">Fork</a>. A work in progress by <a href="http://crem.in">this guy</a>.
|
<a href="https://twitter.com/MatchAudio">Tweet</a> or <a href="https://github.com/kudos/match.audio">Fork</a>. A work in progress by <a href="http://crem.in">this guy</a>.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var React = require('react');
|
var React = require("react");
|
||||||
var Router = require('react-router');
|
var Router = require("react-router");
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
|
|
||||||
mixins: [ Router.State ],
|
mixins: [ Router.State ],
|
||||||
|
contextTypes: {
|
||||||
|
router: React.PropTypes.func.isRequired
|
||||||
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var image = this.props.shares ? this.props.shares[0].artwork.large : "https://match.audio/images/logo-512.png";
|
var image = this.props.shares ? this.props.shares[0].artwork.large : "https://match.audio/images/logo-512.png";
|
||||||
var title = this.props.shares ? this.props.shares[0].name + " by " + this.props.shares[0].artist.name : "Match Audio";
|
var title = this.props.shares ? this.props.shares[0].name + " by " + this.props.shares[0].artist.name : "Match Audio";
|
||||||
|
@ -27,7 +29,7 @@ module.exports = React.createClass({
|
||||||
<meta property="og:url" content={shareUrl} />
|
<meta property="og:url" content={shareUrl} />
|
||||||
<link rel="shortcut icon" href="/images/favicon.png" />
|
<link rel="shortcut icon" href="/images/favicon.png" />
|
||||||
<link rel="icon" sizes="512x512" href="/images/logo-128.png" />
|
<link rel="icon" sizes="512x512" href="/images/logo-128.png" />
|
||||||
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,700' rel='stylesheet' type='text/css' />
|
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,700" rel="stylesheet" type="text/css" />
|
||||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
|
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
|
||||||
<link rel="stylesheet" href="/stylesheets/style.css" />
|
<link rel="stylesheet" href="/stylesheets/style.css" />
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var React = require('react');
|
var React = require("react");
|
||||||
var request = require('superagent');
|
var request = require("superagent");
|
||||||
var Router = require('react-router');
|
var Router = require("react-router");
|
||||||
var Link = require('react-router').Link;
|
var Link = require("react-router").Link;
|
||||||
var Faq = require('./faq.jsx');
|
var Faq = require("./faq.jsx");
|
||||||
var Foot = require('./foot.jsx');
|
var Foot = require("./foot.jsx");
|
||||||
|
|
||||||
var Recent = React.createClass({
|
var Recent = React.createClass({
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ var RecentItem = React.createClass({
|
||||||
return (
|
return (
|
||||||
<div className="col-sm-4 col-xs-6">
|
<div className="col-sm-4 col-xs-6">
|
||||||
<Link to="share" params={this.props.item}>
|
<Link to="share" params={this.props.item}>
|
||||||
<div className={this.props.item.service == "youtube" ? "artwork-youtube artwork" : "artwork"} style={{backgroundImage: "url("+this.props.item.artwork.small+")"}}></div>
|
<div className={this.props.item.service === "youtube" ? "artwork-youtube artwork" : "artwork"} style={{backgroundImage: "url(" + this.props.item.artwork.small + ")"}}></div>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -65,7 +65,7 @@ var SearchForm = React.createClass({
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
request.post('/search').send({url:url}).end(function(res) {
|
request.post("/search").send({url: url}).end(function(res) {
|
||||||
that.setState({
|
that.setState({
|
||||||
submitting: false
|
submitting: false
|
||||||
});
|
});
|
||||||
|
@ -118,7 +118,7 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
componentDidMount: function () {
|
componentDidMount: function () {
|
||||||
if (!this.props.recents) {
|
if (!this.props.recents) {
|
||||||
request.get('/recent').set('Accept', 'application/json').end(function(res) {
|
request.get("/recent").set("Accept", "application/json").end(function(res) {
|
||||||
this.setState({
|
this.setState({
|
||||||
recents: res.body.recents
|
recents: res.body.recents
|
||||||
});
|
});
|
||||||
|
@ -142,7 +142,7 @@ module.exports = React.createClass({
|
||||||
<div className="row blurb">
|
<div className="row blurb">
|
||||||
<div className="col-md-6 col-md-offset-3">
|
<div className="col-md-6 col-md-offset-3">
|
||||||
<p>Match Audio makes sharing from music services better.
|
<p>Match Audio makes sharing from music services better.
|
||||||
What happens when you share your favourite song on Spotify with a friend, but they don't use Spotify?
|
What happens when you share your favourite song on Spotify with a friend, but they don"t use Spotify?
|
||||||
</p><p>We match album and track links from Youtube, Rdio, Spotify, Deezer, Google Music, Xbox Music, Beats Music, and iTunes and give you back one link with matches we find on all of them.
|
</p><p>We match album and track links from Youtube, Rdio, Spotify, Deezer, Google Music, Xbox Music, Beats Music, and iTunes and give you back one link with matches we find on all of them.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var React = require('react');
|
var React = require("react");
|
||||||
var request = require('superagent');
|
var request = require("superagent");
|
||||||
var Router = require('react-router');
|
var Router = require("react-router");
|
||||||
var Link = require('react-router').Link;
|
var Link = require("react-router").Link;
|
||||||
var Foot = require('./foot.jsx');
|
var Foot = require("./foot.jsx");
|
||||||
|
|
||||||
var MusicItem = React.createClass({
|
var MusicItem = React.createClass({
|
||||||
|
|
||||||
|
@ -41,13 +41,13 @@ var MusicItem = React.createClass({
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<div className="col-md-3 col-xs-6">
|
<div className="col-md-3 col-xs-6">
|
||||||
<div className={"service" + (this.props.inc == 0 ? " source-service" : "")}>
|
<div className={"service" + (this.props.inc === 0 ? " source-service" : "")}>
|
||||||
<div className="matching-from hidden-xs">{this.props.inc == 0 ? "Found matches using this link": ""}</div>
|
<div className="matching-from hidden-xs">{this.props.inc === 0 ? "Found matches using this link" : ""}</div>
|
||||||
<a href={this.props.item.streamUrl || this.props.item.purchaseUrl}>
|
<a href={this.props.item.streamUrl || this.props.item.purchaseUrl}>
|
||||||
<div className={this.props.item.service == "youtube" ? "artwork-youtube artwork" : "artwork"} style={{backgroundImage: "url("+this.props.item.artwork.small+")"}}>
|
<div className={this.props.item.service === "youtube" ? "artwork-youtube artwork" : "artwork"} style={{backgroundImage: "url(" + this.props.item.artwork.small + ")"}}>
|
||||||
</div>
|
</div>
|
||||||
<div className={this.props.item.service == "youtube" && this.props.inc > 0 ? "youtube" : ""}>
|
<div className={this.props.item.service === "youtube" && this.props.inc > 0 ? "youtube" : ""}>
|
||||||
{this.props.item.service == "youtube" && this.props.inc > 0 ? this.props.item.name : ""}
|
{this.props.item.service === "youtube" && this.props.inc > 0 ? this.props.item.name : ""}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<div className="service-link">
|
<div className="service-link">
|
||||||
|
@ -68,7 +68,7 @@ module.exports = React.createClass({
|
||||||
mixins: [ Router.State ],
|
mixins: [ Router.State ],
|
||||||
|
|
||||||
getInitialState: function () {
|
getInitialState: function () {
|
||||||
if (this.props.shares && this.props.shares[0].id == this.getParams().id) {
|
if (this.props.shares && this.props.shares[0].id === this.getParams().id) {
|
||||||
return {
|
return {
|
||||||
name: this.props.shares[0].name,
|
name: this.props.shares[0].name,
|
||||||
artist: this.props.shares[0].artist.name,
|
artist: this.props.shares[0].artist.name,
|
||||||
|
@ -122,7 +122,7 @@ module.exports = React.createClass({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this)
|
}.bind(this);
|
||||||
|
|
||||||
if (!this.state.shares.length) {
|
if (!this.state.shares.length) {
|
||||||
getShares();
|
getShares();
|
||||||
|
@ -133,7 +133,7 @@ module.exports = React.createClass({
|
||||||
if (!complete) {
|
if (!complete) {
|
||||||
getShares();
|
getShares();
|
||||||
}
|
}
|
||||||
}.bind(this), 2000);
|
}, 2000);
|
||||||
|
|
||||||
// Some hacks to pop open the Twitter/Facebook/Google Plus sharing dialogs without using their code.
|
// Some hacks to pop open the Twitter/Facebook/Google Plus sharing dialogs without using their code.
|
||||||
Array.prototype.forEach.call(document.querySelectorAll(".share-dialog"), function(dialog){
|
Array.prototype.forEach.call(document.querySelectorAll(".share-dialog"), function(dialog){
|
||||||
|
@ -141,15 +141,15 @@ module.exports = React.createClass({
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var w = 845;
|
var w = 845;
|
||||||
var h = 670;
|
var h = 670;
|
||||||
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
|
var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;
|
||||||
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
|
var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;
|
||||||
|
|
||||||
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
|
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
|
||||||
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
|
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
|
||||||
|
|
||||||
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
|
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
|
||||||
var top = ((height / 2) - (h / 2)) + dualScreenTop;
|
var top = ((height / 2) - (h / 2)) + dualScreenTop;
|
||||||
var newWindow = window.open(dialog.href, "Share Music", 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
|
var newWindow = window.open(dialog.href, "Share Music", "scrollbars=yes, width=" + w + ", height=" + h + ", top=" + top + ", left=" + left);
|
||||||
if (window.focus) {
|
if (window.focus) {
|
||||||
newWindow.focus();
|
newWindow.focus();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue