dsql-admin/dsql-app/.local_dist/server/pages/api/contact.js
Benjamin Toby 885c11f674 Updates
2025-01-14 07:42:13 +01:00

19 lines
3.8 KiB
JavaScript

"use strict";(()=>{var e={};e.id=3409,e.ids=[3409],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},21572:e=>{e.exports=require("nodemailer")},29021:e=>{e.exports=require("fs")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},63133:(e,r,t)=>{t.r(r),t.d(r,{config:()=>d,default:()=>u,routeModule:()=>m});var n={};t.r(n),t.d(n,{default:()=>c});var s=t(89947),a=t(2706),o=t(96762),i=t(96052),l=t(67619);async function c(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let{name:t,email:n,message:s}=e.body;if(!n.match(/.*@.*\..*/))return r.json({success:!1,msg:"Invalid Email"});if(!t.match(/./)||!s.match(/./))return r.json({success:!1,msg:"Please Fill in all Fields"});try{(await (0,i.A)({to:process.env.DSQL_CONTACT_EMAIL,html:`
<h2>Message From ${t}, ${n}</h2>
<p>${s}</p>
`,subject:"Contact Form Submission",text:`Message from ${t}, ${n}`})).messageId?r.json({success:!0}):r.json({success:!1,msg:"Message Sending Failed"})}catch(e){(0,l.A)({component:"/api/contact/main-catch-error",message:e.message}),r.json({success:!1,msg:"Database Files could not be written!"})}}let u=(0,o.M)(n,"default"),d=(0,o.M)(n,"config"),m=new s.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/contact",pathname:"/api/contact",bundlePath:"",filename:""},userland:n})},96052:(e,r,t)=>{t.d(r,{A:()=>i});var n=t(29021),s=t.n(n),a=t(21572);let o=t.n(a)().createTransport({host:process.env.DSQL_MAIL_HOST,port:465,secure:!0,auth:{user:process.env.DSQL_MAIL_EMAIL,pass:process.env.DSQL_MAIL_PASSWORD}});async function i({to:e,subject:r,text:t,html:n,alias:a,senderName:i}){let l;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let c=(a?.match(/support/i),process.env.DSQL_MAIL_EMAIL);if(!s().existsSync("./email/index.html"))return;let u=s().readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,n||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let n={};n.from=`"${i||"Datasquirel"}" <${c}>`,n.sender=c,a&&(n.replyTo=c),n.to=e,n.subject=r,n.text=t,n.html=u,l=await o.sendMail(n)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return l}},67619:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(29021),s=t.n(n);async function a({user:e,message:r,component:t,noMail:n,req:a}){let o=new Date,i=(()=>{if(!a)return null;try{let e=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],t=a.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||n||r||a.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let n=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(n+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),a?.url&&(n+=`
URL: ${a.url}`),a?.body&&(n+=`
Request Body: ${JSON.stringify(a.body,null,4)}`),i&&(n+=`
IP: ${i}`),n+=`
Date: ${o.toDateString()}
========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let l=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",n),s().appendFileSync("./.tmp/error.log",`
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}});var t=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=r(r.s=63133);module.exports=t})();