dsql-admin/dsql-app/.local_dist/server/pages/api/addTableEntry.js
Benjamin Toby 81cf010cb5 Updates
2025-01-14 16:27:08 +01:00

16 lines
5.8 KiB
JavaScript

"use strict";(()=>{var e={};e.id=460,e.ids=[460],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},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:()=>f,default:()=>p,routeModule:()=>y});var a={};t.r(a),t.d(a,{default:()=>m});var s=t(89947),i=t(2706),l=t(96762),o=t(77377),d=t(98e3),n=t(31495),u=t(60125),c=t(67619),g=t(69842);async function m(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,g.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"User Auth Failed"});let{tableName:a,payload:s,tableSchema:i,dbSlug:l,dbId:m,delegated:p}=e.body;try{let c=await (0,u.A)({databaseSlug:l,request:e,user:t,query:e.query});if(!await (0,n.A)({user:t,confirmedDelegetedUser:c,database:l,table:a,dbId:m,priviledgeRegex:/Update Entries/i}))return r.json({success:!1,msg:"Unauthorized"});let g=c?.rootUserId?`datasquirel_user_${c.rootUserId}_${l}`:`datasquirel_user_${t.id}_${l}`,p=await (0,d.A)({dbContext:"Dsql User",paradigm:"Full Access",dbFullName:g,tableName:a,data:s,tableSchema:i});if(!p.insertId)throw console.log("Table Insertion Failed =>",p),Error(p?.error||"Table Insertion Failed");await (0,o.A)({dbName:g,entryId:p.insertId,entryOrder:s.order,tableName:a,tableSchema:i}),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 p=(0,l.M)(a,"default"),f=(0,l.M)(a,"config"),y=new s.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addTableEntry",pathname:"/api/addTableEntry",bundlePath:"",filename:""},userland:a})},31495:(e,r,t)=>{t.d(r,{A:()=>i});var a=t(48786),s=t(67619);async function i({user:e,confirmedDelegetedUser:r,database:t,table:i,priviledgeRegex:l,dbId:o}){let d,n;try{r?.delegated?(d=await (0,a.A)("SELECT priviledge FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=? AND `table`=?",[r.rootUserId,e.id,t,i]),n=d[0]?.priviledge?.match(l)):(d=await (0,a.A)("SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?",[e.id,i,o]),n=!0)}catch(r){(0,s.A)({component:"checkUserRights",message:r.message,user:e})}return!!d&&!!d[0]&&!!n}},60125:(e,r,t)=>{t.d(r,{A:()=>s});var a=t(95969);async function s({request:e,databaseSlug:r,user:t,query:s}){try{let i=t.id,l=null;if(!s?.delegated)return{dbUserId:i};let o=s.dbUserId,d=`${process.env.DSQL_USER_DB_PREFIX}${o}_${r}`,n=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${d}`;try{if(!e.cookies?.[n])throw Error("Cookie not present");let t=(0,a.A)({encryptedString:e.cookies[n]});if(!t)throw Error("Invalid Token");if((l=JSON.parse(t)).databaseSlug===r)return{dbUserId:i=l.rootUserId,rootUserId:l.rootUserId,rootUserName:l.rootUserName,rootUserEmail:l.rootUserEmail,rootUserImage:l.rootUserImage,databaseFullName:l.databaseFullName,databaseSlug:l.databaseSlug,allowedTables:l.allowedTables,priviledges:l.priviledges,database:l.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:i}}catch(e){return null}}},77377:(e,r,t)=>{t.d(r,{A:()=>s});var a=t(37897);async function s({dbName:e,entryId:r,entryOrder:t,tableName:s,tableSchema:i}){try{if(i.fields.find(e=>!!e.fieldName?.match(/^order$/i))&&t){let e=await (0,a.A)({paradigm:"Full Access",queryString:`SELECT * FROM ${s} WHERE \`order\` = '${t}' AND id != ?`,queryValues:[String(r)]});if(!e?.[0])throw Error("No Existing Order");await (0,a.A)({paradigm:"Full Access",queryString:`UPDATE ${s} 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:()=>i});var a=t(39908),s=t.n(a);async function i(e,r,t){let a=s()({req:e,level:t?"deep":void 0});return console.log(a),a.payload}},67619:(e,r,t)=>{t.d(r,{A:()=>i});var a=t(29021),s=t.n(a);async function i({user:e,message:r,component:t,noMail:a,req:i}){let l=new Date,o=(()=>{if(!i)return null;try{let e=i.headers["x-forwarded-for"],r=i.headers["x-real-ip"],t=i.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||a||r||i.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let a=`🚀 SERVER ERROR ===========================
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)}`),o&&(a+=`
IP: ${o}`),a+=`
Date: ${l.toDateString()}
========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let d=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",a),s().appendFileSync("./.tmp/error.log",`
${d}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>l});var a=t(55511),s=t(79428),i=t(32443);function l({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:l,salt:o,keyLen:d,algorithm:n,bufferAllocSize:u}=(0,i.A)({encryptionKey:r});if(!l?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let c=(0,a.scryptSync)(l,o,d),g=s.Buffer.alloc(u,0),m=(0,a.createDecipheriv)(n,c,g);try{let r=m.update(e,"hex","utf8");return r+=m.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),a=r.X(0,[1251],()=>t(66912));module.exports=a})();