~nicohman/ravenserver

715a0b0bb501cd1e9c77c1a42cdbcc35be64ba7c — Nico Hickman 2 years ago dbccd4b + 6bf2d06
Merge branch 'master' of https://github.com/nicohman/ravenserver
3 files changed, 79 insertions(+), 100 deletions(-)

M app.js
D public/downloads.ejs
M public/views/header.ejs
M app.js => app.js +77 -68
@@ 9,7 9,6 @@ var formidable = require("formidable");
var path = require("path");
var bcrypt = require("bcrypt");
var shahash = require('crypto');
var shahash = require('crypto');
var md5 = require("nodejs-md5");
var jwt = require("jsonwebtoken");
var bodyParser = require('body-parser');


@@ 18,7 17,9 @@ var privKey = fs.readFileSync("/etc/letsencrypt/live/demenses.net/privkey.pem",
var cert = fs.readFileSync("/etc/letsencrypt/live/demenses.net/fullchain.pem",
    "utf8");
var config = require("./config.json");
var downloads = require("./downloads.json");
if (config.include_downloads) {
    var downloads = require("./downloads.json");
}
var san = require("sanitizer");
var request = require("request");
var nodemailer = require("nodemailer");


@@ 151,7 152,8 @@ var getThemes = function(req, res) {
        ejs.renderFile("public/themes.ejs", {
            themes: themes,
            ptitle: "All themes",
            constraints: "Sorted by total installs"
            constraints: "Sorted by total installs",
            include_downloads: config.include_downloads
        }, function(err, str) {
            if (err) {
                console.error(err);


@@ 163,7 165,8 @@ var getThemes = function(req, res) {
app.get("/themes/report/:name", function(req, res) {
    ejs.renderFile("public/report.ejs", {
        name: req.params.name,
        ptitle: "Report a Theme"
        ptitle: "Report a Theme",
        include_downloads: config.include_downloads
    }, function(err, str) {
        if (err) {
            console.error(err);


@@ 174,7 177,8 @@ app.get("/themes/report/:name", function(req, res) {
app.get("/themes/report", function(req, res) {
    ejs.renderFile("public/report.ejs", {
        name: "",
        ptitle: "Report a Theme"
        ptitle: "Report a Theme",
        include_downloads: config.include_downloads
    }, function(err, str) {
        if (err) {
            console.error(err);


@@ 239,7 243,8 @@ app.get("/recent", function(req, res) {
        ejs.renderFile("public/themes.ejs", {
            themes: themes,
            ptitle: "All themes",
            constraints: "Sorted by most recent"
            constraints: "Sorted by most recent",
            include_downloads: config.include_downloads
        }, function(err, str) {
            if (err) {
                console.error(err);


@@ 249,7 254,9 @@ app.get("/recent", function(req, res) {
    });
});
app.get("/about", function(req, res) {
    ejs.renderFile("public/about.ejs", function(err, str) {
    ejs.renderFile("public/about.ejs", {
        include_downloads: config.include_downloads
    }, function(err, str) {
        if (err) {
            console.error(err);
        }


@@ 258,56 265,56 @@ app.get("/about", function(req, res) {
});
app.get("/downloads", function(req, res) {
    res.redirect("https://nicohman.demenses.net/downloads");

});
app.get("/checksums", function(req, res) {
    var sums = {};
    md5.file("public/static/raven-nightly", function(err, rsum) {
        if (err) {
            console.err(err);
        } else {
            md5.file("public/static/ravend-nightly", function(err, rdsum) {
                if (err) {
                    console.err(er);
                } else {
                    md5.file("public/static/eidolon-nightly", function(err, esum) {
                        if (err) {
                            console.err(err);
                        } else {
                            md5.file("public/static/graven-nightly", function(err, gsum) {
                                if (err) {
                                    console.err(err);
                                } else {
                                    md5.file("public/static/wyvern-nightly", function(err, wsum) {
                                        if (err) {
                                            console.err(err);
                                        } else {
                                            sums.raven = rsum;
                                            sums.ravend = rdsum;
                                            sums.eidolon = esum;
                                            sums.graven = gsum;
                                            sums.wyvern = wsum;
                                            ejs.renderFile("public/checksums.ejs", {
                                                sums: sums
                                            }, function(err, str) {
                                                if (err) {
                                                    console.err(err);
                                                }
                                                res.send(str);
                                            });
                                        }
                                    });
                                }
                            });
                        }
                    });
                }
            });
        }
    });

});
if (config.include_downloads) {
    app.get("/checksums", function(req, res) {
        var sums = {};
        md5.file("public/static/raven-nightly", function(err, rsum) {
            if (err) {
                console.err(err);
            } else {
                md5.file("public/static/ravend-nightly", function(err, rdsum) {
                    if (err) {
                        console.err(er);
                    } else {
                        md5.file("public/static/eidolon-nightly", function(err, esum) {
                            if (err) {
                                console.err(err);
                            } else {
                                md5.file("public/static/graven-nightly", function(err, gsum) {
                                    if (err) {
                                        console.err(err);
                                    } else {
                                        md5.file("public/static/wyvern-nightly", function(err, wsum) {
                                            if (err) {
                                                console.err(err);
                                            } else {
                                                sums.raven = rsum;
                                                sums.ravend = rdsum;
                                                sums.eidolon = esum;
                                                sums.graven = gsum;
                                                sums.wyvern = wsum;
                                                ejs.renderFile("public/checksums.ejs", {
                                                    sums: sums
                                                }, function(err, str) {
                                                    if (err) {
                                                        console.err(err);
                                                    }
                                                    res.send(str);
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });

    });
}
app.get("/themes/users/view/:id", function(req, res) {
    Theme.find({
        author: req.params.id


@@ 319,7 326,8 @@ app.get("/themes/users/view/:id", function(req, res) {
                ejs.renderFile("public/themes.ejs", {
                    themes: themes,
                    ptitle: "All themes by " + themes[0].pauthor,
                    constraints: ""
                    constraints: "",
                    include_downloads: config.include_downloads
                }, function(err, str) {
                    if (err) {
                        console.error(err);


@@ 344,7 352,8 @@ app.get("/themes/view/:name", function(req, res) {
            if (theme) {
                console.log(theme);
                ejs.renderFile("public/theme.ejs", {
                    theme: theme
                    theme: theme,
                    include_downloads: config.include_downloads
                }, function(err, str) {
                    if (err) {
                        console.error(err);


@@ 366,7 375,6 @@ var upTheme = function(req, res) {
    } else {
        jwt.verify(req.query.token, config.secret, function(err, un) {
            if (!err) {
                console.log("1");
                if (req.query.name && req.query.name.length > 200) {
                    res.status(413).send();
                } else if (req.query.name) {


@@ 543,19 551,20 @@ app.post("/themes/users/delete/:user", function(req, res) {
        res.status(401).send();
    }
});

function downloadsCounter(req, res, next) {
    if (req.path.includes("nightly")) {
        if (downloads[req.path]) {
            downloads[req.path]++;
        } else {
            downloads[req.path] = 1;
if (config.include_downloads) {
    function downloadsCounter(req, res, next) {
        if (req.path.includes("nightly")) {
            if (downloads[req.path]) {
                downloads[req.path]++;
            } else {
                downloads[req.path] = 1;
            }
            fs.writeFile("downloads.json", JSON.stringify(downloads), function() {});
        }
        fs.writeFile("downloads.json", JSON.stringify(downloads), function() {});
        next();
    }
    next();
    app.use(downloadsCounter);
}
app.use(downloadsCounter);
app.use(express.static("/home/nicohman/ravenserver/public/static"));
app.post("/themes/delete/:name", function(req, res) {
    if (req.query.token) {

D public/downloads.ejs => public/downloads.ejs +0 -32
@@ 1,32 0,0 @@
<html>
	<head>
		<title>Raven Downloads</title>
		<link rel="stylesheet" href="/stylesheet.css">
	</head>
	<body>
		<%- include("views/header", {ptitle:"Raven Downloads", constraints:""}); %>
		<div id="about-div">
			<h3> Downloads </h3>
			If you want to download raven, you have a few options:
			<ul>
				<li>
					Build it from source <a href="https://git.sr.ht/~nicohman/raven" class="raven-link">here</a>
				</li>
				<li>
					Install it from <a href="https://crates.io/crates/raventhemer" class="raven-link">crates.io</a>
				</li>
			</ul>
			<h5> Or, you can download binaries from here, built from the latest git version. </h5>
			<a href="/raven-nightly" class="raven-link"> Raven</a><br>
			<%= sums.raven %><br>
			<a href="/ravend-nightly" class="raven-link"> Ravend</a><br>
			<%= sums.ravend %>
			<h5> <a href="https://git.sr.ht/~nicohman/graven">graven</a> is a GUI for raven, currently in <strong>alpha</strong>. Don't expect too much!</h5>
			<a href="/graven-nightly" class="raven-link"> Graven</a><br>
			<%= sums.graven %>
			<h5> This website also hosts auto-compiled binaries of <a href="https://git.sr.ht/~nicohman/eidolon" class="raven-link">eidolon</h5>
				<a href="/eidolon-nightly" class="raven-link"> Eidolon</a><br>
				<%= sums.eidolon %><br>
			</div>
		</body>
	</html>
\ No newline at end of file

M public/views/header.ejs => public/views/header.ejs +2 -0
@@ 20,11 20,13 @@
				About
			</a>
		</div>
		<% if (include_downloads) %>
		<div id ="header-downloads">
			<a href="/downloads">
				Downloads
			</a>
		</div>
		<% } %>
	</div>
	<div id="header-ptitle">
		<%= ptitle %>