Files
RSSHub/lib/v2/spotify/top.js
Outvi V 36b4cc5baa feat(route): add spotify (#8966)
* feat: /spotify/playlist/:id

* feat: /spotify/artist

* feat(spotify/artist): add to radar

* feat: /spotify/saved

* feat: /spotify/top/{tracks,artists}

* feat(spotify): add images for artist and playlist

* docs: /spotify/*

* docs/en: /spotify configurations

* chore(spotify): apiKey/Secret -> clientId/Secret

* fix(spotify/utils): genres can be empty
2022-02-04 18:46:53 +08:00

25 lines
741 B
JavaScript

const utils = require('./utils');
const got = require('@/utils/got');
module.exports = (type) => async (ctx) => {
if (type !== 'tracks' && type !== 'artists') {
throw `Invalid type: ${type}`;
}
const token = await utils.getPrivateToken();
const itemsResponse = await got
.get(`https://api.spotify.com/v1/me/top/${type}`, {
headers: {
Authorization: `Bearer ${token}`,
},
})
.json();
const items = itemsResponse.items;
ctx.state.data = {
title: `Spotify: My Top ${type[0].toUpperCase() + type.slice(1)}`,
allowEmpty: true,
item: type === 'tracks' ? items.map(utils.parseTrack) : items.map(utils.parseArtist),
};
};