mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 01:58:11 +08:00
* 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
25 lines
741 B
JavaScript
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),
|
|
};
|
|
};
|