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

16 lines
8.1 KiB
JavaScript

"use strict";(()=>{var e={};e.id=8932,e.ids=[8932],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")},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")},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}}})},36629:(e,r,t)=>{t.r(r),t.d(r,{config:()=>_,default:()=>p,routeModule:()=>S});var a={};t.r(a),t.d(a,{default:()=>d});var s=t(89947),n=t(2706),o=t(96762),l=t(69842),i=t(67619),u=t(60125),c=t(30944);async function d(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await (0,l.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let a=e.body;try{let s=await (0,u.A)({databaseSlug:a.dbName,request:e,user:t,query:e.query}),n=s?s?.rootUserId?s.rootUserId:s.dbUserId:null;if(!n)throw Error("User not Found!");let o=`datasquirel_user_${n}_${a.dbName}`,l=a.tableName,i=a.page,d=20*i,p=`SELECT * FROM ${o}.${l}`,_=[];a.search&&a.searchField&&(p+=` WHERE LOWER(\`${a.searchField.toLowerCase().replace(/ /g,"_")}\`) LIKE ?`,_.push(`%${a.search.toLowerCase()}%`)),p+=` ORDER BY id DESC LIMIT 20 OFFSET ${d}`;let S=await (0,c.A)({database:o,queryString:p,queryValuesArray:_,tableSchema:a.tableSchema}),f={success:!0,data:S,page:Number(i)+1};r.json(f)}catch(e){(0,i.A)({component:"/api/infiniteScroll/catch-error",message:e.message,user:t}),r.json({success:!1,data:null})}}let p=(0,o.M)(a,"default"),_=(0,o.M)(a,"config"),S=new s.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/infiniteScroll",pathname:"/api/infiniteScroll",bundlePath:"",filename:""},userland:a})},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 n=t.id,o=null;if(!s?.delegated)return{dbUserId:n};let l=s.dbUserId,i=`${process.env.DSQL_USER_DB_PREFIX}${l}_${r}`,u=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${i}`;try{if(!e.cookies?.[u])throw Error("Cookie not present");let t=(0,a.A)({encryptedString:e.cookies[u]});if(!t)throw Error("Invalid Token");if((o=JSON.parse(t)).databaseSlug===r)return{dbUserId:n=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:n}}catch(e){return null}}},69842:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(39908),s=t.n(a);async function n(e,r,t){let a=s()({req:e,level:t?"deep":void 0});return console.log(a),a.payload}},43775:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(95969);let s=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;async function n({unparsedResults:e,tableSchema:r}){let t=[];try{for(let n=0;n<e.length;n++){let o=e[n],l=Object.keys(o);for(let e=0;e<l.length;e++){let t=l[e],n=r?.fields[e];if(t?.match(s))continue;let i=o[t];("number"==typeof i||i)&&n?.encrypted&&i?.match(/./)&&(o[t]=(0,a.A)({encryptedString:i}))}t.push(o)}return t}catch(r){return console.log("ERROR in parseDbResults Function =>",r.message),e}}},67619:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(29021),s=t.n(a);async function n({user:e,message:r,component:t,noMail:a,req:n}){let o=new Date,l=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],r=n.headers["x-real-ip"],t=n.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||a||r||n.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}`),n?.url&&(a+=`
URL: ${n.url}`),n?.body&&(a+=`
Request Body: ${JSON.stringify(n.body,null,4)}`),l&&(a+=`
IP: ${l}`),a+=`
Date: ${o.toDateString()}
========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let i=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",a),s().appendFileSync("./.tmp/error.log",`
${i}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},30944:(e,r,t)=>{t.d(r,{A:()=>l});var a=t(43775),s=t(67619),n=t(7447),o=t(64292);async function l({queryString:e,queryValuesArray:r,database:t,tableSchema:l,useLocal:i,debug:u}){let c=(0,n.A)({fa:!0});i&&(c=(0,n.A)({local:!0})),t?.match(/^datasquirel$/)&&(c=(0,n.A)()),u&&(console.log("varDatabaseDbHandler:query:",e),console.log("varDatabaseDbHandler:values:",r));let d=await (0,o.A)(c,e,r);if(u&&console.log("varDatabaseDbHandler:results:",d),d&&l)try{return await (0,a.A)({unparsedResults:d,tableSchema:l})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),(0,s.A)({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(d)return d;else return null}},95969:(e,r,t)=>{t.d(r,{A:()=>o});var a=t(55511),s=t(79428),n=t(32443);function o({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:o,salt:l,keyLen:i,algorithm:u,bufferAllocSize:c}=(0,n.A)({encryptionKey:r});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=(0,a.scryptSync)(o,l,i),p=s.Buffer.alloc(c,0),_=(0,a.createDecipheriv)(u,d,p);try{let r=_.update(e,"hex","utf8");return r+=_.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},64292:(e,r,t)=>{async function a(e,r,t){try{if("string"==typeof r){let a=await e.query(s(r),t);return JSON.parse(JSON.stringify(a))}if("object"!=typeof r)return null;{let t=[];for(let a=0;a<r.length;a++)try{let n=r[a],o=await e.query(s(n.query),n.values);t.push(JSON.parse(JSON.stringify(o)))}catch(e){t.push(null)}return t}}catch(e){return null}finally{e.end()}}function s(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}t.d(r,{A:()=>a})},7447:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(9973),s=t.n(a);function n(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||s()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||s()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||s()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}},32443:(e,r,t)=>{t.d(r,{A:()=>a});function a(e){return{key:e?.encryptionKey||process.env.DSQL_ENCRYPTION_PASSWORD,keyLen:process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24,salt:e?.encryptionSalt||process.env.DSQL_ENCRYPTION_SALT,apiKey:e?.apiKey||process.env.DSQL_API_KEY,algorithm:e?.algorithm||process.env.DSQL_ENCRYPTION_ALGORITHM||"aes-192-cbc",bufferAllocSize:e?.bufferAllocSize||(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE?function(e,r){try{let r=Number(e);if("number"!=typeof r||isNaN(r))return 0;return Math.round(r)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},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=r(r.s=36629);module.exports=t})();