combine.fm/routes/index.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

import debuglog from 'debug';
2014-12-15 12:49:17 +00:00
import services from '../lib/services';
import render from '../lib/render';
import models from '../models';
2017-10-23 17:58:23 +01:00
const debug = debuglog('combinefm:share');
2015-06-03 21:45:54 -07:00
const recentQuery = {
include: [
{ model: models.artist },
{ model: models.match },
],
limit: 6,
order: [
['updatedAt', 'DESC'],
],
2015-05-17 19:10:30 +01:00
};
export default function* () {
const recentAlbums = yield models.album.findAll(recentQuery);
const recentTracks = yield models.track.findAll(recentQuery);
const initialState = {
recents: recentAlbums.map(album => album.toJSON())
.concat(recentTracks.map(track => track.toJSON()))
.sort((a, b) => a.createdAt < b.createdAt).slice(0, 6),
services: services.map(service => service.id),
};
const url = '/';
const html = yield render(url, initialState);
const head = {
2016-10-23 23:04:32 +01:00
title: 'Share Music',
shareUrl: `${this.request.origin}${url}`,
image: `${this.request.origin}/assets/images/logo-512.png`,
2016-10-24 00:18:36 +01:00
share: false,
2016-10-23 23:04:32 +01:00
};
2017-05-26 19:47:17 +01:00
this.set('Cache-Control', 'no-cache');
yield this.render('index', {
initialState,
head,
html,
});
}