diff --git a/plugins/last-fm/back.js b/plugins/last-fm/back.js index 9d735168..7593f1c1 100644 --- a/plugins/last-fm/back.js +++ b/plugins/last-fm/back.js @@ -1,4 +1,4 @@ -const { shell } = require('electron'); +const { shell, net } = require('electron'); const md5 = require('md5'); const { setOptions } = require('../../config/plugins'); @@ -56,7 +56,7 @@ const createToken = async ({ apiKey, apiRoot, secret }) => { format: 'json', }; const apiSigature = createApiSig(data, secret); - let response = await fetch(`${apiRoot}${createQueryString(data, apiSigature)}`); + let response = await net.fetch(`${apiRoot}${createQueryString(data, apiSigature)}`); response = await response.json(); return response?.token; }; @@ -78,7 +78,7 @@ const getAndSetSessionKey = async (config) => { token: config.token, }; const apiSignature = createApiSig(data, config.secret); - let res = await fetch(`${config.api_root}${createQueryString(data, apiSignature)}`); + let res = await net.fetch(`${config.api_root}${createQueryString(data, apiSignature)}`); res = await res.json(); if (res.error) { await authenticate(config); @@ -107,7 +107,7 @@ const postSongDataToAPI = async (songInfo, config, data) => { }; postData.api_sig = createApiSig(postData, config.secret); - fetch('https://ws.audioscrobbler.com/2.0/', { method: 'POST', body: createFormData(postData) }) + net.fetch('https://ws.audioscrobbler.com/2.0/', { method: 'POST', body: createFormData(postData) }) .catch((error) => { if (error.response.data.error === 9) { // Session key is invalid, so remove it from the config and reauthenticate diff --git a/plugins/lyrics-genius/back.js b/plugins/lyrics-genius/back.js index 0c87db12..1913c193 100644 --- a/plugins/lyrics-genius/back.js +++ b/plugins/lyrics-genius/back.js @@ -1,6 +1,6 @@ const { join } = require('node:path'); -const { ipcMain } = require('electron'); +const { ipcMain, net } = require('electron'); const is = require('electron-is'); const { convert } = require('html-to-text'); @@ -59,7 +59,7 @@ const fetchFromGenius = async (metadata) => { * @returns The lyrics of the first song found using the Genius-Lyrics API */ const getLyricsList = async (queryString) => { - const response = await fetch( + const response = await net.fetch( `https://genius.com/api/search/multi?per_page=5&q=${encodeURIComponent(queryString)}`, ); if (!response.ok) { @@ -88,7 +88,7 @@ const getLyricsList = async (queryString) => { * @returns The lyrics of the song URL provided, null if none */ const getLyrics = async (url) => { - const response = await fetch(url); + const response = await net.fetch(url); if (!response.ok) { return null; } diff --git a/plugins/tuna-obs/back.js b/plugins/tuna-obs/back.js index a1a7d0c2..96e83381 100644 --- a/plugins/tuna-obs/back.js +++ b/plugins/tuna-obs/back.js @@ -1,4 +1,4 @@ -const { ipcMain } = require('electron'); +const { ipcMain, net } = require('electron'); const registerCallback = require('../../providers/song-info'); @@ -24,7 +24,7 @@ const post = async (data) => { 'Access-Control-Allow-Origin': '*', }; const url = `http://127.0.0.1:${port}/`; - fetch(url, { + net.fetch(url, { method: 'POST', headers, body: JSON.stringify({ data }), diff --git a/providers/song-info.js b/providers/song-info.js index 841a0845..4c80b574 100644 --- a/providers/song-info.js +++ b/providers/song-info.js @@ -1,4 +1,4 @@ -const { ipcMain, nativeImage } = require('electron'); +const { ipcMain, nativeImage, net } = require('electron'); const config = require('../config'); const { cache } = require('../providers/decorators'); @@ -29,7 +29,7 @@ const getImage = cache( * @returns {Promise} */ async (src) => { - const result = await fetch(src); + const result = await net.fetch(src); const buffer = await result.arrayBuffer(); const output = nativeImage.createFromBuffer(Buffer.from(buffer)); if (output.isEmpty() && !src.endsWith('.jpg') && src.includes('.jpg')) { // Fix hidden webp files (https://github.com/th-ch/youtube-music/issues/315)