Restore the ability to match using share urls
This commit is contained in:
parent
38139d77d6
commit
93ae893400
2 changed files with 38 additions and 4 deletions
|
@ -9,8 +9,8 @@
|
|||
"start": "node -r babel-core/register app.js",
|
||||
"test": "mocha --require co-mocha --compilers js:babel-core/register test/**/*.js --timeout=10000",
|
||||
"watch": "parallelshell \"npm run watch-js\" \"npm run watch-server\"",
|
||||
"watch-js": "babel --modules system -wd public/views views",
|
||||
"watch-server": "nodemon -x \"node -r babel-core/register\" -e js,jsx -i public/ app.js"
|
||||
"watch-js": "babel -wd public/views views",
|
||||
"watch-server": "nodemon -x \"node -r babel-core/register\" -e js,jsx -i public/ -i chrome/ app.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^5.0.0",
|
||||
|
|
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||
import createHandler from '../lib/react-handler';
|
||||
import { routes } from '../views/app';
|
||||
import services from '../lib/services';
|
||||
import co from 'co';
|
||||
|
||||
function formatAndSort(matches, serviceId) {
|
||||
matches = Object.keys(matches).map(function (key) {return matches[key]; });
|
||||
|
@ -24,9 +25,42 @@ export default function* (serviceId, type, itemId, format, next) {
|
|||
return yield next;
|
||||
}
|
||||
|
||||
const doc = yield this.db.matches.findOne({_id: serviceId + '$$' + itemId});
|
||||
let doc = yield this.db.matches.findOne({_id: serviceId + '$$' + itemId});
|
||||
if (!doc) {
|
||||
const item = yield matchedService.lookupId(itemId, type);
|
||||
this.assert(item.id, 404);
|
||||
item.matched_at = new Date(); // eslint-disable-line camelcase
|
||||
const matches = {};
|
||||
matches[item.service] = item;
|
||||
|
||||
this.assert(doc, 404, 'Not Found');
|
||||
for (let service of services) {
|
||||
if (service.id === item.service) {
|
||||
continue;
|
||||
}
|
||||
matches[service.id] = {service: service.id};
|
||||
}
|
||||
doc = {_id: item.service + '$$' + item.id, 'created_at': new Date(), services: matches};
|
||||
yield this.db.matches.save(doc);
|
||||
process.nextTick(() => {
|
||||
for (let service of services) {
|
||||
console.log(service.id);
|
||||
if (service.id === item.service) {
|
||||
continue;
|
||||
}
|
||||
matches[service.id] = {service: service.id};
|
||||
co(function* (){
|
||||
const match = yield service.search(item);
|
||||
console.log(match.id);
|
||||
match.matched_at = new Date(); // eslint-disable-line camelcase
|
||||
const update = {};
|
||||
update['services.' + match.service] = match;
|
||||
yield this.db.matches.updateOne({_id: item.service + '$$' + item.id}, {'$set': update});
|
||||
}.bind(this)).catch((err) => {
|
||||
debug(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const shares = formatAndSort(doc.services, serviceId);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue