From 4de9949649b388d60001f35d00a9b17dfa8b18b7 Mon Sep 17 00:00:00 2001 From: gw Date: Sat, 11 Apr 2026 15:16:19 -0500 Subject: [PATCH] fix(spotify): replace broken request-promise with native fetch The request-promise package was pinned to ^0.0.1 (a long-abandoned package whose main field points to a missing lib/tp.js), causing the server to crash at startup when lib/helpers/require-dir.js transitively loaded this file. Switch to Node's built-in fetch and simplify the gratuitous Promise wrapping around auth() and authenticateService(). Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/music_services/spotifyDef.js | 43 ++++++++++++-------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/lib/music_services/spotifyDef.js b/lib/music_services/spotifyDef.js index 85ba833a..5f555e1c 100644 --- a/lib/music_services/spotifyDef.js +++ b/lib/music_services/spotifyDef.js @@ -1,6 +1,5 @@ 'use strict'; -var request = require('request-promise'); const settings = require('../../settings'); var clientId = ""; @@ -72,28 +71,22 @@ const getHeaders = () => { }; }; -const getOptions = (url) => { - return { - url, - headers: getHeaders(), - json: true, - method: 'POST', - form: { - grant_type: 'client_credentials', - }, - }; -}; - const auth = () => { - const options = getOptions(SPOTIFY_TOKEN_URL); - return new Promise((resolve, reject) => { - request(options).then((response) => { - const responseMapped = mapResponse(response); - resolve(responseMapped); - }).catch((err) => { - reject(new Error(`Unable to authenticate Spotify with client id: ${clientId}`)); + return fetch(SPOTIFY_TOKEN_URL, { + method: 'POST', + headers: getHeaders(), + body: new URLSearchParams({ grant_type: 'client_credentials' }).toString(), + }) + .then((res) => { + if (!res.ok) { + throw new Error(`HTTP ${res.status}`); + } + return res.json(); }) - }); + .then(mapResponse) + .catch(() => { + throw new Error(`Unable to authenticate Spotify with client id: ${clientId}`); + }); }; function getTokenHeaders() { @@ -106,12 +99,8 @@ function getTokenHeaders() { } function authenticateService() { - return new Promise((resolve, reject) => { - auth().then((response) => { - const accessToken = response.accessToken; - clientToken = accessToken; - resolve(); - }).catch(reject); + return auth().then((response) => { + clientToken = response.accessToken; }); }