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

16 lines
11 KiB
JavaScript
Raw Normal View History

2025-02-16 16:12:40 +00:00
"use strict";(()=>{var e={};e.id=8925,e.ids=[8925],e.modules={76102:e=>{e.exports=require("@moduletrace/datasquirel/dist/client")},39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/users/user-auth")},65967:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson")},93726:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy")},30889:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},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")},33873:e=>{e.exports=require("path")},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}}})},58240:(e,r,t)=>{t.r(r),t.d(r,{config:()=>A,default:()=>y,routeModule:()=>E});var n={};t.r(n),t.d(n,{default:()=>h});var a=t(89947),s=t(2706),o=t(96762),i=t(48786);let l=require("node-fetch");var u=t.n(l),c=t(9288),p=t.n(c),d=t(67619);async function _({imageSourceUrl:e,imageWritePath:r,maxSize:t,sourceType:n}){try{async function a(){let r;if(n?.match("url")){if(e.match(/^http/i)){let t=await u()(e,{});r=await t.buffer()}else r=`./public${e}`}else n?.match("base64")&&(r=Buffer.from(e,"base64"));return r}let s=await a(),o=t||650,i=p()(s),{width:l,height:c,format:d}=await i.metadata();if(l&&c&&l>o){let e=o/l;i.resize(o,Math.round(c*e),{fit:"cover"})}d&&i.toFormat(d,{quality:80}),await i.toFile(r)}catch(e){(0,d.A)({component:"functions/backend/fsWriteImageToDisk",message:e.message})}}var S=t(69842),f=t(33873),g=t.n(f),m=t(79646),D=t(30802);async function h(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await (0,S.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{first_name:n,last_name:a,image:s}=e.body;try{let e=(await (0,i.A)(`SELECT image FROM users WHERE id='${t.id}'`))[0].image===s,o=process.env.DSQL_STATIC_SERVER_DIR;if(!o)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let l=g().join(o,`images/user-images/user-${t.id}/user-${t.id}-profile.jpg`),u=g().join(o,`images/user-images/user-${t.id}/user-${t.id}-profile-thumbnail.jpg`);e||(await _({imageSourceUrl:"string"==typeof s?s:s.imageBase64,imageWritePath:l,sourceType:"string"==typeof s?"url":"base64"}),await _({imageSourceUrl:"string"==typeof s?s:s.imageBase64,imageWritePath:u,maxSize:250,sourceType:"string"==typeof s?"url":"base64"}),(0,m.execSync)(`chmod 644 ${l} ${u}`));let c=l.replace(o,process.env.DSQL_STATIC_HOST||""),p=u.replace(o,process.env.DSQL_STATIC_HOST||"");await (0,D.A)({dbFullName:"datasquirel",tableName:"users",identifierColumnName:"id",identifierValue:t.id,data:{first_name:n,last_name:a,image:c,image_thumbnail:p}}),await (0,D.A)({dbFullName:"datasquirel",tableName:"user_users",identifierColumnName:"invited_user_id",identifierValue:t.id,data:{first_name:n,last_name:a,image:c,image_thumbnail:p}}),r.json({user:!0})}catch(e){(0,d.A)({component:"/api/updateUser/main-catch-error",message:e.message,user:t}),r.json({user:null})}}let y=(0,o.M)(n,"default"),A=(0,o.M)(n,"config"),E=new a.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/updateUser",pathname:"/api/updateUser",bundlePath:"",filename:""},userland:n})},55153:(e,r,t)=>{t.d(r,{On:()=>a.a,_n:()=>o}),t(76102);var n=t(65967),a=t.n(n);t(30889);var s=t(93726);let o=t.n(s)()},69842:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(39383),a=t.n(n),s=t(55153);async function o(e,r,t,n){let o=a()({req:e,level:t?"deep":void 0});return n&&o.payload?.id&&(0,s._n)(process.env.DSQL_SU_USER_ID)!==o.payload.id?null:o.payload}},30802:(e,r,t)=>{t.d(r,{A:()=>u});var n=t(72583),a=t.n(n),s=t(92652),o=t(68829),i=t(52939),l=t(6429
2024-12-08 19:56:57 +00:00
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}
2025-02-16 16:12:40 +00:00
User Email: ${e?.email}`),s?.url&&(n+=`
URL: ${s.url}`),s?.body&&(n+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),i&&(n+=`
2025-01-28 18:43:16 +00:00
IP: ${i}`),n+=`
2025-02-16 16:12:40 +00:00
Date: ${o.toDateString()}
========================================`,a().existsSync("./.tmp/error.log")||a().writeFileSync("./.tmp/error.log","","utf-8");let l=a().readFileSync("./.tmp/error.log","utf-8");a().writeFileSync("./.tmp/error.log",n),a().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-02-16 16:12:40 +00:00
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},68829:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(55511),a=t(79428),s=t(31542);function o({data:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let{key:o,salt:i,keyLen:l,algorithm:u,bufferAllocSize:c}=(0,s.A)({encryptionKey:r});if(!o?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let p=(0,n.scryptSync)(o,i,l),d=a.Buffer.alloc(c,0),_=(0,n.createCipheriv)(u,p,d);try{let r=_.update(e,"utf8","hex");return r+=_.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(7447);async function a(...e){let r=(0,n.A)();try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},52939:(e,r,t)=>{t.d(r,{A:()=>n});function n({dbContext:e,dbFullName:r}){return!e?.match(/dsql.user/i)&&(!!global.DSQL_USE_LOCAL||!r||!!r.match(/^datasquirel$/))}},64292:(e,r,t)=>{async function n(e,r,t){try{if(!e)throw Error("No Connection Found!");if(!r)throw Error("Query String Required!");if("string"==typeof r){let n=await e.query(a(r),t);return JSON.parse(JSON.stringify(n))}if("object"!=typeof r)return null;{let t=[];for(let n=0;n<r.length;n++)try{let s=r[n],o=await e.query(a(s.query),s.values);t.push(JSON.parse(JSON.stringify(o)))}catch(e){console.log(`connDbHandler Query Error: ${e.message}`),t.push(null)}return t}}catch(r){return console.log(`connDbHandler Error: ${r.message}`),console.log(e?.config()),null}finally{e?.end()}}function a(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}t.d(r,{A:()=>n})},7447:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(9973),a=t.n(n);function s(e){return global.DSQL_USE_LOCAL||e?.local?global.DSQL_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.ro?global.DSQL_READ_ONLY_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}},31542:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(82535);function a(e){return{key:e?.encryptionKey||process.env.DSQL_ENCRYPTION_PASSWORD,keyLen:process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24,salt:e?.encryptionSalt||process.env.DSQL_ENCRYPTION_SALT,apiKey:e?.apiKey||process.env.DSQL_API_KEY,algorithm:e?.algorithm||process.env.DSQL_ENCRYPTION_ALGORITHM||"aes-192-cbc",bufferAllocSize:e?.bufferAllocSize||(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE?(0,n.A)(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},82535:(e,r,t)=>{t.d(r,{A:()=>n});function n(e,r){try{let t=Number(e);if("number"!=typeof t||isNaN(t))return 0;if(r)return Number(t.toFixed(r));return Math.round(t)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}},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(75