"use strict";(()=>{vare={};e.id=4436,e.ids=[4436],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")},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")},32551:(e,a,t)=>{t.r(a),t.d(a,{config:()=>A,default:()=>m,routeModule:()=>b});vars={};t.r(s),t.d(s,{default:()=>p});varr=t(89947),l=t(2706),d=t(96762),i=t(48786),u=t(67619),o=t(69842),n=t(98e3),_=t(76856);letf=t(29021);t(33873);let{execSync:c}=t(79646);asyncfunctionp(e,a){if("POST"!==e.method)returna.json({msg:"Failed!"});lets=await(0,o.A)(e,a,!0);if(!s)returna.json({success:!1,msg:"Unauthorized"});let{dbFullName:r,dbSlug:l,dbId:d}=e.body,c=t(8693),p=t(95610),m=[...p.slice(0,2),...c.fields,...p.slice(2)];c.fields=[...m];try{lete;lett=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`,o=JSON.parse(f.readFileSync(t,"utf8")),p=o.filter(e=>e.dbFullName===r)[0],m=p.tables.filter((a,t)=>{if("users"===a.tableName)returne=t,!0});if(m?.[0]&&"number"==typeofe?p.tables[e]=c:p.tables.push(c),p.childrenDatabases)for(lete=0;e<p.childrenDatabases.length;e++){leta=p.childrenDatabases[e];try{o.filter(e=>e.dbFullName===a.dbFullName)[0].tables=p.tables;lete=await(0,i.A)("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[s.id,a.dbFullName]);await(0,n.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:s.id,db_id:e[0].id,db_slug:e[0].db_slug,table_name:"Users",table_slug:"users"}})}catch(e){(0,u.default)({component:"/api/addUsersTableToDatabase/lines-100-115",message:e.message,user:s})}}f.writeFileSync(`${t}`,JSON.stringify(o),"utf8"),await(0,n.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:s.id,db_id:d,db_slug:l,table_name:"Users",table_slug:"users"}});letA=r.replace(/[^a-z\_0-9]/g,"");await(0,_.A)({userId:s.id,targetDatabase:A}),a.json({success:!0})}catch(e){(0,u.default)({component:"/api/addUsersTableToDatabase/main-catch-error",message:e.message,user:s}),a.json({success:!1,msg:"Database Files could not be written!"})}}letm=(0,d.M)(s,"default"),A=(0,d.M)(s,"config"),b=newr.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/addUsersTableToDatabase",pathname:"/api/addUsersTableToDatabase",bundlePath:"",filename:""},userland:s})},69842:(e,a,t)=>{t.d(a,{A:()=>u});vars=t(48786),r=t(95969),l=t(29021),d=t.n(l),i=t(89159);asyncfunctionu(e,a,t){try{let{keyCookieName:l,csrfCookieName:u}=(0,i.A)();if(!e.cookies?.[l]?.match(/./))throwError("Request Cookies not Found!");leto=(0,r.A)({encryptedString:e.cookies[l]});if(!o)throwError("Couldn't decrypt auth cookie!");letn=JSON.parse(o);if(!n.csrf_k)throwError("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(n.csrf_k)))throwError("Deep Auth Failed. `csrf` key not found in request headers!");let_=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)throwError("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!d().existsSync(`${_}/${n.csrf_k}`))throwError("Key not found in Auth Keys Folder!");if(0==n.verification_status&&!t){lete=await(0,s.A)(`SELECT verification_status FROM users WHERE id='${n.id}'`);e&&e[0]&&1==e[0].verification_status&&a.setHeader("Set-Cookie",["user_refresh=1"])}if(n?.date&&Date.now()-n.date>6048e5)throwError("Key expired!");returnn}catch(e){returnconsole.log(`userAuth Error: ${e.message}`),null}}},89159:(e,a,t)=>{t.d(a,{A:()=>s});functions(e){leta=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",r=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",l=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),d=a;e?.userId&&(d+=`user_${e.userId}_`),l&&(d+=`${l}_`),d+=t;leti=a;e?.userId&&(i+=`user_${e.userId}_`)