2019-11-17 02:27:32 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const express = require("express");
|
2020-01-11 16:48:56 +00:00
|
|
|
const jsdom = require("jsdom").JSDOM;
|
|
|
|
const options = {
|
2020-01-12 09:38:32 +00:00
|
|
|
resources: "usable"
|
2020-01-11 16:48:56 +00:00
|
|
|
};
|
2020-01-12 09:38:32 +00:00
|
|
|
const { updateHTML } = require("./populate");
|
|
|
|
const { populateCSS, populateConfig } = require("./build");
|
|
|
|
const { updateCommand } = require("./update");
|
2019-11-17 02:27:32 +00:00
|
|
|
const app = express();
|
|
|
|
app.set("view engine", "ejs");
|
|
|
|
app.use(express.static(__dirname + "/views"));
|
|
|
|
app.set("views", __dirname + "/views");
|
|
|
|
app.use(
|
2020-01-12 09:38:32 +00:00
|
|
|
express.json({
|
|
|
|
limit: "50mb"
|
|
|
|
})
|
2019-11-17 02:27:32 +00:00
|
|
|
);
|
|
|
|
app.use(
|
2020-01-12 09:38:32 +00:00
|
|
|
express.urlencoded({
|
|
|
|
limit: "50mb",
|
|
|
|
extended: true
|
|
|
|
})
|
2019-11-17 02:27:32 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const port = 3000;
|
|
|
|
|
|
|
|
global.DOMParser = new jsdom().window.DOMParser;
|
|
|
|
|
2019-12-11 15:02:03 +00:00
|
|
|
function uiCommand() {
|
2020-01-12 09:38:32 +00:00
|
|
|
app.get("/", (req, res) => {
|
|
|
|
res.render("index.ejs");
|
|
|
|
});
|
2020-01-11 16:48:56 +00:00
|
|
|
|
2020-01-12 09:38:32 +00:00
|
|
|
app.get("/update", (req, res) => {
|
|
|
|
if (!fs.existsSync(`${outDir}/config.json`)) {
|
|
|
|
return res.send(
|
|
|
|
'You need to run build command before using update<br><a href="/">Go Back</a>'
|
|
|
|
);
|
|
|
|
}
|
2020-01-11 16:48:56 +00:00
|
|
|
|
2020-01-12 09:38:32 +00:00
|
|
|
updateCommand();
|
|
|
|
res.redirect("/");
|
|
|
|
});
|
2019-11-17 02:27:32 +00:00
|
|
|
|
2020-01-12 09:38:32 +00:00
|
|
|
app.post("/build", (req, res) => {
|
|
|
|
const { username } = req.body;
|
|
|
|
if (!username) {
|
|
|
|
return res.send("username can't be empty");
|
|
|
|
}
|
2019-11-17 02:27:32 +00:00
|
|
|
|
2020-01-12 09:38:32 +00:00
|
|
|
const sort = req.body.sort ? req.body.sort : "created";
|
|
|
|
const order = req.body.order ? req.body.order : "asc";
|
|
|
|
const includeFork = req.body.fork === "true";
|
|
|
|
const types = ["owner"];
|
|
|
|
const codepen = req.body.codepen ? req.body.codepen : null;
|
|
|
|
const dev = req.body.dev ? req.body.dev : null;
|
|
|
|
const dribbble = req.body.dribbble ? req.body.dribbble : null;
|
|
|
|
const email = req.body.email ? req.body.email : null;
|
|
|
|
const instagram = req.body.instagram ? req.body.instagram : null;
|
|
|
|
const reddit = req.body.reddit ? req.body.reddit : null;
|
|
|
|
const telegram = req.body.telegram ? req.body.telegram : null;
|
|
|
|
const twitter = req.body.twitter ? req.body.twitter : null;
|
|
|
|
const background = req.body.background
|
|
|
|
? req.body.background
|
|
|
|
: "https://source.unsplash.com/1280x720/?wallpaper";
|
|
|
|
const theme = req.body.theme === "on" ? "dark" : "light";
|
|
|
|
const opts = {
|
|
|
|
sort,
|
|
|
|
order,
|
|
|
|
includeFork,
|
|
|
|
types,
|
|
|
|
codepen,
|
|
|
|
dev,
|
|
|
|
dribbble,
|
|
|
|
email,
|
|
|
|
instagram,
|
|
|
|
reddit,
|
|
|
|
telegram,
|
|
|
|
twitter
|
|
|
|
};
|
2019-11-17 02:27:32 +00:00
|
|
|
|
2020-01-12 09:38:32 +00:00
|
|
|
updateHTML(username, opts);
|
|
|
|
populateCSS({
|
|
|
|
background,
|
|
|
|
theme
|
|
|
|
});
|
|
|
|
populateConfig(opts);
|
|
|
|
res.redirect("/");
|
|
|
|
});
|
2019-11-17 02:27:32 +00:00
|
|
|
|
2020-01-12 09:38:32 +00:00
|
|
|
console.log("\nStarting...");
|
|
|
|
app.listen(port);
|
|
|
|
console.log(
|
|
|
|
`The GUI is running on port ${port}, Navigate to http://localhost:${port} in your browser\n`
|
|
|
|
);
|
2019-11-17 02:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2020-01-12 09:38:32 +00:00
|
|
|
uiCommand
|
2019-12-11 15:02:03 +00:00
|
|
|
};
|