Added Url Parameters support for Invidious, Piped https://github.com/libredirect/libredirect/issues/491

This commit is contained in:
ManeraKai 2022-12-08 20:59:52 +03:00
parent c702c1d469
commit 2a738e883c
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
2 changed files with 8 additions and 3 deletions

View File

@ -97,6 +97,9 @@ function redirect(url, type, initiator, forceRedirection) {
break break
} }
if (!frontend || !randomInstance) return if (!frontend || !randomInstance) return
let randomInstanceURL = new URL(randomInstance);
let allParams = randomInstanceURL.searchParams
url.searchParams.forEach((value, key) => allParams.append(key, value))
// Here is a (temperory) space for defining constants required in 2 or more switch cases. // Here is a (temperory) space for defining constants required in 2 or more switch cases.
// When possible, try have the two switch cases share all their code as done with searx and searxng. // When possible, try have the two switch cases share all their code as done with searx and searxng.
@ -116,7 +119,6 @@ function redirect(url, type, initiator, forceRedirection) {
} }
return [zoom, lon, lat] return [zoom, lon, lat]
} }
console.log(frontend)
switch (frontend) { switch (frontend) {
// This is where all instance-specific code must be ran to convert the service url to one that can be understood by the frontend. // This is where all instance-specific code must be ran to convert the service url to one that can be understood by the frontend.
case "beatbump": case "beatbump":
@ -447,8 +449,11 @@ function redirect(url, type, initiator, forceRedirection) {
return `${randomInstance}${url.pathname}${url.search}` return `${randomInstance}${url.pathname}${url.search}`
case "simpleertube": case "simpleertube":
return `${randomInstance}/${url.hostname}${url.pathname}${url.search}` return `${randomInstance}/${url.hostname}${url.pathname}${url.search}`
case "invidious":
case "piped":
return `${utils.protocolHost(randomInstanceURL)}${url.pathname}?${allParams.toString()}`
default: default:
return `${randomInstance}${url.pathname}${url.search} ` return `${randomInstance}${url.pathname}${url.search}`
} }
} }

View File

@ -188,7 +188,7 @@ async function processDefaultCustomInstances(service, frontend, network, documen
event.preventDefault() event.preventDefault()
let frontendCustomInstanceInput = frontendNetworkElement.getElementsByClassName("custom-instance")[0] let frontendCustomInstanceInput = frontendNetworkElement.getElementsByClassName("custom-instance")[0]
let url = new URL(frontendCustomInstanceInput.value) let url = new URL(frontendCustomInstanceInput.value)
let protocolHostVar = protocolHost(url) let protocolHostVar = url.href
if (frontendCustomInstanceInput.validity.valid && !redirects[frontend][network].includes(protocolHostVar)) { if (frontendCustomInstanceInput.validity.valid && !redirects[frontend][network].includes(protocolHostVar)) {
if (!frontendCustomInstances.includes(protocolHostVar)) { if (!frontendCustomInstances.includes(protocolHostVar)) {
frontendCustomInstances.push(protocolHostVar) frontendCustomInstances.push(protocolHostVar)