mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-01 17:48:15 +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
31 lines
942 B
JavaScript
31 lines
942 B
JavaScript
const utils = require('./utils');
|
|
const got = require('@/utils/got');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
|
|
module.exports = async (ctx) => {
|
|
const token = await utils.getPrivateToken();
|
|
|
|
const { limit } = ctx.params;
|
|
const pageSize = !isNaN(parseInt(limit)) ? parseInt(limit) : 50;
|
|
|
|
const itemsResponse = await got
|
|
.get(`https://api.spotify.com/v1/me/tracks?limit=${pageSize}`, {
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
})
|
|
.json();
|
|
const tracks = itemsResponse.items;
|
|
|
|
ctx.state.data = {
|
|
title: 'Spotify: My Saved Tracks',
|
|
link: 'https://open.spotify.com/collection/tracks',
|
|
description: `Latest ${pageSize} saved tracks on Spotify.`,
|
|
allowEmpty: true,
|
|
item: tracks.map((x) => ({
|
|
...utils.parseTrack(x.track),
|
|
pubDate: parseDate(x.added_at),
|
|
})),
|
|
};
|
|
};
|