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

16 lines
7.4 KiB
JavaScript
Raw Normal View History

2025-01-14 06:42:13 +00:00
"use strict";(()=>{var e={};e.id=460,e.ids=[460],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")},66912:(e,r,t)=>{t.r(r),t.d(r,{config:()=>p,default:()=>f,routeModule:()=>g});var s={};t.r(s),t.d(s,{default:()=>E});var a=t(89947),o=t(2706),i=t(96762),n=t(77377),l=t(98e3),d=t(31495),u=t(60125),c=t(67619),_=t(69842);async function E(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,_.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"User Auth Failed"});let{tableName:s,payload:a,tableSchema:o,dbSlug:i,dbId:E,delegated:f}=e.body;try{let c=await (0,u.A)({databaseSlug:i,request:e,user:t,query:e.query});if(!await (0,d.A)({user:t,confirmedDelegetedUser:c,database:i,table:s,dbId:E,priviledgeRegex:/Update Entries/i}))return r.json({success:!1,msg:"Unauthorized"});let _=c?.rootUserId?`datasquirel_user_${c.rootUserId}_${i}`:`datasquirel_user_${t.id}_${i}`,f=await (0,l.A)({dbContext:"Dsql User",paradigm:"Full Access",dbFullName:_,tableName:s,data:a,tableSchema:o});if(!f.insertId)throw console.log("Table Insertion Failed =>",f),Error(f?.error||"Table Insertion Failed");await (0,n.A)({dbName:_,entryId:f.insertId,entryOrder:a.order,tableName:s,tableSchema:o}),r.json({success:!0})}catch(e){(0,c.A)({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 f=(0,i.M)(s,"default"),p=(0,i.M)(s,"config"),g=new a.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/addTableEntry",pathname:"/api/addTableEntry",bundlePath:"",filename:""},userland:s})},31495:(e,r,t)=>{t.d(r,{A:()=>o});var s=t(48786),a=t(67619);async function o({user:e,confirmedDelegetedUser:r,database:t,table:o,priviledgeRegex:i,dbId:n}){let l,d;try{r?.delegated?(l=await (0,s.A)("SELECT priviledge FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=? AND `table`=?",[r.rootUserId,e.id,t,o]),d=l[0]?.priviledge?.match(i)):(l=await (0,s.A)("SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?",[e.id,o,n]),d=!0)}catch(r){(0,a.A)({component:"checkUserRights",message:r.message,user:e})}return!!l&&!!l[0]&&!!d}},60125:(e,r,t)=>{t.d(r,{A:()=>a});var s=t(95969);async function a({request:e,databaseSlug:r,user:t,query:a}){try{let o=t.id,i=null;if(!a?.delegated)return{dbUserId:o};let n=a.dbUserId,l=`${process.env.DSQL_USER_DB_PREFIX}${n}_${r}`,d=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${l}`;try{if(!e.cookies?.[d])throw Error("Cookie not present");let t=(0,s.A)({encryptedString:e.cookies[d]});if(!t)throw Error("Invalid Token");if((i=JSON.parse(t)).databaseSlug===r)return{dbUserId:o=i.rootUserId,rootUserId:i.rootUserId,rootUserName:i.rootUserName,rootUserEmail:i.rootUserEmail,rootUserImage:i.rootUserImage,databaseFullName:i.databaseFullName,databaseSlug:i.databaseSlug,allowedTables:i.allowedTables,priviledges:i.priviledges,database:i.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:o}}catch(e){return null}}},77377:(e,r,t)=>{t.d(r,{A:()=>a});var s=t(37275);async function a({dbName:e,entryId:r,entryOrder:t,tableName:a,tableSchema:o}){try{if(o.fields.find(e=>!!e.fieldName?.match(/^order$/i))&&t){let e=await (0,s.A)({paradigm:"Full Access",queryString:`SELECT * FROM ${a} WHERE \`order\` = '${t}' AND id != ?`,queryValues:[String(r)]});if(!e?.[0])throw Error("No Existing Order");await (0,s.A)({paradigm:"Full Access",queryString:`UPDATE ${a} SET \`order\` = \`order\` + 1 WHERE \`order\` >= ${t} AND id != ?`,queryValues:[String(r)]})}return!0}catch(e){return!1}}},69842:(e,r,t)=>{t.d(r,{A:()=>l});var s=t(48786),a=t(95969),o=t(29021),i=t.n(o),n=t(89159);async function l(e,r,t){try{let{keyCookieName:o,csrfCookieName:l}=(0,n.A)();if(!e.cookies?.[o]?.match(/./))throw Error("Request Cookies not Found!");let d=(0,a.A)({encryptedString:e.cookies[o]})
2024-12-08 19:56:57 +00:00
Error Message: ${r}
2025-01-14 06:19:19 +00:00
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
2024-12-08 19:56:57 +00:00
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
2025-01-14 06:19:19 +00:00
User Email: ${e?.email}`),o?.url&&(s+=`
URL: ${o.url}`),o?.body&&(s+=`
Request Body: ${JSON.stringify(o.body,null,4)}`),n&&(s+=`
IP: ${n}`),s+=`
Date: ${i.toDateString()}
2025-01-14 06:42:13 +00:00
========================================`,a().existsSync("./.tmp/error.log")||a().writeFileSync("./.tmp/error.log","","utf-8");let l=a().readFileSync("./.tmp/error.log","utf-8");a().writeFileSync("./.tmp/error.log",s),a().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-01-14 06:42:13 +00:00
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>o});var s=t(55511),a=t(79428);function o({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,i=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(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let l=(0,s.scryptSync)(o,i,n),d=a.Buffer.alloc(16,0),u=(0,s.createDecipheriv)("aes-192-cbc",l,d);try{let r=u.update(e,"hex","utf8");return r+=u.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,[1251],()=>t(66912));module.exports=s})();