dsql-admin/dsql-app/.local_dist/server/pages/api/sync-table-data.js

16 lines
9.1 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"use strict";(()=>{var e={};e.id=538,e.ids=[538],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")},9288:e=>{e.exports=require("sharp")},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")},41848:(e,r,t)=>{t.r(r),t.d(r,{config:()=>v,default:()=>y,routeModule:()=>R});var a={};t.r(a),t.d(a,{default:()=>h});var s=t(89947),o=t(2706),l=t(96762);t(82703),t(10701);var i=t(77538),n=t.n(i),d=t(6420),u=t.n(d),c=t(27825),m=t.n(c),p=t(51348),f=t.n(p),b=t(27444);t(39831),t(81630),t(77538);let _=t(51348);async function S({tbls:e,user:r,query:t}){let a;if(!t?.delegated)return{isPriviledged:!0,rootUserId:r.id};try{for(let t=0;t<e.length;t++){let s=e[t],o=await _(`SELECT * FROM delegated_user_tables WHERE delegated_user_id='${r.id}' AND \`database\`='${s.db}' AND \`table\`='${s.table}'`);if(!o?.[0]?.root_user_id)throw Error("Unauthorized!");let l=o[0];a||(a=l.root_user_id)}return{isPriviledged:!0,rootUserId:a}}catch(e){return{isPriviledged:!1,rootUserId:a,error:e.message}}}var g=t(49827);t(29021),t(33873);let{execSync:E}=t(79646);async function h(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await u()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{paradigm:a,src:s,dst:o}=e.body;try{let l=await S({tbls:[{db:s.db,table:s.table},{db:o.db,table:o.table}],user:t,query:e.query});if(!l.rootUserId||!l.isPriviledged)throw Error(l.error||"Unauthorized!");let i=(0,g.default)({userId:l.rootUserId});if(!i)throw Error("User Schema Data not Found!");let n=`${process.env.DSQL_USER_DB_PREFIX}${l.rootUserId}_${o.db}`,d=`${process.env.DSQL_USER_DB_PREFIX}${l.rootUserId}_${s.db}`,u=i.find(e=>e.dbFullName==n),c=i.find(e=>e.dbFullName==d),p=u?.tables.find(e=>e.tableName==o.table),_=c?.tables.find(e=>e.tableName==s.table);if(!p||!_)throw Error("Operation Failed! Tables Schemas not present.");if(!m().isEqual(_.fields,p.fields))throw Error("Tables incompatible");switch(a){case"Push":let E=await f()(`SELECT * FROM ${d}.${s.table}`),h=await (0,b.A)({dbName:o.db,paradigm:"import",payload:E,tableName:o.table,userId:l.rootUserId,payloadType:"object"});return await $({dbName:o.db,tableName:o.table,data:E,userId:l.rootUserId}),r.json({success:!0,payload:h});case"Pull":let y=await f()(`SELECT * FROM ${n}.${o.table}`),v=await (0,b.A)({dbName:s.db,paradigm:"import",payload:y,tableName:s.table,userId:l.rootUserId,payloadType:"object"});return await $({dbName:s.db,tableName:s.table,data:y,userId:l.rootUserId}),r.json({success:!0,payload:v})}r.json({success:!1})}catch(e){console.log(e.message),n()({component:"/api/sync-table-data",message:e.message,user:t}),r.json({success:!1,msg:e.message})}}async function $({dbName:e,tableName:r,data:t,userId:a}){let s=`${process.env.DSQL_USER_DB_PREFIX}${a}_${e.replace(/ /g,"")}`,o=t.map(e=>e.id),l=`DELETE FROM ${s}.${r}`;o?.[0]&&(l+=` WHERE id NOT IN (${o.join(",")})`),await f()(l)}let y=(0,l.M)(a,"default"),v=(0,l.M)(a,"config"),R=new s.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/sync-table-data",pathname:"/api/sync-table-data",bundlePath:"",filename:""},userland:a})},10701:(e,r,t)=>{let a=t(9288),s=t(77538),o=t(48227);e.exports=async function({imageSourceBase64:e,imageName:r,user:t,mimeType:l,thumbnailSize:i,folder:n,isPrivate:d}){try{let s=Buffer.from(e,"base64"),u=i?parseInt(i.toString()):400,c=a(s),m=a(s),p=o({isPrivate:d,user:t,folder:n});if(!p)return null;let{fileRootPath:f,urlRootPath:b,relativePath:_}=p,{width:S,height:g,format:E}=await c.metadata(),h=l||E;S&&g&&S>1800&&c.resize(1800,Math.round(1800/S*g),{fit:"cover"}),c.toFormat(h,{quality:80}),await c.metadata();let $=`${r}.${h}`;if(await c.toFile(f+$),S&&g&&S>u){let e=u/S;m.resize(u,Math.round(g*e),{fit:"cover"})}else S&&g&&m.resize(150,Math.round(150/S*g),{fit:"cove
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),o?.url&&(s+=`
URL: ${o.url}`),o?.body&&(s+=`
Request Body: ${JSON.stringify(o.body,null,4)}`),i&&(s+=`
IP: ${i}`),s+=`
Date: ${l.toDateString()}
========================================`,a.existsSync("./.tmp/error.log")||a.writeFileSync("./.tmp/error.log","","utf-8");let n=a.readFileSync("./.tmp/error.log","utf-8");a.writeFileSync("./.tmp/error.log",s),a.appendFileSync("./.tmp/error.log",`
2024-11-05 11:12:42 +00:00
2024-12-05 07:03:33 +00:00
${n}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,r,t)=>{t(81630);let a=t(51348),s=t(72907),o=t(29021);async function l(e,r,t,l){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let i=s(e.cookies.datasquirelAuthKey);if(!i)return null;let n=JSON.parse(i);if(!n.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${n.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&&!o.existsSync(`${d}/${n.csrf_k}`))return null;if(0==n.verification_status&&!t){let e=await a(`SELECT verification_status FROM users WHERE id='${n.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return n?.date&&Date.now()-n.date>6048e5?null:n}e.exports=l},72907:(e,r,t)=>{let{scryptSync:a,createDecipheriv:s}=t(55511),{Buffer:o}=t(79428);e.exports=e=>{let r=s("aes-192-cbc",a(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),o.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),a=r.X(0,[4050],()=>t(41848));module.exports=a})();