"use strict";(()=>{var e={};e.id=9171,e.ids=[9171],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},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")},21820:e=>{e.exports=require("os")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,s){return s in r?r[s]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,s)):"function"==typeof r&&"default"===s?r:void 0}}})},99323:(e,r,s)=>{s.r(r),s.d(r,{config:()=>E,default:()=>D,routeModule:()=>A});var o={};s.r(o),s.d(o,{default:()=>d});var n=s(89947),t=s(2706),c=s(96762),_=s(29021),a=s.n(_),i=s(21820),u=s.n(i),l=s(79646),S=s(48786),p=s(87369);async function d(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Wrong Method"});let s=await (0,p.A)(e);if(!s?.logged_in_status)return r.json({success:!1,log:"Unauthorized"});try{let s=e.body.user.id.toString().replace(/[^0-9]/g,"").replace(/\//g,""),o=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s}/backups`;a().existsSync(o)||a().mkdirSync(o);let n=Date.now().toString();a().mkdirSync(`${o}/${n}`);let t=await (0,S.A)("SHOW databases LIKE ?",[`datasquirel_user_${s}_%`]);for(let e=0;e ${a}`;console.log(`addUserBackup.ts exe => ${i}`),(0,l.spawnSync)(c,["-u",process.env.DSQL_DB_USERNAME||"","-h",process.env.DSQL_DB_HOST||"",`-p${process.env.DSQL_DB_PASSWORD}`,s,">",a],_)}a().copyFileSync(`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s}/main.json`,`${o}/${n}/main.json`),r.json({success:!0})}catch(e){console.log(e.message),r.json({success:!1})}}let D=(0,c.M)(o,"default"),E=(0,c.M)(o,"config"),A=new n.PagesAPIRouteModule({definition:{kind:t.A.PAGES_API,page:"/api/admin/addUserBackup",pathname:"/api/admin/addUserBackup",bundlePath:"",filename:""},userland:o})},87369:(e,r,s)=>{s.d(r,{A:()=>t});var o=s(95969),n=s(89159);async function t(e){let{keyCookieName:r,csrfCookieName:s}=(0,n.A)(),t=`${r}_su`;if(!e.cookies?.[t])return console.log("No auth key cookie found"),null;let c=(0,o.A)({encryptedString:e.cookies[t]});if(!c)return console.log("No user payload found"),null;let _=JSON.parse(c);return _.password!==process.env.DSQL_USER_KEY?(console.log("Invalid password"),null):_.authKey!==process.env.DSQL_SPECIAL_KEY?(console.log("Invalid auth key"),null):_}},89159:(e,r,s)=>{s.d(r,{A:()=>o});function o(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",s=process.env.DSQL_COOKIES_KEY_NAME||"key",o=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",n=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",t=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),c=r;e?.userId&&(c+=`user_${e.userId}_`),t&&(c+=`${t}_`),c+=s;let _=r;e?.userId&&(_+=`user_${e.userId}_`),t&&(_+=`${t}_`),_+=o;let a=r;return e?.userId&&(a+=`user_${e.userId}_`),t&&(a+=`${t}_`),{keyCookieName:c,csrfCookieName:_,oneTimeCodeName:a+=n}}},95969:(e,r,s)=>{s.d(r,{A:()=>c});var o=s(55511),n=s(79428),t=s(32443);function c({encryptedString:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:c,salt:_,keyLen:a,algorithm:i,bufferAllocSize:u}=(0,t.A)({encryptionKey:r});if(!c?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!_?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let l=(0,o.scryptSync)(c,_,a),S=n.Buffer.alloc(u,0),p=(0,o.createDecipheriv)(i,l,S);try{let r=p.update(e,"hex","utf8");return r+=p.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,s)=>{s.d(r,{A:()=>n});var o=s(7447);async function n(...e){let r=(0,o.A)();try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let s=await r.query(...e);return JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},7447:(e,r,s)=>{s.d(r,{A:()=>t});var o=s(9973),n=s.n(o);function t(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||n()({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||n()({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||n()({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"}})}},32443:(e,r,s)=>{s.d(r,{A:()=>o});function o(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?function(e,r){try{let r=Number(e);if("number"!=typeof r||isNaN(r))return 0;return Math.round(r)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return s}});var s=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,s)=>{e.exports=s(75600)}};var r=require("../../../webpack-api-runtime.js");r.C(e);var s=r(r.s=99323);module.exports=s})();