diff --git a/APIDOCS.md b/APIDOCS.md index d2cbd98..af25813 100644 --- a/APIDOCS.md +++ b/APIDOCS.md @@ -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. diff --git a/README.md b/README.md index f87183f..ec2efd3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/routes/admin.js b/routes/admin.js index 56055e9..8730392 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -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; \ No newline at end of file diff --git a/routes/api/routes/config.js b/routes/api/routes/config.js index 23c6697..504df08 100644 --- a/routes/api/routes/config.js +++ b/routes/api/routes/config.js @@ -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")); }); diff --git a/views/admin.ejs b/views/admin.ejs index 8b769df..4a247c9 100644 --- a/views/admin.ejs +++ b/views/admin.ejs @@ -32,6 +32,7 @@ IP BAN REMOVE IP BAN Create Category + Edit config

Banned users:

diff --git a/views/config.ejs b/views/config.ejs new file mode 100644 index 0000000..b52ad92 --- /dev/null +++ b/views/config.ejs @@ -0,0 +1,31 @@ + + + +<%- include("extra/meta", {title: "Edit Forum Config!" }) %> + + + <%- include("extra/navbar") %> +

Edit forum config

+ + Edit config + + <%- include("extra/footer") %> + + + + \ No newline at end of file