parent
06632137c0
commit
9304548847
@ -1,9 +1,15 @@
|
||||
const { Router } = require("express")
|
||||
const { BanModel,UserModel } = require("../models");
|
||||
const { Router } = require("express");
|
||||
const fs = require("fs");
|
||||
const { BanModel, UserModel } = require("../models");
|
||||
const app = Router();
|
||||
|
||||
app.use(async (req, res, next) => {
|
||||
if (!req.user?.admin) return res.error(403, "You are not admin");
|
||||
next();
|
||||
});
|
||||
app.get("/", async (req, res) => {
|
||||
if (!req.user?.admin) return res.error(403, "You have not got permissions for view to this page.");
|
||||
res.reply("admin",{bans: await BanModel.find({}), admins: await UserModel.find({admin: true})});
|
||||
res.reply("admin", { bans: await BanModel.find({}), admins: await UserModel.find({ admin: true }) });
|
||||
});
|
||||
app.get("/config", async (req, res) => {
|
||||
res.reply("config", { config: fs.readFileSync("./config.json", "utf8") });
|
||||
});
|
||||
module.exports = app;
|
@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<%- include("extra/meta", {title: "Edit Forum Config!" }) %>
|
||||
|
||||
<body style="text-align: center;">
|
||||
<%- include("extra/navbar") %>
|
||||
<h1>Edit forum config</h1>
|
||||
<textarea rows="30" cols="75"><%= config %></textarea>
|
||||
<a onclick="send();" class="btn-primary">Edit config</a>
|
||||
<script>
|
||||
const textarea = document.querySelector('textarea');
|
||||
async function send() {
|
||||
const res = await fetch('/api/config?text', {
|
||||
method: 'PUT',
|
||||
body: textarea.value,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
if (res.error) return alert(res.error);
|
||||
alert('Success!');
|
||||
textarea.value=JSON.stringify( await res.json(),null,4)
|
||||
|
||||
}
|
||||
</script>
|
||||
<%- include("extra/footer") %>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in new issue