Add in process-caching, example links
This commit is contained in:
parent
a401a0a351
commit
69c60a078e
4 changed files with 19 additions and 4 deletions
7
app.js
7
app.js
|
@ -44,7 +44,12 @@ app.get('*', function(req,res,next) {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/', function(req, res) {
|
app.get('/', function(req, res) {
|
||||||
res.render('index', { error: req.flash('search-error') });
|
var samples = [
|
||||||
|
{artist: "Aesop Rock", album: "None Shall Pass", url: '/google/album/Bpnz47tzvmp3p46ht3syerwyvva'},
|
||||||
|
{artist: "Hozier", album: "self-titled album", url: '/google/album/Bd3mxcy3otokg4yc45qktq7l35q'},
|
||||||
|
{artist: "Daft Punk", album: "Discovery", url: '/google/album/B4t6yqqvhnb2hy4st4uisjrcsrm'}
|
||||||
|
];
|
||||||
|
res.render('index', { samples: samples, error: req.flash('search-error') });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/search', search);
|
app.post('/search', search);
|
||||||
|
|
|
@ -73,6 +73,7 @@ module.exports.search = function(data) {
|
||||||
|
|
||||||
if (!data[type + "s"].items[0]) {
|
if (!data[type + "s"].items[0]) {
|
||||||
deferred.resolve({service:"spotify"});
|
deferred.resolve({service:"spotify"});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var item = data[type + "s"].items[0];
|
var item = data[type + "s"].items[0];
|
||||||
|
|
|
@ -4,10 +4,13 @@ var Q = require('q');
|
||||||
|
|
||||||
var services = {};
|
var services = {};
|
||||||
|
|
||||||
|
var cache = {};
|
||||||
|
|
||||||
require("fs").readdirSync(path.join(__dirname, "..", "lib", "services")).forEach(function(file) {
|
require("fs").readdirSync(path.join(__dirname, "..", "lib", "services")).forEach(function(file) {
|
||||||
var service = require("../lib/services/" + file);
|
var service = require("../lib/services/" + file);
|
||||||
if (service.search) {
|
if (service.search) {
|
||||||
services[service.id] = service;
|
services[service.id] = service;
|
||||||
|
cache[service.id] = {};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -17,6 +20,11 @@ module.exports = function(req, res) {
|
||||||
var itemId = req.params.id;
|
var itemId = req.params.id;
|
||||||
var promises = [];
|
var promises = [];
|
||||||
|
|
||||||
|
if (cache[serviceId][type + "-" + itemId]) {
|
||||||
|
res.render(type, {items: cache[serviceId][type + "-" + itemId]});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
services[serviceId].lookupId(itemId, type).then(function(item) {
|
services[serviceId].lookupId(itemId, type).then(function(item) {
|
||||||
for (var id in services) {
|
for (var id in services) {
|
||||||
if (id != serviceId) {
|
if (id != serviceId) {
|
||||||
|
@ -38,7 +46,7 @@ module.exports = function(req, res) {
|
||||||
});
|
});
|
||||||
|
|
||||||
items.unshift(item);
|
items.unshift(item);
|
||||||
|
cache[serviceId][item.type + "-" + item.id] = items;
|
||||||
res.render(type, {items: items});
|
res.render(type, {items: items});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
<form role="form" method="post" action="/search">
|
<form role="form" method="post" action="/search">
|
||||||
<div class="input-group input-group-lg">
|
<div class="input-group input-group-lg">
|
||||||
<input type="text" name="url" placeholder="Paste link here" class="form-control">
|
<input type="text" name="url" placeholder="Paste link here" class="form-control" autofocus>
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<input type="submit" class="btn btn-lg btn-custom" value="Share Music">
|
<input type="submit" class="btn btn-lg btn-custom" value="Share Music">
|
||||||
</span>
|
</span>
|
||||||
|
@ -38,7 +38,8 @@
|
||||||
<div class="col-md-6 col-md-offset-3">
|
<div class="col-md-6 col-md-offset-3">
|
||||||
<p>Make sharing from music services better.
|
<p>Make sharing from music services better.
|
||||||
We match album and track links from Rdio, Spotify, Deezer, Beats Music, Google Music and iTunes and give you back a link with all of them.</p>
|
We match album and track links from Rdio, Spotify, Deezer, Beats Music, Google Music and iTunes and give you back a link with all of them.</p>
|
||||||
<p><a href="/google/album/B3qrtsvk5s3piwyla76sk6qyxny">Here's a sample</a>.</p>
|
<% var sample = samples[Math.floor(Math.random() * samples.length)] %>
|
||||||
|
<p><a href="<%= sample.url %>">Here's an example with <%= sample.artist %>'s <%= sample.album %></a>.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue