fix sponsorblock plugin

This commit is contained in:
Araxeus
2021-10-30 12:43:51 +03:00
parent 62e8e673eb
commit 286bc0113e
4 changed files with 29 additions and 38 deletions

View File

@ -1,4 +1,12 @@
const fetch = require("node-fetch");
const is = require("electron-is");
// see https://github.com/node-fetch/node-fetch/issues/568#issuecomment-932200523
// will not be needed if project's electron version >= v15.1.0 (https://github.com/node-fetch/node-fetch/issues/568#issuecomment-932435180)
const https = require("https");
const agent = new https.Agent({
rejectUnauthorized: false,
});
const defaultConfig = require("../../config/defaults");
const registerCallback = require("../../providers/song-info");
@ -24,6 +32,7 @@ module.exports = (win, options) => {
});
};
const fetchSegments = async (apiURL, categories) => {
const sponsorBlockURL = `${apiURL}/api/skipSegments?videoID=${videoID}&categories=${JSON.stringify(
categories
@ -35,6 +44,7 @@ const fetchSegments = async (apiURL, categories) => {
"Content-Type": "application/json",
},
redirect: "follow",
agent // fixes error: 'CERT_HAS_EXPIRED'
});
if (resp.status !== 200) {
return [];
@ -45,7 +55,10 @@ const fetchSegments = async (apiURL, categories) => {
);
return sortedSegments;
} catch {
} catch (e) {
if (is.dev()) {
console.log('error on sponsorblock request:', e);
}
return [];
}
};