1 line
5.2 KiB
JavaScript
1 line
5.2 KiB
JavaScript
"use strict";(()=>{var e={};e.id=8275,e.ids=[8275],e.modules={60818:e=>{e.exports=require("dotenv")},27825:e=>{e.exports=require("lodash")},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")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},13441:(e,a,t)=>{t.r(a),t.d(a,{config:()=>v,default:()=>F,routeModule:()=>x});var s={};t.r(s),t.d(s,{default:()=>D});var r=t(89947),l=t(2706),d=t(96762),i=t(48225),n=t.n(i),u=t(6420),o=t.n(u),b=t(2258),c=t(27825),_=t.n(c),m=t(78634),f=t(51348),p=t.n(f),N=t(47670),h=t.n(N),S=t(19261),g=t.n(S);t(29021),t(33873);let{execSync:E}=t(79646);async function D(e,a){if("POST"!==e.method)return a.json({msg:"Failed!"});let t=await o()(e,a,!0);if(!t)return console.log("No User"),a.json({success:!1,msg:"Unauthorized"});let{payload:s}=e.body,r=e.body.dbFullName.replace(/[^a-z\_0-9]/g,""),l=e.body.dbSlug,d=e.body.dbId,i=e.body.parentDatabase,u=e.body.parentTable;try{let e=(0,b.default)({userId:t.id});if(!e)throw Error("No User Schema found!");let o=e.findIndex(e=>e.dbFullName===r),c=e[o];if(!c)throw Error("No Target Database Found!");let f=c.tables.findIndex(e=>e.tableName===s.tableName);if(f>=0?e[o].tables[f]=s:e[o].tables.push(s),s?.childTable){let a=e.find(e=>e.dbFullName===i),t=a?.tables.find(e=>{if(e.tableName===u)return!0});if(!t)throw Error("Child Table Parent Doesn't Exist!");t.childrenTables?.[0]?t.childrenTables.push({dbNameFull:r,tableName:s.tableName,tableNameFull:s.tableNameFull}):t.childrenTables=[{dbNameFull:r,tableName:s.tableName,tableNameFull:s.tableFullName}]}if(c.childrenDatabases)for(let a=0;a<c.childrenDatabases.length;a++){let r=c.childrenDatabases[a];try{let a=e.findIndex(e=>e.dbFullName===r.dbFullName);e[a]&&(e[a].tables=_().cloneDeep(c.tables));let l=await p()("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[t.id,r.dbFullName]),d=await p()("SELECT * FROM user_database_tables WHERE db_id=? AND user_id=? AND table_slug=?",[l[0].id,t.id,s.tableName]);if(d?.[0])continue;await h()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:t.id,db_id:l[0].id,db_slug:l[0].db_slug,table_name:s.tableFullName,table_slug:s.tableName}})}catch(e){n()({component:"/api/addUserTable/lines-124-140",message:e.message,user:t})}}(0,m.default)({userId:t.id,schemaData:e});let N={user_id:t.id,db_id:d,db_slug:l,table_name:s.tableFullName,table_slug:s.tableName};s?.childTable&&(N.child_table="1",N.child_table_parent_database=i,N.child_table_parent_table=u),await h()({dbFullName:"datasquirel",tableName:"user_database_tables",data:N}),await g()({userId:t.id,targetDatabase:r}),a.json({success:!0})}catch(e){console.log(e.message),n()({component:"/api/addUserTable/main-catch-error",message:e.message,user:t}),a.json({success:!1,msg:"Database Files could not be written!"})}}let F=(0,d.M)(s,"default"),v=(0,d.M)(s,"config"),x=new r.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/addUserTable",pathname:"/api/addUserTable",bundlePath:"",filename:""},userland:s})},6420:(e,a,t)=>{t(81630);let s=t(51348),r=t(72835),l=t(29021),d=t(31341);async function i(e,a,t,i){let{keyCookieName:n,csrfCookieName:u}=d();if(!e.cookies?.[n]?.match(/./))return null;let o=r({encryptedString:e.cookies[n]});if(!o)return null;let b=JSON.parse(o);if(!b.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${b.csrf_k}`)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!l.existsSync(`${c}/${b.csrf_k}`))return null;if(0==b.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${b.id}'`);e&&e[0]&&1==e[0].verification_status&&a.setHeader("Set-Cookie",["user_refresh=1"])}return b?.date&&Date.now()-b.date>6048e5?null:b}e.exports=i},31341:e=>{e.exports=function(e){let a=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",r=e?.database||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),l=a;e?.userId&&(l+=`user_${e.userId}_`),r&&(l+=`${r}_`),l+=t;let d=a;return e?.userId&&(d+=`user_${e.userId}_`),r&&(d+=`${r}_`),{keyCookieName:l,csrfCookieName:d+=s}}},2258:(e,a,t)=>{t.r(a),t.d(a,{default:()=>d});let s=t(48225),r=t(29021),l=t(33873);function d({userId:e}){try{let a=l.resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);return JSON.parse(r.readFileSync(a,"utf-8"))}catch(e){return s({component:"grabUserSchemaData",message:e.message}),null}}},78634:(e,a,t)=>{t.r(a),t.d(a,{default:()=>d});let s=t(48225),r=t(29021),l=t(33873);function d({userId:e,schemaData:a}){try{let t=l.resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);return r.writeFileSync(t,JSON.stringify(a),"utf8"),!0}catch(e){return s({component:"/functions/backend/setUserSchemaData",message:e.message}),!1}}}};var a=require("../../webpack-api-runtime.js");a.C(e);var t=e=>a(a.s=e),s=a.X(0,[4050,2451],()=>t(13441));module.exports=s})(); |