2024-09-12 14:26:39 +03:30
|
|
|
const query = require("../queries");
|
2024-08-21 21:22:59 +03:30
|
|
|
const utils = require("../utils");
|
|
|
|
const env = require("../env");
|
|
|
|
|
|
|
|
async function homepage(req, res) {
|
|
|
|
res.render("homepage", {
|
|
|
|
title: "Modern open source URL shortener",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function login(req, res) {
|
|
|
|
if (req.user) {
|
2024-09-12 14:26:39 +03:30
|
|
|
res.redirect("/");
|
|
|
|
return;
|
2024-08-21 21:22:59 +03:30
|
|
|
}
|
|
|
|
res.render("login", {
|
|
|
|
title: "Log in or sign up"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function logout(req, res) {
|
2024-09-12 14:26:39 +03:30
|
|
|
utils.deleteCurrentToken(res);
|
2024-08-21 21:22:59 +03:30
|
|
|
res.render("logout", {
|
|
|
|
title: "Logging out.."
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-09-08 14:10:02 +03:30
|
|
|
function notFound(req, res) {
|
|
|
|
res.render("404", {
|
|
|
|
title: "404 - Not found"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-08-31 12:19:39 +03:30
|
|
|
function settings(req, res) {
|
|
|
|
res.render("settings", {
|
|
|
|
title: "Settings"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-09-08 14:10:02 +03:30
|
|
|
function stats(req, res) {
|
|
|
|
res.render("stats", {
|
|
|
|
title: "Stats"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function banned(req, res) {
|
|
|
|
res.render("banned", {
|
|
|
|
title: "Banned link",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function report(req, res) {
|
|
|
|
res.render("report", {
|
|
|
|
title: "Report abuse",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function resetPassword(req, res) {
|
|
|
|
res.render("reset_password", {
|
|
|
|
title: "Reset password",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function resetPasswordResult(req, res) {
|
|
|
|
res.render("reset_password_result", {
|
|
|
|
title: "Reset password",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function verifyChangeEmail(req, res) {
|
|
|
|
res.render("verify_change_email", {
|
|
|
|
title: "Verifying email",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function verify(req, res) {
|
|
|
|
res.render("verify", {
|
|
|
|
title: "Verify",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function terms(req, res) {
|
|
|
|
res.render("terms", {
|
|
|
|
title: "Terms of Service",
|
|
|
|
});
|
|
|
|
}
|
2024-08-31 12:19:39 +03:30
|
|
|
|
2024-08-21 21:22:59 +03:30
|
|
|
async function confirmLinkDelete(req, res) {
|
|
|
|
const link = await query.link.find({
|
|
|
|
uuid: req.query.id,
|
|
|
|
...(!req.user.admin && { user_id: req.user.id })
|
|
|
|
});
|
|
|
|
if (!link) {
|
2024-08-31 12:19:39 +03:30
|
|
|
return res.render("partials/links/dialog/message", {
|
2024-08-21 21:22:59 +03:30
|
|
|
layout: false,
|
|
|
|
message: "Could not find the link."
|
|
|
|
});
|
|
|
|
}
|
2024-08-31 12:19:39 +03:30
|
|
|
res.render("partials/links/dialog/delete", {
|
2024-08-21 21:22:59 +03:30
|
|
|
layout: false,
|
|
|
|
link: utils.getShortURL(link.address, link.domain).link,
|
|
|
|
id: link.uuid
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-08-31 12:19:39 +03:30
|
|
|
async function confirmLinkBan(req, res) {
|
|
|
|
const link = await query.link.find({
|
|
|
|
uuid: req.query.id,
|
|
|
|
...(!req.user.admin && { user_id: req.user.id })
|
|
|
|
});
|
|
|
|
if (!link) {
|
|
|
|
return res.render("partials/links/dialog/message", {
|
|
|
|
message: "Could not find the link."
|
|
|
|
});
|
|
|
|
}
|
|
|
|
res.render("partials/links/dialog/ban", {
|
|
|
|
link: utils.getShortURL(link.address, link.domain).link,
|
|
|
|
id: link.uuid
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function addDomainForm(req, res) {
|
|
|
|
res.render("partials/settings/domain/add_form");
|
|
|
|
}
|
|
|
|
|
|
|
|
async function confirmDomainDelete(req, res) {
|
|
|
|
const domain = await query.domain.find({
|
|
|
|
uuid: req.query.id,
|
|
|
|
user_id: req.user.id
|
|
|
|
});
|
|
|
|
if (!domain) {
|
|
|
|
throw new utils.CustomError("Could not find the link", 400);
|
|
|
|
}
|
|
|
|
res.render("partials/settings/domain/delete", {
|
|
|
|
...utils.sanitize.domain(domain)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-08 14:10:02 +03:30
|
|
|
async function getReportEmail(req, res) {
|
|
|
|
if (!env.REPORT_EMAIL) {
|
|
|
|
throw new utils.CustomError("No report email is available.", 400);
|
|
|
|
}
|
|
|
|
res.render("partials/report/email", {
|
|
|
|
report_email: env.REPORT_EMAIL.replace("@", "[at]")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-08-21 21:22:59 +03:30
|
|
|
async function linkEdit(req, res) {
|
|
|
|
const link = await query.link.find({
|
|
|
|
uuid: req.params.id,
|
|
|
|
...(!req.user.admin && { user_id: req.user.id })
|
|
|
|
});
|
|
|
|
res.render("partials/links/edit", {
|
2024-09-12 14:26:39 +03:30
|
|
|
...(!link && utils.sanitize.link(link)),
|
2024-08-21 21:22:59 +03:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2024-08-31 12:19:39 +03:30
|
|
|
addDomainForm,
|
2024-09-08 14:10:02 +03:30
|
|
|
banned,
|
|
|
|
confirmDomainDelete,
|
|
|
|
confirmLinkBan,
|
|
|
|
confirmLinkDelete,
|
|
|
|
getReportEmail,
|
2024-08-21 21:22:59 +03:30
|
|
|
homepage,
|
|
|
|
linkEdit,
|
|
|
|
login,
|
|
|
|
logout,
|
2024-09-08 14:10:02 +03:30
|
|
|
notFound,
|
|
|
|
report,
|
|
|
|
resetPassword,
|
|
|
|
resetPasswordResult,
|
2024-08-31 12:19:39 +03:30
|
|
|
settings,
|
2024-09-08 14:10:02 +03:30
|
|
|
stats,
|
|
|
|
terms,
|
|
|
|
verifyChangeEmail,
|
|
|
|
verify,
|
2024-08-21 21:22:59 +03:30
|
|
|
}
|