1 line
4.1 KiB
JavaScript
1 line
4.1 KiB
JavaScript
"use strict";(()=>{var e={};e.id=4105,e.ids=[4105],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},55096:(e,r,t)=>{t.r(r),t.d(r,{config:()=>A,default:()=>E,routeModule:()=>S});var s={};t.r(s),t.d(s,{default:()=>p});var a=t(89947),n=t(2706),i=t(96762),u=t(69842),o=t(67619),l=t(48786),c=t(33873),d=t.n(c),_=t(76856);let f=t(29021);async function p(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await (0,u.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let s=e.body.schema,a=e.body.dbId;try{let e=await (0,l.A)("SELECT * FROM user_databases WHERE user_id = ? AND id = ?",[t.id,a]);if(!e?.[0])throw Error("Invalid Database");let n=e[0],i=d().resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/main.json`),u=JSON.parse(f.readFileSync(i,"utf-8")),o=u.find(e=>e.dbFullName==n.db_full_name);if(!o)throw Error("This Database doesn't exist");if(o.tables=s.tables,o.childrenDatabases)for(let e=0;e<o.childrenDatabases.length;e++){let{dbFullName:r}=o.childrenDatabases[e],t=u.find(e=>e.dbFullName===r);if(!t||!t.tables){o.childrenDatabases?.splice(e,1);continue}t.tables=s.tables}f.writeFileSync(`${i}`,JSON.stringify(u),"utf8"),await (0,_.A)({userId:t.id,targetDatabase:n.db_full_name}),r.json({success:!0})}catch(s){(0,o.default)({component:"/api/acceptUserInvitation/catch-error",message:s.message,user:t,req:e}),r.json({success:!1})}}let E=(0,i.M)(s,"default"),A=(0,i.M)(s,"config"),S=new a.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/user-schema/replace-database-schema",pathname:"/api/user-schema/replace-database-schema",bundlePath:"",filename:""},userland:s})},69842:(e,r,t)=>{t.d(r,{A:()=>o});var s=t(48786),a=t(95969),n=t(29021),i=t.n(n),u=t(89159);async function o(e,r,t){let{keyCookieName:n,csrfCookieName:o}=(0,u.A)();if(!e.cookies?.[n]?.match(/./))return null;let l=(0,a.A)({encryptedString:e.cookies[n]});if(!l)return null;let c=JSON.parse(l);if(!c.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(c.csrf_k)))return null;let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!i().existsSync(`${d}/${c.csrf_k}`))return null;if(0==c.verification_status&&!t){let e=await (0,s.A)(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",n=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),i=r;e?.userId&&(i+=`user_${e.userId}_`),n&&(i+=`${n}_`),i+=t;let u=r;e?.userId&&(u+=`user_${e.userId}_`),n&&(u+=`${n}_`),u+=s;let o=r;return e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),{keyCookieName:i,csrfCookieName:u,oneTimeCodeName:o+=a}}},48786:(e,r,t)=>{t.d(r,{A:()=>s});async function s(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}});var t=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,t)=>{e.exports=t(75600)}};var r=require("../../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[2282],()=>t(55096));module.exports=s})(); |