1 line
5.5 KiB
JavaScript
1 line
5.5 KiB
JavaScript
"use strict";(()=>{var e={};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")},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:()=>p,routeModule:()=>b});var s={};t.r(s),t.d(s,{default:()=>m});var r=t(89947),l=t(2706),d=t(96762),i=t(29021),u=t.n(i),o=t(48786),n=t(67619),_=t(69842),f=t(98e3),c=t(76856);async function m(e,a){if("POST"!==e.method)return a.json({msg:"Failed!"});let s=await (0,_.A)(e,a,!0);if(!s)return a.json({success:!1,msg:"Unauthorized"});let{dbFullName:r,dbSlug:l,dbId:d}=e.body,i=t(8693),m=t(95610),p=[...m.slice(0,2),...i.fields,...m.slice(2)];i.fields=[...p];try{let e;let t=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`,_=JSON.parse(u().readFileSync(t,"utf8")),m=_.filter(e=>e.dbFullName===r)[0],p=m.tables.filter((a,t)=>{if("users"===a.tableName)return e=t,!0});if(p?.[0]&&"number"==typeof e?m.tables[e]=i:m.tables.push(i),m.childrenDatabases)for(let e=0;e<m.childrenDatabases.length;e++){let a=m.childrenDatabases[e];try{_.filter(e=>e.dbFullName===a.dbFullName)[0].tables=m.tables;let e=await (0,o.A)("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[s.id,a.dbFullName]);await (0,f.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,n.A)({component:"/api/addUsersTableToDatabase/lines-100-115",message:e.message,user:s})}}u().writeFileSync(`${t}`,JSON.stringify(_),"utf8"),await (0,f.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:s.id,db_id:d,db_slug:l,table_name:"Users",table_slug:"users"}});let A=r.replace(/[^a-z\_0-9]/g,"");await (0,c.A)({userId:s.id,targetDatabase:A}),a.json({success:!0})}catch(e){(0,n.A)({component:"/api/addUsersTableToDatabase/main-catch-error",message:e.message,user:s}),a.json({success:!1,msg:"Database Files could not be written!"})}}let p=(0,d.M)(s,"default"),A=(0,d.M)(s,"config"),b=new r.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});var s=t(48786),r=t(95969),l=t(29021),d=t.n(l),i=t(89159);async function u(e,a,t){try{let{keyCookieName:l,csrfCookieName:u}=(0,i.A)();if(!e.cookies?.[l]?.match(/./))throw Error("Request Cookies not Found!");let o=(0,r.A)({encryptedString:e.cookies[l]});if(!o)throw Error("Couldn't decrypt auth cookie!");let n=JSON.parse(o);if(!n.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(n.csrf_k)))throw Error("Deep Auth Failed. `csrf` key not found in request headers!");let _=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!d().existsSync(`${_}/${n.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==n.verification_status&&!t){let e=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)throw Error("Key expired!");return n}catch(a){return console.log(`userAuth Error for ${e.url}: ${a.message}`),null}}},89159:(e,a,t)=>{t.d(a,{A:()=>s});function s(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=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;let i=a;e?.userId&&(i+=`user_${e.userId}_`),l&&(i+=`${l}_`),i+=s;let u=a;return e?.userId&&(u+=`user_${e.userId}_`),l&&(u+=`${l}_`),{keyCookieName:d,csrfCookieName:i,oneTimeCodeName:u+=r}}},8693: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":"TEXT"},{"fieldName":"image","dataType":"VARCHAR(250)"},{"fieldName":"image_thumbnail","dataType":"VARCHAR(250)"},{"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),s=a.X(0,[1251,2282],()=>t(32551));module.exports=s})(); |