Use the builtin subtle crypto library instead of node-forge (#2276)
This commit is contained in:
parent
7ae9160362
commit
dd5c68223b
|
@ -71,7 +71,6 @@
|
||||||
"marked": "^4.0.15",
|
"marked": "^4.0.15",
|
||||||
"material-design-icons": "^3.0.1",
|
"material-design-icons": "^3.0.1",
|
||||||
"nedb-promises": "^5.0.1",
|
"nedb-promises": "^5.0.1",
|
||||||
"node-forge": "^1.3.1",
|
|
||||||
"opml-to-json": "^1.0.1",
|
"opml-to-json": "^1.0.1",
|
||||||
"rss-parser": "^3.12.0",
|
"rss-parser": "^3.12.0",
|
||||||
"socks-proxy-agent": "^6.0.0",
|
"socks-proxy-agent": "^6.0.0",
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import $ from 'jquery'
|
import $ from 'jquery'
|
||||||
import forge from 'node-forge'
|
|
||||||
|
|
||||||
const state = {}
|
const state = {}
|
||||||
const getters = {}
|
const getters = {}
|
||||||
|
@ -7,22 +6,30 @@ const getters = {}
|
||||||
const actions = {
|
const actions = {
|
||||||
sponsorBlockSkipSegments ({ rootState }, { videoId, categories }) {
|
sponsorBlockSkipSegments ({ rootState }, { videoId, categories }) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const messageDigestSha256 = forge.md.sha256.create()
|
const videoIdBuffer = new TextEncoder().encode(videoId)
|
||||||
messageDigestSha256.update(videoId)
|
|
||||||
const videoIdHashPrefix = messageDigestSha256.digest().toHex().substring(0, 4)
|
|
||||||
const requestUrl = `${rootState.settings.sponsorBlockUrl}/api/skipSegments/${videoIdHashPrefix}?categories=${JSON.stringify(categories)}`
|
|
||||||
|
|
||||||
$.getJSON(requestUrl, (response) => {
|
crypto.subtle.digest('SHA-256', videoIdBuffer).then((hashBuffer) => {
|
||||||
const segments = response
|
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
||||||
.filter((result) => result.videoID === videoId)
|
|
||||||
.flatMap((result) => result.segments)
|
const videoIdHashPrefix = hashArray
|
||||||
resolve(segments)
|
.map(byte => byte.toString(16).padStart(2, '0'))
|
||||||
}).fail((xhr, textStatus, error) => {
|
.slice(0, 4)
|
||||||
console.log(xhr)
|
.join('')
|
||||||
console.log(textStatus)
|
|
||||||
console.log(requestUrl)
|
const requestUrl = `${rootState.settings.sponsorBlockUrl}/api/skipSegments/${videoIdHashPrefix}?categories=${JSON.stringify(categories)}`
|
||||||
console.log(error)
|
|
||||||
reject(xhr)
|
$.getJSON(requestUrl, (response) => {
|
||||||
|
const segments = response
|
||||||
|
.filter((result) => result.videoID === videoId)
|
||||||
|
.flatMap((result) => result.segments)
|
||||||
|
resolve(segments)
|
||||||
|
}).fail((xhr, textStatus, error) => {
|
||||||
|
console.log(xhr)
|
||||||
|
console.log(textStatus)
|
||||||
|
console.log(requestUrl)
|
||||||
|
console.log(error)
|
||||||
|
reject(xhr)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -6356,7 +6356,7 @@ node-fetch@^2.6.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
whatwg-url "^5.0.0"
|
whatwg-url "^5.0.0"
|
||||||
|
|
||||||
node-forge@^1, node-forge@^1.3.1:
|
node-forge@^1:
|
||||||
version "1.3.1"
|
version "1.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3"
|
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3"
|
||||||
integrity sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==
|
integrity sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==
|
||||||
|
|
Loading…
Reference in New Issue