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