16 lines
7.0 KiB
JavaScript
16 lines
7.0 KiB
JavaScript
"use strict";(()=>{var e={};e.id=4436,e.ids=[4436],e.modules={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")},13461:(e,a,t)=>{t.r(a),t.d(a,{config:()=>A,default:()=>y,routeModule:()=>b});var l={};t.r(l),t.d(l,{default:()=>R});var r=t(89947),s=t(2706),i=t(96762),d=t(51348),u=t.n(d),n=t(77538),o=t.n(n),p=t(6420),m=t.n(p),f=t(47670),c=t.n(f);let _=t(29021),N=t(33873),{execSync:T}=t(79646);async function R(e,a){if("POST"!==e.method)return a.json({msg:"Failed!"});let l=await m()(e,a,!0);if(!l)return a.json({success:!1,msg:"Unauthorized"});let{dbFullName:r,dbSlug:s,dbId:i}=e.body,d=t(87924),n=t(83434),p=[...n.slice(0,2),...d.fields,...n.slice(2)];d.fields=[...p];try{let e;let t=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${l.id}/main.json`,n=JSON.parse(_.readFileSync(t,"utf8")),p=n.filter(e=>e.dbFullName===r)[0],m=p.tables.filter((a,t)=>{if("users"===a.tableName)return e=t,!0});if(m?.[0]&&"number"==typeof e?p.tables[e]=d:p.tables.push(d),p.childrenDatabases)for(let e=0;e<p.childrenDatabases.length;e++){let a=p.childrenDatabases[e];try{n.filter(e=>e.dbFullName===a.dbFullName)[0].tables=p.tables;let e=await u()("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[l.id,a.dbFullName]);await c()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:l.id,db_id:e[0].id,db_slug:e[0].db_slug,table_name:"Users",table_slug:"users"}})}catch(e){o()({component:"/api/addUsersTableToDatabase/lines-100-115",message:e.message,user:l})}}_.writeFileSync(`${t}`,JSON.stringify(n),"utf8"),await c()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:l.id,db_id:i,db_slug:s,table_name:"Users",table_slug:"users"}});let f=N.join(process.cwd(),"/shell"),R=r.replace(/[^a-z\_0-9]/g,""),y=T(`node createDbFromSchema.js --user ${l.id} --database ${R}`,{cwd:f});console.log(y.toString()),a.json({success:!0})}catch(e){o()({component:"/api/addUsersTableToDatabase/main-catch-error",message:e.message,user:l}),a.json({success:!1,msg:"Database Files could not be written!"})}}let y=(0,i.M)(l,"default"),A=(0,i.M)(l,"config"),b=new r.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/addUsersTableToDatabase",pathname:"/api/addUsersTableToDatabase",bundlePath:"",filename:""},userland:l})},77538:(e,a,t)=>{let l=t(29021),{IncomingMessage:r}=t(81630);e.exports=async function({user:e,message:a,component:t,noMail:r,req:s}){let i=new Date,d=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],a=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],l=Array.isArray(e)?e[0]:e?.split(",")[0],r=t||l||a||s.socket.remoteAddress;if(!r)return null;return String(r)}catch(e){return null}})();try{let r=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${a}
|
|
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(r+=`
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}`),s?.url&&(r+=`
|
|
URL: ${s.url}`),s?.body&&(r+=`
|
|
Request Body: ${JSON.stringify(s.body,null,4)}`),d&&(r+=`
|
|
IP: ${d}`),r+=`
|
|
Date: ${i.toDateString()}
|
|
========================================`,l.existsSync("./.tmp/error.log")||l.writeFileSync("./.tmp/error.log","","utf-8");let u=l.readFileSync("./.tmp/error.log","utf-8");l.writeFileSync("./.tmp/error.log",r),l.appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${u}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,a,t)=>{t(81630);let l=t(51348),r=t(72907),s=t(29021);async function i(e,a,t,i){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let d=r(e.cookies.datasquirelAuthKey);if(!d)return null;let u=JSON.parse(d);if(!u.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${u.csrf_k}`)))return null;let n=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!n)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!s.existsSync(`${n}/${u.csrf_k}`))return null;if(0==u.verification_status&&!t){let e=await l(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&a.setHeader("Set-Cookie",["user_refresh=1"])}return u?.date&&Date.now()-u.date>6048e5?null:u}e.exports=i},72907:(e,a,t)=>{let{scryptSync:l,createDecipheriv:r}=t(55511),{Buffer:s}=t(79428);e.exports=e=>{let a=r("aes-192-cbc",l(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),s.alloc(16,0));try{let t=a.update(e,"hex","utf8");return t+=a.final("utf8")}catch(e){return null}}},83434:e=>{e.exports=JSON.parse('[{"fieldName":"id","dataType":"BIGINT","notNullValue":true,"primaryKey":true,"autoIncrement":true},{"fieldName":"uuid","dataType":"UUID","defaultValueLiteral":"UUID()"},{"fieldName":"date_created","dataType":"VARCHAR(250)","nullValue":true},{"fieldName":"date_created_code","dataType":"BIGINT","nullValue":true},{"fieldName":"date_created_timestamp","dataType":"TIMESTAMP","defaultValueLiteral":"CURRENT_TIMESTAMP"},{"fieldName":"date_updated","dataType":"VARCHAR(250)","nullValue":true},{"fieldName":"date_updated_code","dataType":"BIGINT","nullValue":true},{"fieldName":"date_updated_timestamp","dataType":"TIMESTAMP","defaultValueLiteral":"CURRENT_TIMESTAMP","onUpdateLiteral":"CURRENT_TIMESTAMP"}]')},87924:e=>{e.exports=JSON.parse('{"tableName":"users","tableFullName":"Users","fields":[{"fieldName":"first_name","dataType":"VARCHAR(100)","notNullValue":true},{"fieldName":"last_name","dataType":"VARCHAR(100)","notNullValue":true},{"fieldName":"email","dataType":"VARCHAR(200)","notNullValue":true},{"fieldName":"phone","dataType":"VARCHAR(50)"},{"fieldName":"user_type","dataType":"VARCHAR(20)","defaultValue":"default"},{"fieldName":"username","dataType":"VARCHAR(100)","nullValue":true},{"fieldName":"password","dataType":"VARCHAR(250)","notNullValue":true},{"fieldName":"image","dataType":"VARCHAR(250)","defaultValue":"/images/user-preset.png"},{"fieldName":"image_thumbnail","dataType":"VARCHAR(250)","defaultValue":"/images/user-preset-thumbnail.png"},{"fieldName":"address","dataType":"VARCHAR(255)"},{"fieldName":"city","dataType":"VARCHAR(50)"},{"fieldName":"state","dataType":"VARCHAR(50)"},{"fieldName":"country","dataType":"VARCHAR(50)"},{"fieldName":"zip_code","dataType":"VARCHAR(50)"},{"fieldName":"social_login","dataType":"TINYINT","defaultValue":"0"},{"fieldName":"social_platform","dataType":"VARCHAR(50)","nullValue":true},{"fieldName":"social_id","dataType":"VARCHAR(250)","nullValue":true},{"fieldName":"more_user_data","dataType":"BIGINT","defaultValue":"0"},{"fieldName":"verification_status","dataType":"TINYINT","defaultValue":"0"},{"fieldName":"temp_login_code","dataType":"VARCHAR(50)","nullValue":true}]}')}};var a=require("../../webpack-api-runtime.js");a.C(e);var t=e=>a(a.s=e),l=a.X(0,[4050],()=>t(13461));module.exports=l})(); |