Parcourir la source

get support email

Pouria Ezzati il y a 1 an
Parent
commit
ee331a6e1e

+ 1 - 0
server/handlers/locals.handler.js

@@ -23,6 +23,7 @@ function viewTemplate(template) {
 function config(req, res, next) {
   res.locals.default_domain = env.DEFAULT_DOMAIN;
   res.locals.site_name = env.SITE_NAME;
+  res.locals.contact_email = env.CONTACT_EMAIL;
   res.locals.server_ip_address = env.SERVER_IP_ADDRESS;
   next();
 }

+ 11 - 0
server/handlers/renders.handler.js

@@ -146,6 +146,16 @@ async function getReportEmail(req, res) {
   });
 }
 
+async function getSupportEmail(req, res) {
+  if (!env.CONTACT_EMAIL) {
+    throw new utils.CustomError("No support email is available.", 400);
+  }
+  await utils.sleep(500);
+  res.render("partials/support_email", {
+    email: env.CONTACT_EMAIL,
+  });
+}
+
 async function linkEdit(req, res) {
   const link = await query.link.find({
     uuid: req.params.id,
@@ -163,6 +173,7 @@ module.exports = {
   confirmLinkBan,
   confirmLinkDelete,
   getReportEmail,
+  getSupportEmail,
   homepage,
   linkEdit,
   login,

+ 7 - 0
server/routes/renders.routes.js

@@ -146,4 +146,11 @@ router.get(
   asyncHandler(renders.getReportEmail)
 );
 
+router.get(
+  "/get-support-email", 
+  locals.noLayout,
+  locals.viewTemplate("partials/support_email"),
+  asyncHandler(renders.getSupportEmail)
+);
+
 module.exports = router;

+ 8 - 2
server/views/partials/footer.hbs

@@ -3,7 +3,13 @@
     Made with love by <a href="https://thedevs.network" title="The Devs" target="_blank" rel="noopener noreferrer">The Devs</a>. <span>|</span> 
     <a href="https://github.com/thedevs-network/kutt" title="GitHub" target="_blank" rel="noopener noreferrer">GitHub</a> <span>|</span> 
     <a href="/terms" title="Terms of Service">Terms of Service</a> <span>|</span>
-    <a href="/report" title="Report abuse">Report Abuse</a> <span>|</span> 
-    <a href="mailto:support@kutt.it" title="Contact us">Contact us</a>
+    <a href="/report" title="Report abuse">Report Abuse</a> 
+    {{#if contact_email}}
+      <span>|</span> 
+      <button class="link" hx-get="/get-support-email" hx-swap="outerHTML">
+        <span>{{> icons/spinner}}</span>
+        Contact us
+      </button>
+    {{/if}}
   </p>
 </footer>

+ 1 - 0
server/views/partials/support_email.hbs

@@ -0,0 +1 @@
+<a href="mailto:{{email}}" title="Contact us">{{email}}</a>

+ 13 - 0
static/css/styles.css

@@ -1598,6 +1598,19 @@ footer {
   text-align: center;
 }
 
+footer button.link {
+  display: inline-block;
+  font-size: 13px;
+}
+
+footer button.link .spinner {
+  display: none;
+  width: 1em;
+  margin: 0 0 -2px;
+}
+
+footer button.link.htmx-request .spinner { display: inline; }
+
 /* SETTINGS */
 
 #settings {