dsql-admin/dsql-app/.local_dist/server/pages/api/updateUser.js

28 lines
11 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"use strict";(()=>{var e={};e.id=8925,e.ids=[8925],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},34229:e=>{e.exports=require("node-fetch")},21572:e=>{e.exports=require("nodemailer")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},9288:e=>{e.exports=require("sharp")},79428:e=>{e.exports=require("buffer")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},96762:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,r){return r in t?t[r]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,r)):"function"==typeof t&&"default"===r?t:void 0}}})},43359:(e,t,r)=>{r.r(t),r.d(t,{config:()=>L,default:()=>E,routeModule:()=>A});var s={};r.r(s),r.d(s,{default:()=>D});var a=r(89947),n=r(2706),i=r(96762),o=r(51348),l=r.n(o);r(82703);var u=r(17662),c=r.n(u);r(79531);var p=r(77538),d=r.n(p),S=r(6420),m=r.n(S),f=r(33873),_=r.n(f),g=r(79646),h=r(33364),y=r.n(h);async function D(e,t){if("POST"!==e.method)return t.json({user:null,msg:"Registration Failed!"});let r=await m()(e,t,!0);if(!r)return t.json({success:!1,msg:"Unauthorized"});let{first_name:s,last_name:a,image:n}=e.body;try{let e=(await l()(`SELECT image FROM users WHERE id='${r.id}'`))[0].image===n,i=process.env.DSQL_STATIC_SERVER_DIR;if(!i)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let o=_().join(i,`images/user-images/user-${r.id}/user-${r.id}-profile.jpg`),u=_().join(i,`images/user-images/user-${r.id}/user-${r.id}-profile-thumbnail.jpg`);e||(await c()({imageSourceUrl:"string"==typeof n?n:n.imageBase64,imageWritePath:o,sourceType:"string"==typeof n?"url":"base64"}),await c()({imageSourceUrl:"string"==typeof n?n:n.imageBase64,imageWritePath:u,maxSize:250,sourceType:"string"==typeof n?"url":"base64"}),(0,g.execSync)(`chmod 644 ${o} ${u}`));let p=o.replace(i,process.env.DSQL_STATIC_HOST||""),d=u.replace(i,process.env.DSQL_STATIC_HOST||"");await y()({dbFullName:"datasquirel",tableName:"users",identifierColumnName:"id",identifierValue:r.id,data:{first_name:s,last_name:a,image:p,image_thumbnail:d}}),await y()({dbFullName:"datasquirel",tableName:"user_users",identifierColumnName:"invited_user_id",identifierValue:r.id,data:{first_name:s,last_name:a,image:p,image_thumbnail:d}}),t.json({user:!0})}catch(e){d()({component:"/api/updateUser/main-catch-error",message:e.message,user:r}),t.json({user:null})}}r(29021);let E=(0,i.M)(s,"default"),L=(0,i.M)(s,"config"),A=new a.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/updateUser",pathname:"/api/updateUser",bundlePath:"",filename:""},userland:s})},17662:(e,t,r)=>{let s=r(34229),a=r(9288),n=r(77538);e.exports=async function({imageSourceUrl:e,imageWritePath:t,maxSize:r,sourceType:i}){try{async function o(){let t;if(i?.match("url")){if(e.match(/^http/i)){let r=await s(e,{});t=await r.buffer()}else t=`./public${e}`}else i?.match("base64")&&(t=Buffer.from(e,"base64"));return t}let n=await o(),l=r||650,u=a(n),{width:c,height:p,format:d}=await u.metadata();if(c&&p&&c>l){let e=l/c;u.resize(l,Math.round(p*e),{fit:"cover"})}d&&u.toFormat(d,{quality:80}),await u.toFile(t)}catch(e){n({component:"functions/backend/fsWriteImageToDisk",message:e.message})}}},79531:(e,t,r)=>{let s=r(29021),a=r(21572).createTransport({host:process.env.DSQL_MAIL_HOST,port:465,secure:!0,auth:{user:process.env.DSQL_MAIL_EMAIL,pass:process.env.DSQL_MAIL_PASSWORD}});e.exports=async function({to:e,subject:t,text:r,html:n,alias:i}){let o;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let l=(i?.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 s={};s.from=`"Datasquirel" <${l}>`,s.sender=l,i&&(s["replyTo "]=l),s.to=e,s.subject=t,s.text=r,s
Error Message: ${t}
Component: ${r}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),n?.url&&(a+=`
URL: ${n.url}`),n?.body&&(a+=`
Request Body: ${JSON.stringify(n.body,null,4)}`),o&&(a+=`
IP: ${o}`),a+=`
Date: ${i.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",a),s.appendFileSync("./.tmp/error.log",`
2024-11-05 11:12:42 +00:00
2024-12-05 07:03:33 +00:00
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,t,r)=>{r(81630);let s=r(51348),a=r(72907),n=r(29021);async function i(e,t,r,i){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let o=a(e.cookies.datasquirelAuthKey);if(!o)return null;let l=JSON.parse(o);if(!l.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${l.csrf_k}`)))return null;let u=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!u)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!n.existsSync(`${u}/${l.csrf_k}`))return null;if(0==l.verification_status&&!r){let e=await s(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return l?.date&&Date.now()-l.date>6048e5?null:l}e.exports=i},33364:(e,t,r)=>{let s=r(82703),a=r(72583),n=r(16570),i=r(51348),o=r(21339);async function l({dbContext:e,paradigm:t,dbFullName:r,tableName:l,data:u,tableSchema:c,identifierColumnName:p,identifierValue:d,encryptionKey:S,encryptionSalt:m}){if(!u||!Object.keys(u).length)return null;let f=!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),_=f?i:o,g=Object.keys(u),h=[],y=[];for(let e=0;e<g.length;e++)try{let t=g[e],r=u[t],i=c?c?.fields?.filter(e=>e.fieldName===t):null,o=i&&i[0]?i[0]:null;if(null==r||void 0==r)continue;o?.richText&&(r=a(r,n)),o?.encrypted&&(r=s(r,S,m)),"object"==typeof r&&(r=JSON.stringify(r)),o?.pattern&&!new RegExp(o.pattern,o.patternFlags||"").test(r)&&(console.log("DSQL: Pattern not matched =>",r),r=""),"string"==typeof r&&r.match(/^null$/i)&&(r={toSqlString:function(){return"NULL"}}),"string"!=typeof r||r.match(/./i)||(r={toSqlString:function(){return"NULL"}}),h.push(`\`${t}\`=?`),"number"==typeof r?y.push(String(r)):y.push(r)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}h.push(`date_updated='${Date()}'`),h.push(`date_updated_code='${Date.now()}'`);let D=`UPDATE ${l} SET ${h.join(",")} WHERE \`${p}\`=?`;return y.push(d),f?await _(D,y):await _({paradigm:t,database:r,queryString:D,queryValues:y})}e.exports=l},72907:(e,t,r)=>{let{scryptSync:s,createDecipheriv:a}=r(55511),{Buffer:n}=r(79428);e.exports=e=>{let t=a("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),n.alloc(16,0));try{let r=t.update(e,"hex","utf8");return r+=t.final("utf8")}catch(e){return null}}},82703:(e,t,r)=>{let{scryptSync:s,createCipheriv:a}=r(55511),{Buffer:n}=r(79428),i=r(48225);e.exports=(e,t,r)=>{let o=a("aes-192-cbc",s(t||process.env.DSQL_ENCRYPTION_PASSWORD||"",r||process.env.DSQL_ENCRYPTION_SALT||"",24),n.alloc(16,0));try{let t=o.update(e,"utf8","hex");return t+=o.final("hex")}catch(e){return i({component:"encrypt",message:e.message}),null}}},16570:e=>{e.exports={allowedTags:["b","i","em","strong","a","p","span","ul","ol","li","h1","h2","h3","h4","h5","h6","img","div","button","pre","code","br"],allowedAttributes:{a:["href"],img:["src","alt","width","height","class","style"],"*":["style","class"]}}},48225:(e,t,r)=>{let s=r(29021);e.exports=async function({user:e,message:t,component:r,noMail:a}){let n=`🚀 SERVER ERROR ===========================
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}
Error Message: ${t}
Component: ${r}
Date: ${Date()}
========================================`;s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let i=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",n),s.appendFileSync("./.tmp/error.log",`
2024-11-05 11:12:42 +00:00
2024-12-05 07:03:33 +00:00
${i}`)}},51348:(e,t,r)=>{let s=r(9973),a=r(21580),n=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:a()}});async function i(...e){try{let t=await n.query(...e);return await n.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=i},21339:(e,t,r)=>{let s=r(29021);r(33873);let a=r(9973),n=r(21580),i=a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,charset:"utf8mb4",ssl:n()}});e.exports=function({paradigm:e,database:t,queryString:r,queryValues:o}){try{return new Promise((l,u)=>{let c=!!e?.match(/full.access|^fa$/i);try{function p(e){i.end(),l(JSON.parse(JSON.stringify(e)))}function d(e){i.end(),l({error:e.message,queryStringGenerated:r,queryValuesGenerated:o,sql:e.sql})}i=c?a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,database:t,ssl:n()}}):a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,database:t,ssl:n()}}),o&&Array.isArray(o)&&o[0]?i.query(r,o).then(p).catch(d):i.query(r).then(p).catch(d)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),l({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},21580:(e,t,r)=>{let s=r(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let t=`${e}/ca-cert.pem`;if(!s.existsSync(t)){console.log(`${t} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,t)=>{var r;Object.defineProperty(t,"A",{enumerable:!0,get:function(){return r}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(r||(r={}))},89947:(e,t,r)=>{e.exports=r(75600)}};var t=require("../../webpack-api-runtime.js");t.C(e);var r=t(t.s=43359);module.exports=r})();