mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-22 20:10:40 +03:00
setup and index is now differnt
This commit is contained in:
parent
667c0222e9
commit
adb19e2e34
3 changed files with 37 additions and 33 deletions
|
@ -59,10 +59,8 @@ Akf-forum has got an API for AJAX (fetch), other clients etc. And, you can learn
|
||||||
- change category name
|
- change category name
|
||||||
- _id
|
- _id
|
||||||
- add support for transition around gravatar
|
- add support for transition around gravatar
|
||||||
- forum setup page rewrite and directly open a router
|
|
||||||
- login w/ email
|
|
||||||
- BETTER SETUP PAGE
|
- BETTER SETUP PAGE
|
||||||
|
- add used open source libraries to README.md
|
||||||
### front-end
|
### front-end
|
||||||
- text alling center body
|
- text alling center body
|
||||||
- add a css file for CodeMirror in threads / send message ok
|
- add a css file for CodeMirror in threads / send message ok
|
||||||
|
|
32
routes/.js
32
routes/.js
|
@ -1,7 +1,6 @@
|
||||||
const { UserModel, ThreadModel, MessageModel } = require("../models")
|
const { UserModel, ThreadModel, MessageModel } = require("../models")
|
||||||
const { Router } = require("express");
|
const { Router } = require("express");
|
||||||
const app = Router();
|
const app = Router();
|
||||||
const fs = require("fs");
|
|
||||||
|
|
||||||
app.get("/", async (req, res) => {
|
app.get("/", async (req, res) => {
|
||||||
|
|
||||||
|
@ -11,35 +10,8 @@ app.get("/", async (req, res) => {
|
||||||
threads = await ThreadModel.count({ state: "OPEN" }),
|
threads = await ThreadModel.count({ state: "OPEN" }),
|
||||||
messages = await MessageModel.count({ deleted: false });
|
messages = await MessageModel.count({ deleted: false });
|
||||||
|
|
||||||
res.reply("index", { mem, users, threads, messages })
|
res.reply("index", { mem, users, threads, messages });
|
||||||
|
|
||||||
})
|
});
|
||||||
|
|
||||||
app.get("/setup", async (req, res) => {
|
|
||||||
if (await UserModel.exists({ admin: true })) return res.error(400, "You have already setuped the site.");
|
|
||||||
res.reply("setup");
|
|
||||||
})
|
|
||||||
app.post("/setup", async (req, res) => {
|
|
||||||
if (await UserModel.exists({ admin: true })) return res.error(400, "You have already setuped the site.");
|
|
||||||
let original = {};
|
|
||||||
|
|
||||||
try {
|
|
||||||
original = JSON.parse(fs.readFileSync("./config.json", "utf8"));
|
|
||||||
} catch (e) {
|
|
||||||
try {
|
|
||||||
original = JSON.parse(fs.readFileSync("./config.json.example", "utf8"));
|
|
||||||
} catch (e) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
const content = req.body;
|
|
||||||
|
|
||||||
for (const key in content)
|
|
||||||
if (key in original && content[key])
|
|
||||||
original[key] = content[key];
|
|
||||||
|
|
||||||
fs.writeFileSync("./config.json", JSON.stringify(original,null,4));
|
|
||||||
require.cache[require.resolve("../config.json")] = require("../config.json");
|
|
||||||
res.redirect("/register");
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
34
routes/setup.js
Normal file
34
routes/setup.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
const { UserModel } = require("../models")
|
||||||
|
const { Router } = require("express");
|
||||||
|
const app = Router();
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
app.use(async (req, res, next) => {
|
||||||
|
if (await UserModel.exists({ admin: true })) return res.error(400, "You have already setuped the site.");
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
app.get("/", async (req, res) => res.reply("setup"))
|
||||||
|
app.post("/", async (req, res) => {
|
||||||
|
let original = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
original = JSON.parse(fs.readFileSync("./config.json", "utf8"));
|
||||||
|
} catch (e) {
|
||||||
|
try {
|
||||||
|
original = JSON.parse(fs.readFileSync("./config.json.example", "utf8"));
|
||||||
|
// eslint-disable-next-line no-empty
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
const content = req.body;
|
||||||
|
|
||||||
|
for (const key in content)
|
||||||
|
if (key in original && content[key])
|
||||||
|
original[key] = content[key];
|
||||||
|
|
||||||
|
fs.writeFileSync("./config.json", JSON.stringify(original, null, 4));
|
||||||
|
require.cache[require.resolve("../config.json")] = require("../config.json");
|
||||||
|
res.redirect("/register");
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = app;
|
Loading…
Reference in a new issue