Changes:
Fixed instance updating Made the instance updater remove frontends & networks not in the current version Fixed CI linter
This commit is contained in:
parent
1dfd4f8764
commit
eb3794cdcb
@ -26,7 +26,7 @@ pipeline:
|
|||||||
event: [push, pull_request]
|
event: [push, pull_request]
|
||||||
path:
|
path:
|
||||||
exclude: ["src/instances/**"]
|
exclude: ["src/instances/**"]
|
||||||
include: ["src/"]
|
include: ["src/**"]
|
||||||
commands:
|
commands:
|
||||||
- npm i
|
- npm i
|
||||||
- npx web-ext lint --source-dir ./src/
|
- npx web-ext lint --source-dir ./src/
|
||||||
|
@ -566,17 +566,30 @@ function unifyPreferences(url, tabId) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setRedirects(redirects) {
|
function setRedirects(passedRedirects) {
|
||||||
|
return new Promise(resolve => {
|
||||||
fetch("/config/config.json")
|
fetch("/config/config.json")
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(configData => {
|
.then(configData => {
|
||||||
//browser.storage.local.get(["options", "blacklists"], async r => {
|
browser.storage.local.get(/* [ */ "options" /* , "blacklists"] */, async r => {
|
||||||
//const options = r.options
|
let redirects = passedRedirects
|
||||||
|
let options = r.options
|
||||||
const config = JSON.parse(configData)
|
const config = JSON.parse(configData)
|
||||||
let targets = {}
|
let targets = {}
|
||||||
for (const service in config.services) {
|
for (const service in config.services) {
|
||||||
if (config.services[service].targets == "datajson") {
|
if (config.services[service].targets == "datajson") {
|
||||||
targets[service] = redirects[service]
|
targets[service] = redirects[service]
|
||||||
|
delete redirects[service]
|
||||||
|
}
|
||||||
|
for (const frontend in config.services[service].frontends) {
|
||||||
|
if (config.services[service].frontends[frontend].instanceList) {
|
||||||
|
for (const network in config.networks) {
|
||||||
|
for (const instance of options[frontend][network].enabled) {
|
||||||
|
let i = redirects[frontend][network].indexOf(instance)
|
||||||
|
if (i < 0) options[frontend][network].enabled.splice(i, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
for (const frontend in config.services[service].frontends) {
|
for (const frontend in config.services[service].frontends) {
|
||||||
@ -595,8 +608,15 @@ async function setRedirects(redirects) {
|
|||||||
*/
|
*/
|
||||||
// The above will be implemented with https://github.com/libredirect/libredirect/issues/334
|
// The above will be implemented with https://github.com/libredirect/libredirect/issues/334
|
||||||
}
|
}
|
||||||
browser.storage.local.set({ redirects, targets /*, options*/ })
|
for (const frontend in redirects) {
|
||||||
//})
|
let exists = false
|
||||||
|
for (const service in config.services) if (config.services[service].frontends[frontend]) exists = true
|
||||||
|
if (!exists) delete redirects[frontend]
|
||||||
|
else for (const network in redirects[frontend]) if (!config.networks[network]) delete redirects[frontend][network]
|
||||||
|
}
|
||||||
|
browser.storage.local.set({ redirects, targets, options }, () => resolve())
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,7 +637,10 @@ function initDefaults() {
|
|||||||
const latency = {}
|
const latency = {}
|
||||||
for (const service in config.services) {
|
for (const service in config.services) {
|
||||||
options[service] = {}
|
options[service] = {}
|
||||||
if (config.services[service].targets == "datajson") targets[service] = redirects[service]
|
if (config.services[service].targets == "datajson") {
|
||||||
|
targets[service] = redirects[service]
|
||||||
|
delete redirects[service]
|
||||||
|
}
|
||||||
for (const defaultOption in config.services[service].options) options[service][defaultOption] = config.services[service].options[defaultOption]
|
for (const defaultOption in config.services[service].options) options[service][defaultOption] = config.services[service].options[defaultOption]
|
||||||
for (const frontend in config.services[service].frontends) {
|
for (const frontend in config.services[service].frontends) {
|
||||||
if (config.services[service].frontends[frontend].instanceList) {
|
if (config.services[service].frontends[frontend].instanceList) {
|
||||||
@ -729,7 +752,10 @@ function processUpdate() {
|
|||||||
let config = JSON.parse(configData)
|
let config = JSON.parse(configData)
|
||||||
for (const service in config.services) {
|
for (const service in config.services) {
|
||||||
if (!options[service]) options[service] = {}
|
if (!options[service]) options[service] = {}
|
||||||
if (config.services[service].targets == "datajson") targets[service] = redirects[service]
|
if (config.services[service].targets == "datajson") {
|
||||||
|
targets[service] = redirects[service]
|
||||||
|
delete redirects[service]
|
||||||
|
}
|
||||||
for (const defaultOption in config.services[service].options) {
|
for (const defaultOption in config.services[service].options) {
|
||||||
if (options[service][defaultOption] === undefined) {
|
if (options[service][defaultOption] === undefined) {
|
||||||
options[service][defaultOption] = config.services[service].options[defaultOption]
|
options[service][defaultOption] = config.services[service].options[defaultOption]
|
||||||
|
@ -47,7 +47,6 @@ function updateInstances() {
|
|||||||
const instances = JSON.parse(http.responseText)
|
const instances = JSON.parse(http.responseText)
|
||||||
|
|
||||||
await servicesHelper.setRedirects(instances)
|
await servicesHelper.setRedirects(instances)
|
||||||
await servicesHelper.processEnabledInstanceList()
|
|
||||||
|
|
||||||
console.info("Successfully updated Instances")
|
console.info("Successfully updated Instances")
|
||||||
resolve(true)
|
resolve(true)
|
||||||
|
@ -253,7 +253,7 @@
|
|||||||
"instanceList": true
|
"instanceList": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"targets": ["^https?:\\/{2}(www\\.|old\\.|np\\.|new\\.|amp\\.|)reddit\\.com(?=\\/u(ser)?\\/|\\/r\\/|\\/?$)", "^https?:\\/{2}(i\\.|(external-)?preview\\.|)redd\\.it"],
|
"targets": ["^https?:\\/{2}(www\\.|old\\.|np\\.|new\\.|amp\\.|)reddit\\.com(?=\\/u(ser)?\\/|\\/r\\/|\\/?$)", "^https?:\\/{2}(i|(external-)?preview)\\.redd\\.it"],
|
||||||
"name": "Reddit",
|
"name": "Reddit",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user