combine.fm/routes/index.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

import debuglog from 'debug';
2014-12-15 12:49:17 +00:00
2020-01-18 10:19:20 +00:00
import services from '../lib/services.js';
import render from '../lib/render.js';
import models from '../models/index.cjs';
const debug = debuglog('combine.fm:share');
2015-06-03 21:45:54 -07:00
const recentQuery = {
include: [
{ model: models.artist },
{ model: models.match },
],
2017-11-11 21:29:47 +00:00
limit: 9,
order: [
['updatedAt', 'DESC'],
],
2015-05-17 19:10:30 +01:00
};
2018-04-13 21:44:31 +01:00
export default async function (ctx) {
const recentAlbums = await models.album.findAll(recentQuery);
const recentTracks = await models.track.findAll(recentQuery);
2018-04-13 21:44:31 +01:00
const serviceList = services.map(service => service.id);
const recents = recentAlbums.map(album => album.toJSON())
.concat(recentTracks.map(track => track.toJSON()))
2018-04-13 21:44:31 +01:00
.sort((a, b) => a.createdAt < b.createdAt).slice(0, 9);
const url = '/';
2018-04-13 21:44:31 +01:00
const html = await render(url, { manifest: ctx.manifest, services: serviceList, recents });
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
};
2018-04-13 21:44:31 +01:00
await ctx.render('index', {
initialState: { services: serviceList, recents },
head,
html,
});
}