2016-10-03 13:31:29 +01:00
|
|
|
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';
|
2016-10-03 13:31:29 +01:00
|
|
|
|
2017-10-23 21:05:58 +01:00
|
|
|
const debug = debuglog('combine.fm:share');
|
2015-06-03 21:45:54 -07:00
|
|
|
|
2016-10-03 13:31:29 +01:00
|
|
|
const recentQuery = {
|
|
|
|
include: [
|
|
|
|
{ model: models.artist },
|
|
|
|
{ model: models.match },
|
|
|
|
],
|
2017-11-11 21:29:47 +00:00
|
|
|
limit: 9,
|
2016-10-03 13:31:29 +01:00
|
|
|
order: [
|
|
|
|
['updatedAt', 'DESC'],
|
|
|
|
],
|
2015-05-17 19:10:30 +01:00
|
|
|
};
|
2016-10-03 13:31:29 +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);
|
2016-10-03 13:31:29 +01:00
|
|
|
|
2018-04-13 21:44:31 +01:00
|
|
|
const serviceList = services.map(service => service.id);
|
|
|
|
const recents = recentAlbums.map(album => album.toJSON())
|
2016-10-03 13:31:29 +01:00
|
|
|
.concat(recentTracks.map(track => track.toJSON()))
|
2018-04-13 21:44:31 +01:00
|
|
|
.sort((a, b) => a.createdAt < b.createdAt).slice(0, 9);
|
2016-10-03 13:31:29 +01:00
|
|
|
|
|
|
|
const url = '/';
|
|
|
|
|
2018-04-13 21:44:31 +01:00
|
|
|
const html = await render(url, { manifest: ctx.manifest, services: serviceList, recents });
|
2016-10-03 13:31:29 +01:00
|
|
|
|
|
|
|
const head = {
|
2016-10-23 23:04:32 +01:00
|
|
|
title: 'Share Music',
|
2016-10-03 13:31:29 +01:00
|
|
|
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
|
|
|
};
|
2016-10-03 13:31:29 +01:00
|
|
|
|
2018-04-13 21:44:31 +01:00
|
|
|
await ctx.render('index', {
|
|
|
|
initialState: { services: serviceList, recents },
|
2016-10-03 13:31:29 +01:00
|
|
|
head,
|
|
|
|
html,
|
|
|
|
});
|
|
|
|
}
|