mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-15 04:11:47 +00:00
fix: use net.fetch instead of node native fetch
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
const { shell } = require('electron');
|
const { shell, net } = require('electron');
|
||||||
const md5 = require('md5');
|
const md5 = require('md5');
|
||||||
|
|
||||||
const { setOptions } = require('../../config/plugins');
|
const { setOptions } = require('../../config/plugins');
|
||||||
@ -56,7 +56,7 @@ const createToken = async ({ apiKey, apiRoot, secret }) => {
|
|||||||
format: 'json',
|
format: 'json',
|
||||||
};
|
};
|
||||||
const apiSigature = createApiSig(data, secret);
|
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();
|
response = await response.json();
|
||||||
return response?.token;
|
return response?.token;
|
||||||
};
|
};
|
||||||
@ -78,7 +78,7 @@ const getAndSetSessionKey = async (config) => {
|
|||||||
token: config.token,
|
token: config.token,
|
||||||
};
|
};
|
||||||
const apiSignature = createApiSig(data, config.secret);
|
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();
|
res = await res.json();
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
await authenticate(config);
|
await authenticate(config);
|
||||||
@ -107,7 +107,7 @@ const postSongDataToAPI = async (songInfo, config, data) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
postData.api_sig = createApiSig(postData, config.secret);
|
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) => {
|
.catch((error) => {
|
||||||
if (error.response.data.error === 9) {
|
if (error.response.data.error === 9) {
|
||||||
// Session key is invalid, so remove it from the config and reauthenticate
|
// Session key is invalid, so remove it from the config and reauthenticate
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
const { join } = require('node:path');
|
const { join } = require('node:path');
|
||||||
|
|
||||||
const { ipcMain } = require('electron');
|
const { ipcMain, net } = require('electron');
|
||||||
const is = require('electron-is');
|
const is = require('electron-is');
|
||||||
const { convert } = require('html-to-text');
|
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
|
* @returns The lyrics of the first song found using the Genius-Lyrics API
|
||||||
*/
|
*/
|
||||||
const getLyricsList = async (queryString) => {
|
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)}`,
|
`https://genius.com/api/search/multi?per_page=5&q=${encodeURIComponent(queryString)}`,
|
||||||
);
|
);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@ -88,7 +88,7 @@ const getLyricsList = async (queryString) => {
|
|||||||
* @returns The lyrics of the song URL provided, null if none
|
* @returns The lyrics of the song URL provided, null if none
|
||||||
*/
|
*/
|
||||||
const getLyrics = async (url) => {
|
const getLyrics = async (url) => {
|
||||||
const response = await fetch(url);
|
const response = await net.fetch(url);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { ipcMain } = require('electron');
|
const { ipcMain, net } = require('electron');
|
||||||
|
|
||||||
const registerCallback = require('../../providers/song-info');
|
const registerCallback = require('../../providers/song-info');
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ const post = async (data) => {
|
|||||||
'Access-Control-Allow-Origin': '*',
|
'Access-Control-Allow-Origin': '*',
|
||||||
};
|
};
|
||||||
const url = `http://127.0.0.1:${port}/`;
|
const url = `http://127.0.0.1:${port}/`;
|
||||||
fetch(url, {
|
net.fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify({ data }),
|
body: JSON.stringify({ data }),
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { ipcMain, nativeImage } = require('electron');
|
const { ipcMain, nativeImage, net } = require('electron');
|
||||||
|
|
||||||
const config = require('../config');
|
const config = require('../config');
|
||||||
const { cache } = require('../providers/decorators');
|
const { cache } = require('../providers/decorators');
|
||||||
@ -29,7 +29,7 @@ const getImage = cache(
|
|||||||
* @returns {Promise<Electron.NativeImage>}
|
* @returns {Promise<Electron.NativeImage>}
|
||||||
*/
|
*/
|
||||||
async (src) => {
|
async (src) => {
|
||||||
const result = await fetch(src);
|
const result = await net.fetch(src);
|
||||||
const buffer = await result.arrayBuffer();
|
const buffer = await result.arrayBuffer();
|
||||||
const output = nativeImage.createFromBuffer(Buffer.from(buffer));
|
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)
|
if (output.isEmpty() && !src.endsWith('.jpg') && src.includes('.jpg')) { // Fix hidden webp files (https://github.com/th-ch/youtube-music/issues/315)
|
||||||
|
|||||||
Reference in New Issue
Block a user