Fixed twimg redirects

Closes https://github.com/libredirect/libredirect/issues/307
This commit is contained in:
Hygna 2022-10-06 14:19:05 +01:00
parent 3bd83642f3
commit 04fd2de0bb
No known key found for this signature in database
1 changed files with 21 additions and 32 deletions

View File

@ -150,9 +150,13 @@ function redirect(url, type, initiator) {
if (search !== "") search = `?${search}`
if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") {
const [, id, format, extra] = url.search.match(/(.*)\?format=(.*)&(.*)/)
try {
const [, id, format, extra] = search.match(/(.*)\?format=(.*)&(.*)/)
const query = encodeURIComponent(`${id}.${format}?${extra}`)
return `${randomInstance}/pic${search}${query}`
return `${randomInstance}/pic${url.pathname}${query}`
} catch {
return `${randomInstance}/pic${url.pathname}${search}`
}
}
if (url.pathname.split("/").includes("tweets")) return `${randomInstance}${url.pathname.replace("/tweets", "")}${search}`
@ -412,20 +416,13 @@ function computeService(url, returnFrontend) {
const options = r.options
for (const service in config.services) {
if (regexArray(service, url, config)) {
if (returnFrontend) {
resolve([service, null])
} else {
resolve(service)
}
return
} else {
for (const frontend in config.services[service].frontends) {
if (all(service, frontend, options, config, redirects).includes(utils.protocolHost(url))) {
if (returnFrontend) {
resolve([service, frontend])
} else {
resolve(service)
}
if (returnFrontend) resolve([service, frontend, url.hostname])
else resolve(service)
return
}
}
@ -601,12 +598,8 @@ function initDefaults() {
const latency = {}
for (const service in config.services) {
options[service] = {}
if (config.services[service].targets == "datajson") {
targets[service] = redirects[service]
}
for (const defaultOption in config.services[service].options) {
options[service][defaultOption] = config.services[service].options[defaultOption]
}
if (config.services[service].targets == "datajson") targets[service] = redirects[service]
for (const defaultOption in config.services[service].options) options[service][defaultOption] = config.services[service].options[defaultOption]
for (const frontend in config.services[service].frontends) {
if (config.services[service].frontends[frontend].instanceList) {
options[frontend] = {}
@ -717,24 +710,20 @@ function processUpdate() {
let targets = r.targets
let config = JSON.parse(configData)
for (const service in config.services) {
if (!options[service]) {
options[service] = {}
if (config.services[service].targets == "datajson") {
targets[service] = redirects[service]
}
for (const defaultOption in config.services[service].options) {
options[service][defaultOption] = config.services[service].options[defaultOption]
}
}
if (!options[service]) options[service] = {}
if (config.services[service].targets == "datajson") targets[service] = redirects[service]
for (const defaultOption in config.services[service].options) if (!options[service][defaultOption]) options[service][defaultOption] = config.services[service].options[defaultOption]
for (const frontend in config.services[service].frontends) {
if (!options[service][frontend]) {
if (config.services[service].frontends[frontend].instanceList) {
options[frontend] = {}
for (const network in config.networks) {
if (!options[frontend][network]) {
options[frontend][network] = {}
options[frontend][network].enabled = JSON.parse(data)[frontend][network]
options[frontend][network].custom = []
}
}
if (!options[service][frontend]) {
options[frontend] = {}
for (const blacklist in r.blacklists) {
for (const instance of r.blacklists[blacklist]) {
let i = options[frontend].clearnet.enabled.indexOf(instance)