Added edit config to web

This commit is contained in:
Akif9748 2022-10-09 22:57:46 +03:00
parent 06632137c0
commit 9304548847
6 changed files with 59 additions and 14 deletions

View file

@ -24,6 +24,10 @@ You can change them in config.json.
#### `/api/me`
- GET `/api/me` to get your account.
#### `/api/config`
- GET `/` to reach config file.
- PUT `/` to edit config file.
#### `/api/bans`
- GET `/` fetch all bans.
- GET `/:ip` fetch a ban.

View file

@ -49,18 +49,20 @@ Akf-forum has got an API for AJAX (fetch), other clients etc. And, you can learn
- Profile Message or DM
- mod role, permissions
- upload other photos, model for it
- categories page is need a update, thread count in category
- Disable last seen button for web.
- old contents / titles add to forum interface
- add ban button to user profile.?
- change password.
- add approval threads page.
- who liked a message for web.
- edit config from web admin panel.
- Add a feature list to README.md
- delete admin???
- change category name
- theme support++, directly edit html!
### front-end
- better usermenu for user profile
- old contents / titles add to forum interface
- categories page is need a update, thread count in category (?)
- add ban button to user profile.?
- who liked a message for web.
- edit config from web admin panel.
## Major Version History
- V4: Caching
- V3: New Theme

View file

@ -1,9 +1,15 @@
const { Router } = require("express")
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 }) });
});
app.get("/config", async (req, res) => {
res.reply("config", { config: fs.readFileSync("./config.json", "utf8") });
});
module.exports = app;

View file

@ -15,9 +15,10 @@ app.get("/", (req, res) => {
res.error(500, e.message);
}
});
app.post("/", (req, res) => {
fs.writeFileSync("./config.json", JSON.stringify(req.body, null, 4));
require.cache[require.resolve("../config.json")] = require("../../../config.json");
app.put("/", (req, res) => {
const write= req.query.text ? req.body : JSON.stringify(req.body, null, 4)
fs.writeFileSync("./config.json",write );
require.cache[require.resolve("../../../config.json")] = require("../../../config.json");
res.complate(require("../../../config.json"));
});

View file

@ -32,6 +32,7 @@
<a class="btn-primary" onclick="ban();">IP BAN</a>
<a class="btn-outline-primary" onclick="unban();">REMOVE IP BAN</a>
<a href="/categories/create" class="btn-primary">Create Category</a>
<a href="/admin/config" class="btn-primary">Edit config</a>
<h2 style="color: var(--second);">Banned users:</h2>

31
views/config.ejs Normal file
View file

@ -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>