From 4426c2f2061aef207cf371b5727c1880256fedd8 Mon Sep 17 00:00:00 2001 From: Cadence Fish Date: Sat, 1 Feb 2020 21:17:10 +1300 Subject: [PATCH] Show instance state on homepage --- src/lib/structures/RequestHistory.js | 7 +++++++ src/site/api/routes.js | 10 +++++++++- src/site/pug/home.pug | 7 +++++++ src/site/repl.js | 2 +- src/site/server.js | 1 - 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/lib/structures/RequestHistory.js b/src/lib/structures/RequestHistory.js index 8063ff1..b5f87ae 100644 --- a/src/lib/structures/RequestHistory.js +++ b/src/lib/structures/RequestHistory.js @@ -32,6 +32,13 @@ class RequestHistory { } return result } + + testNoneBlocked() { + for (const value of this.store.values()) { + if (value.lastRequestSuccessful === false) return false + } + return true + } } module.exports = RequestHistory diff --git a/src/site/api/routes.js b/src/site/api/routes.js index 852be75..e0f1fca 100644 --- a/src/site/api/routes.js +++ b/src/site/api/routes.js @@ -1,9 +1,17 @@ const constants = require("../../lib/constants") -const {fetchUser, getOrFetchShortcode, requestCache} = require("../../lib/collectors") +const {fetchUser, getOrFetchShortcode, requestCache, history} = require("../../lib/collectors") const {render, redirect} = require("pinski/plugins") const {pugCache} = require("../passthrough") module.exports = [ + { + route: "/", methods: ["GET"], code: async () => { + return render(200, "pug/home.pug", { + rssEnabled: constants.settings.rss_enabled, + allUnblocked: history.testNoneBlocked() + }) + } + }, { route: `/u`, methods: ["GET"], code: async ({url}) => { if (url.searchParams.has("u")) { diff --git a/src/site/pug/home.pug b/src/site/pug/home.pug index 2181b0a..1e4b3a6 100644 --- a/src/site/pug/home.pug +++ b/src/site/pug/home.pug @@ -1,3 +1,5 @@ +//- Needs rssEnabled, allUnblocked + doctype html html head @@ -31,6 +33,11 @@ html p. Bibliogram does #[em not] allow you to anonymously post, like, comment, follow, or view private profiles. It does not preserve deleted posts. + h2 About this instance + ul + li Instance is #{allUnblocked ? "not blocked" : "blocked"} + li RSS feeds are #{rssEnabled ? "enabled" : "disabled"} + h2 External links ul.link-list - const links = [ diff --git a/src/site/repl.js b/src/site/repl.js index 986ef61..fa8d747 100644 --- a/src/site/repl.js +++ b/src/site/repl.js @@ -1,5 +1,5 @@ const {instance, pugCache, wss} = require("./passthrough") -const {requestCache, timelineEntryCache} = require("../lib/collectors") +const {requestCache, timelineEntryCache, history} = require("../lib/collectors") const constants = require("../lib/constants") const util = require("util") const repl = require("repl") diff --git a/src/site/server.js b/src/site/server.js index fc5ac3a..ca98b75 100644 --- a/src/site/server.js +++ b/src/site/server.js @@ -14,7 +14,6 @@ subdirs("pug", (err, dirs) => { //pinski.addRoute("/", "pug/index.pug", "pug") pinski.addRoute("/static/css/main.css", "sass/main.sass", "sass") pinski.addPugDir("pug", dirs) - pinski.addRoute("/", "pug/home.pug", "pug") pinski.addAPIDir("html/static/js/templates/api") pinski.addSassDir("sass") pinski.addAPIDir("api")