dsql-admin/dsql-app/.local_dist/server/pages/api/addTableEntry.js

16 lines
7.1 KiB
JavaScript
Raw Permalink Normal View History

2024-12-15 11:27:16 +00:00
"use strict";(()=>{var e={};e.id=460,e.ids=[460],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")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},14373:(e,r,t)=>{t.r(r),t.d(r,{config:()=>f,default:()=>m,routeModule:()=>S});var s={};t.r(s),t.d(s,{default:()=>g});var a=t(89947),i=t(2706),o=t(96762),l=t(96771),n=t.n(l),d=t(47670),u=t.n(d);t(51348),t(21339);let c=t(73677),_=t(39831),p=t(48225),E=t(6420);async function g(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await E(e,r,!0);if(!t)return r.json({success:!1,msg:"User Auth Failed"});let{tableName:s,payload:a,tableSchema:i,dbSlug:o,dbId:l,delegated:d}=e.body;try{let d=await _({databaseSlug:o,request:e,user:t,query:e.query});if(!await c({user:t,confirmedDelegetedUser:d,database:o,table:s,dbId:l,priviledgeRegex:/Update Entries/i}))return r.json({success:!1,msg:"Unauthorized"});let p=d?.rootUserId?`datasquirel_user_${d.rootUserId}_${o}`:`datasquirel_user_${t.id}_${o}`,E=await u()({dbContext:"Dsql User",paradigm:"Full Access",dbFullName:p,tableName:s,data:a,tableSchema:i});if(!E.insertId)throw console.log("Table Insertion Failed =>",E),Error(E?.error||"Table Insertion Failed");await n()({dbName:p,entryId:E.insertId,entryOrder:a.order,tableName:s,tableSchema:i}),r.json({success:!0})}catch(e){p({component:"/api/addTableEntry/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Database Files could not be written!",err:e.message})}}let m=(0,o.M)(s,"default"),f=(0,o.M)(s,"config"),S=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addTableEntry",pathname:"/api/addTableEntry",bundlePath:"",filename:""},userland:s})},73677:(e,r,t)=>{let s=t(51348),a=t(48225);e.exports=async function({user:e,confirmedDelegetedUser:r,database:t,table:i,priviledgeRegex:o,dbId:l}){let n,d;try{r?.delegated?(n=await s("SELECT priviledge FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=? AND `table`=?",[r.rootUserId,e.id,t,i]),d=n[0]?.priviledge?.match(o)):(n=await s("SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?",[e.id,i,l]),d=!0)}catch(r){a({component:"checkUserRights",message:r.message,user:e})}return!!n&&!!n[0]&&!!d}},39831:(e,r,t)=>{t(81630);let s=t(72835);e.exports=async function({request:e,databaseSlug:r,user:t,query:a}){try{let i=t.id,o=null;if(!a?.delegated)return{dbUserId:i};let l=a.dbUserId,n=`${process.env.DSQL_USER_DB_PREFIX}${l}_${r}`,d=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${n}`;try{if(!e.cookies?.[d])throw Error("Cookie not present");let t=s({encryptedString:e.cookies[d]});if(!t)throw Error("Invalid Token");if((o=JSON.parse(t)).databaseSlug===r)return{dbUserId:i=o.rootUserId,rootUserId:o.rootUserId,rootUserName:o.rootUserName,rootUserEmail:o.rootUserEmail,rootUserImage:o.rootUserImage,databaseFullName:o.databaseFullName,databaseSlug:o.databaseSlug,allowedTables:o.allowedTables,priviledges:o.priviledges,database:o.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:i}}catch(e){return null}}},96771:(e,r,t)=>{let s=t(21339);e.exports=async function({dbName:e,entryId:r,entryOrder:t,tableName:a,tableSchema:i}){try{if(i.fields.find(e=>!!e.fieldName?.match(/^order$/i))&&t){let i=await s({database:e,paradigm:"Full Access",queryString:`SELECT * FROM ${a} WHERE \`order\` = '${t}' AND id != ?`,queryValues:[String(r)]});if(!i?.[0])throw Error("No Existing Order");await s({database:e,paradigm:"Full Access",queryString:`UPDATE ${a} SET \`order\` = \`order\` + 1 WHERE \`order\` >= ${t} AND id != ?`,queryValues:[String(r)]})}return!0}catch(e){return!1}}},6420:(e,r,t)=>{t(81630);let s=t(51348),a=t(72835),i=t(29021),o=t(31341);async function l(e,r,t,l){let{keyCookieName:n,csrfCookieName:d}=o();if(!e.cookies?.[n]?.match(/./))return null;let u=a({enc
2024-12-08 19:56:57 +00:00
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),i?.url&&(a+=`
URL: ${i.url}`),i?.body&&(a+=`
Request Body: ${JSON.stringify(i.body,null,4)}`),l&&(a+=`
IP: ${l}`),a+=`
Date: ${o.toDateString()}
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let n=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",a),s.appendFileSync("./.tmp/error.log",`
${n}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},72835:(e,r,t)=>{let{scryptSync:s,createDecipheriv:a}=t(55511),{Buffer:i}=t(79428);e.exports=({encryptedString:e,encryptionKey:r,encryptionSalt:t})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let o=r||process.env.DSQL_ENCRYPTION_PASSWORD,l=t||process.env.DSQL_ENCRYPTION_SALT,n=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!o?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=a("aes-192-cbc",s(o,l,n),i.alloc(16,0));try{let r=d.update(e,"hex","utf8");return r+=d.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[4050],()=>t(14373));module.exports=s})();