1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-22 16:17:29 +00:00

Add Tor status to home and stats

This commit is contained in:
Cadence Fish 2020-02-03 04:09:40 +13:00
parent 6e136dc77a
commit 1fcdfce868
No known key found for this signature in database
GPG Key ID: 81015DF9AA8607E1
5 changed files with 23 additions and 4 deletions

View File

@ -10,6 +10,10 @@ class TorSwitcher {
this.torManager = torManager
}
canUseTor() {
return !!this.torManager
}
/**
* Request from the URL.
* The test function will be called with the response object.

View File

@ -1,4 +1,5 @@
const constants = require("../../lib/constants")
const switcher = require("../../lib/utils/torswitcher")
const {fetchUser, getOrFetchShortcode, userRequestCache, history} = require("../../lib/collectors")
const {render, redirect} = require("pinski/plugins")
const {pugCache} = require("../passthrough")
@ -8,7 +9,8 @@ module.exports = [
route: "/", methods: ["GET"], code: async () => {
return render(200, "pug/home.pug", {
rssEnabled: constants.settings.rss_enabled,
allUnblocked: history.testNoneBlocked()
allUnblocked: history.testNoneBlocked(),
torAvailable: switcher.canUseTor()
})
}
},

View File

@ -3,6 +3,7 @@ const child_process = require("child_process")
const md = require("mixin-deep")
const constants = require("../../lib/constants")
const {history} = require("../../lib/collectors")
const switcher = require("../../lib/utils/torswitcher")
const {redirect} = require("pinski/plugins")
function reply(statusCode, content) {
@ -27,7 +28,7 @@ let commit = ""
// Set up inner versioning
const displayVersions = ["1.0", "1.1", "1.2"]
const displayVersions = ["1.0", "1.1", "1.2", "1.3"]
const versions = new Map(displayVersions.map(v => [v, semver.coerce(v)]))
const features = [
"PAGE_PROFILE",
@ -61,6 +62,11 @@ const innerMap = new Map()
rssEnabled: constants.settings.rss_enabled
}
})
addVersion("1.3", {
settings: {
torAvailable: switcher.canUseTor() // server.js holds on loading this file until tor state is known, so this is fine
}
})
}
module.exports = [

View File

@ -1,4 +1,4 @@
//- Needs rssEnabled, allUnblocked
//- Needs rssEnabled, allUnblocked, torAvailable
doctype html
html
@ -37,6 +37,7 @@ html
ul
li Instance is #{allUnblocked ? "not blocked" : "blocked"}
li RSS feeds are #{rssEnabled ? "enabled" : "disabled"}
li Tor is #{torAvailable ? "enabled" : "not available"}
h2 External links
ul.link-list
-

View File

@ -1,5 +1,6 @@
const {Pinski} = require("pinski")
const {subdirs} = require("node-dir")
const constants = require("../lib/constants")
const passthrough = require("./passthrough")
@ -8,7 +9,7 @@ const pinski = new Pinski({
relativeRoot: __dirname
})
subdirs("pug", (err, dirs) => {
subdirs("pug", async (err, dirs) => {
if (err) throw err
//pinski.addRoute("/", "pug/index.pug", "pug")
@ -20,6 +21,11 @@ subdirs("pug", (err, dirs) => {
pinski.muteLogsStartingWith("/imageproxy")
pinski.muteLogsStartingWith("/videoproxy")
pinski.muteLogsStartingWith("/static")
if (constants.tor.enabled) {
await require("../lib/utils/tor") // make sure tor state is known before going further
}
pinski.startServer()
pinski.enableWS()