mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 08:07:30 +00:00
Remove updater page
This commit is contained in:
parent
f6977ed3b9
commit
a7a9af8854
@ -175,10 +175,6 @@ let constants = {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
settings: {
|
|
||||||
enable_updater_page: false
|
|
||||||
},
|
|
||||||
|
|
||||||
featured_profiles: [
|
featured_profiles: [
|
||||||
],
|
],
|
||||||
|
|
||||||
@ -202,7 +198,6 @@ let constants = {
|
|||||||
image_cache_control: `public, max-age=${7*24*60*60}`,
|
image_cache_control: `public, max-age=${7*24*60*60}`,
|
||||||
resource_cache_time: 30*60*1000,
|
resource_cache_time: 30*60*1000,
|
||||||
instance_list_cache_time: 3*60*1000,
|
instance_list_cache_time: 3*60*1000,
|
||||||
updater_cache_time: 2*60*1000,
|
|
||||||
cache_sweep_interval: 3*60*1000,
|
cache_sweep_interval: 3*60*1000,
|
||||||
csrf_time: 60*60*1000,
|
csrf_time: 60*60*1000,
|
||||||
self_blocked_status: {
|
self_blocked_status: {
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
const child_process = require("child_process")
|
|
||||||
const constants = require("../../lib/constants")
|
|
||||||
const {render} = require("pinski/plugins")
|
|
||||||
|
|
||||||
function run(command) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
child_process.exec(command, {encoding: "utf8"}, (error, stdout, stderr) => {
|
|
||||||
if (error) reject(error)
|
|
||||||
else resolve({stdout, stderr})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let lastFetchRunAt = 0
|
|
||||||
async function fetch() {
|
|
||||||
if (lastFetchRunAt + constants.caching.updater_cache_time < Date.now()) {
|
|
||||||
await run("git fetch origin")
|
|
||||||
lastFetchRunAt = Date.now()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = [
|
|
||||||
{route: "/admin/updater", methods: ["GET"], code: async () => {
|
|
||||||
if (constants.settings.enable_updater_page) {
|
|
||||||
let {stdout: current} = await run("git rev-parse --abbrev-ref HEAD")
|
|
||||||
current = current.trim()
|
|
||||||
let {stdout: upstream} = await run("git rev-parse --abbrev-ref '@{u}'")
|
|
||||||
upstream = upstream.trim()
|
|
||||||
if (current !== "master" || upstream !== "origin/master") {
|
|
||||||
return render(200, "pug/admin_update.pug", {error: `Refusing to automatically update: current is ${current}, upstream is ${upstream}, need master and origin/master`})
|
|
||||||
} else {
|
|
||||||
await fetch()
|
|
||||||
let {stdout: log} = await run("git log --oneline origin/master ^master")
|
|
||||||
log = log.trim()
|
|
||||||
const numberOfCommits = log === "" ? 0 : log.split("\n").length
|
|
||||||
const {stdout: changedFiles} = await run("git diff master origin/master --name-only")
|
|
||||||
const changedFilesList = changedFiles.trim().split("\n")
|
|
||||||
let requiresRestart = false
|
|
||||||
let requiresDeps = false
|
|
||||||
if (changedFilesList.some(c => c.startsWith("src/lib") || c === "server.js")) {
|
|
||||||
requiresRestart = true
|
|
||||||
}
|
|
||||||
if (changedFilesList.some(c => c === "package.json" || c === "package-lock.json")) {
|
|
||||||
requiresDeps = true
|
|
||||||
requiresRestart = true
|
|
||||||
}
|
|
||||||
const formattedLog = log.split("\n").map(line => {
|
|
||||||
if (!line) return line // skip for empty string
|
|
||||||
const [hash, message] = line.match(/(\w+) (.*)$/).slice(1)
|
|
||||||
return {hash, message}
|
|
||||||
})
|
|
||||||
return render(200, "pug/admin_update.pug", {formattedLog, numberOfCommits, requiresDeps, requiresRestart})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return render(403, "pug/friendlyerror.pug", {
|
|
||||||
statusCode: 403,
|
|
||||||
title: "Updater page disabled",
|
|
||||||
message: "Updater page disabled"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
]
|
|
@ -1,32 +0,0 @@
|
|||||||
//- Needs {error} or {formattedLog, numberOfCommits, requiresDeps, requiresRestart}
|
|
||||||
|
|
||||||
doctype html
|
|
||||||
html
|
|
||||||
head
|
|
||||||
title Updater | Bibliogram
|
|
||||||
include includes/head
|
|
||||||
body.updater-page
|
|
||||||
if error
|
|
||||||
h1 Aw man.
|
|
||||||
div= error
|
|
||||||
else
|
|
||||||
h1 Bibliogram updater
|
|
||||||
if numberOfCommits > 0
|
|
||||||
div You are #{numberOfCommits} #{numberOfCommits === 1 ? "commit" : "commits"} behind (most recent first):
|
|
||||||
div.commits
|
|
||||||
each line in formattedLog
|
|
||||||
div.commit
|
|
||||||
code.hash= line.hash
|
|
||||||
span.message= line.message
|
|
||||||
div
|
|
||||||
if requiresDeps
|
|
||||||
span.attention You must run #[code npm install] after pulling.
|
|
||||||
else
|
|
||||||
span No changes to dependencies.
|
|
||||||
div
|
|
||||||
if requiresRestart
|
|
||||||
span.attention You must restart Bibliogram after pulling.
|
|
||||||
else
|
|
||||||
span You do not need to restart Bibliogram after pulling.
|
|
||||||
else
|
|
||||||
div You are running the latest version. Hurrah!
|
|
Loading…
Reference in New Issue
Block a user