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

16 lines
5.4 KiB
JavaScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
"use strict";(()=>{var e={};e.id=4727,e.ids=[4727],e.modules={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")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},27310:(e,r,t)=>{t.r(r),t.d(r,{config:()=>p,default:()=>d,routeModule:()=>_});var s={};t.r(s),t.d(s,{config:()=>u,default:()=>c});var a=t(89947),n=t(2706),i=t(96762),l=t(69842),o=t(33170);let u={api:{responseLimit:"1mb",bodyParser:{sizeLimit:"200mb"}}};async function c(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,l.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{paradigm:s,dbName:a,tableName:n,payload:i}=e.body;try{let e=await (0,o.A)({dbName:a,paradigm:s,payload:i,tableName:n,userId:t.id,payloadType:"base64"});if(!e)return r.json({success:!1,msg:"Operation Failed!"});r.json({success:!0,msg:"Success!",data:e?.tableData})}catch(e){r.json({success:!1,msg:e.message})}}let d=(0,i.M)(s,"default"),p=(0,i.M)(s,"config"),_=new a.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/exportTableData",pathname:"/api/exportTableData",bundlePath:"",filename:""},userland:s})},33170:(e,r,t)=>{t.d(r,{A:()=>i});var s=t(98e3),a=t(67619),n=t(48786);async function i({paradigm:e,userId:r,dbName:t,tableName:i,payload:l,payloadType:o}){let u={};try{let a=`${process.env.DSQL_USER_DB_PREFIX}${r}_${t.replace(/ /g,"")}`;switch(e){case"export":let c=await (0,n.A)(`SELECT * FROM \`${a}\`.\`${i}\``);u.tableData=c;break;case"import":let d="base64"==o?Buffer.from(l,"base64").toString():l,p="object"===o?l:JSON.parse(d);for(let e=0;e<p.length;e++){let r=p[e],t=await (0,s.A)({data:r,dbFullName:a,tableName:i,dbContext:"Dsql User",paradigm:"Full Access",duplicateColumnName:"id",duplicateColumnValue:r?.id,update:!0});if(t.error)throw Error(t.error)}break;default:return null}return u}catch(e){return(0,a.default)({component:"/functions/backend/importExportTableDataFn",message:e.message}),null}}},69842:(e,r,t)=>{t.d(r,{A:()=>o});var s=t(48786),a=t(95969),n=t(29021),i=t.n(n),l=t(89159);async function o(e,r,t){let{keyCookieName:n,csrfCookieName:o}=(0,l.A)();if(!e.cookies?.[n]?.match(/./))return null;let u=(0,a.A)({encryptedString:e.cookies[n]});if(!u)return null;let c=JSON.parse(u);if(!c.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(c.csrf_k)))return null;let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!i().existsSync(`${d}/${c.csrf_k}`))return null;if(0==c.verification_status&&!t){let e=await (0,s.A)(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",n=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),i=r;e?.userId&&(i+=`user_${e.userId}_`),n&&(i+=`${n}_`),i+=t;let l=r;e?.userId&&(l+=`user_${e.userId}_`),n&&(l+=`${n}_`),l+=s;let o=r;return e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),{keyCookieName:i,csrfCookieName:l,oneTimeCodeName:o+=a}}},67619:(e,r,t)=>{t.r(r),t.d(r,{default:()=>n});var s=t(29021),a=t.n(s);async function n({user:e,message:r,component:t,noMail:s,req:n}){let i=new Date,l=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],r=n.headers["x-real-ip"],t=n.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],a=t||s||r||n.socket.remoteAddress;if(!a)return null;return String(a)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
2024-12-08 19:56:57 +00:00
Error Message: ${r}
2025-01-13 08:00:21 +00:00
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
2024-12-08 19:56:57 +00:00
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
2025-01-13 08:00:21 +00:00
User Email: ${e?.email}`),n?.url&&(s+=`
URL: ${n.url}`),n?.body&&(s+=`
Request Body: ${JSON.stringify(n.body,null,4)}`),l&&(s+=`
IP: ${l}`),s+=`
2024-12-08 19:56:57 +00:00
Date: ${i.toDateString()}
2025-01-13 08:00:21 +00:00
========================================`,a().existsSync("./.tmp/error.log")||a().writeFileSync("./.tmp/error.log","","utf-8");let o=a().readFileSync("./.tmp/error.log","utf-8");a().writeFileSync("./.tmp/error.log",s),a().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-01-13 08:00:21 +00:00
${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(55511),a=t(79428);function n({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=r||process.env.DSQL_ENCRYPTION_PASSWORD,i=t||process.env.DSQL_ENCRYPTION_SALT,l=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let o=(0,s.scryptSync)(n,i,l),u=a.Buffer.alloc(16,0),c=(0,s.createDecipheriv)("aes-192-cbc",o,u);try{let r=c.update(e,"hex","utf8");return r+=c.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[1251],()=>t(27310));module.exports=s})();