Finally finished giant ES6 refactor
This commit is contained in:
parent
c6d48cc424
commit
03e2666958
39 changed files with 553 additions and 635 deletions
|
@ -1,12 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
import React from 'react';
|
||||
import createHandler from '../lib/react-handler';
|
||||
import {routes} from '../views/app';
|
||||
import { routes } from '../views/app';
|
||||
|
||||
module.exports = function* () {
|
||||
let recents = [];
|
||||
let docs = yield this.db.matches.find().sort({'created_at': -1}).limit(6).toArray();
|
||||
export default function* () {
|
||||
const recents = [];
|
||||
const docs = yield this.db.matches.find().sort({'created_at': -1}).limit(6).toArray();
|
||||
docs.forEach(function(doc) {
|
||||
let shares = Object.keys(doc.services).map(function (key) {return doc.services[key]; });
|
||||
shares.some(function(item) {
|
||||
|
@ -17,9 +15,9 @@ module.exports = function* () {
|
|||
});
|
||||
});
|
||||
|
||||
let Handler = yield createHandler(routes, this.request.url);
|
||||
const Handler = yield createHandler(routes, this.request.url);
|
||||
|
||||
let App = React.createFactory(Handler);
|
||||
const App = React.createFactory(Handler);
|
||||
let content = React.renderToString(new App({recents: recents}));
|
||||
|
||||
content = content.replace('</body></html>', '<script>var recents = ' + JSON.stringify(recents) + '</script></body></html>');
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import {parse} from 'url';
|
||||
import { parse } from 'url';
|
||||
import request from 'superagent';
|
||||
|
||||
module.exports = function* (next) {
|
||||
let url = 'http://' + this.request.url.substr(8);
|
||||
let parsed = parse(url);
|
||||
export default function* (next) {
|
||||
const url = 'http://' + this.request.url.substr(8);
|
||||
const parsed = parse(url);
|
||||
if (parsed.host.match(/mzstatic\.com/)) {
|
||||
let proxyResponse = yield request.get(url);
|
||||
const proxyResponse = yield request.get(url);
|
||||
this.set(proxyResponse.headers);
|
||||
this.body = proxyResponse.body;
|
||||
} else {
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
import {parse} from 'url';
|
||||
import { parse } from 'url';
|
||||
import co from 'co';
|
||||
import lookup from '../lib/lookup';
|
||||
import services from '../lib/services';
|
||||
|
||||
module.exports = function* () {
|
||||
let url = parse(this.request.body.url);
|
||||
const url = parse(this.request.body.url);
|
||||
this.assert(url.host, 400, {error: {message: 'You need to submit a url.'}});
|
||||
|
||||
let item = yield lookup(this.request.body.url);
|
||||
const item = yield lookup(this.request.body.url);
|
||||
|
||||
this.assert(item, 400, {error: {message: 'No supported music found at that link :('}});
|
||||
|
||||
item.matched_at = new Date(); // eslint-disable-line camelcase
|
||||
let matches = {};
|
||||
const matches = {};
|
||||
matches[item.service] = item;
|
||||
|
||||
|
||||
|
@ -32,9 +32,9 @@ module.exports = function* () {
|
|||
continue;
|
||||
}
|
||||
matches[service.id] = {service: service.id};
|
||||
let match = yield service.search(item);
|
||||
const match = yield service.search(item);
|
||||
match.matched_at = new Date(); // eslint-disable-line camelcase
|
||||
let update = {};
|
||||
const update = {};
|
||||
update['services.' + match.service] = match;
|
||||
yield this.db.matches.updateOne({_id: item.service + '$$' + item.id}, {'$set': update});
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import React from 'react';
|
||||
import createHandler from '../lib/react-handler';
|
||||
import {routes} from '../views/app';
|
||||
import { routes } from '../views/app';
|
||||
import services from '../lib/services';
|
||||
|
||||
let formatAndSort = function(matches, serviceId) {
|
||||
function formatAndSort(matches, serviceId) {
|
||||
matches = Object.keys(matches).map(function (key) {return matches[key]; });
|
||||
matches.sort(function(a, b) {
|
||||
return a.id && !b.id;
|
||||
|
@ -13,7 +13,7 @@ let formatAndSort = function(matches, serviceId) {
|
|||
return matches;
|
||||
};
|
||||
|
||||
module.exports = function* (serviceId, type, itemId, format, next) {
|
||||
export default function* (serviceId, type, itemId, format, next) {
|
||||
let matchedService;
|
||||
services.some(function(service) {
|
||||
matchedService = serviceId === service.id ? service : null;
|
||||
|
@ -24,19 +24,18 @@ module.exports = function* (serviceId, type, itemId, format, next) {
|
|||
return yield next;
|
||||
}
|
||||
|
||||
let shares = [];
|
||||
let doc = yield this.db.matches.findOne({_id: serviceId + '$$' + itemId});
|
||||
const doc = yield this.db.matches.findOne({_id: serviceId + '$$' + itemId});
|
||||
|
||||
this.assert(doc, 404, 'Not Found');
|
||||
|
||||
shares = formatAndSort(doc.services, serviceId);
|
||||
const shares = formatAndSort(doc.services, serviceId);
|
||||
|
||||
if (format === 'json') {
|
||||
this.body = {shares: shares};
|
||||
} else {
|
||||
let Handler = yield createHandler(routes, this.request.url);
|
||||
const Handler = yield createHandler(routes, this.request.url);
|
||||
|
||||
let App = React.createFactory(Handler);
|
||||
const App = React.createFactory(Handler);
|
||||
let content = React.renderToString(new App({shares: shares}));
|
||||
|
||||
content = content.replace('</body></html>', '<script>var shares = ' + JSON.stringify(shares) + '</script></body></html>');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue