dsql-admin/dsql-app/.local_dist/server/chunks/8370.js
Benjamin Toby 86f931fb82 Updates
2024-12-08 09:57:48 +01:00

16 lines
12 KiB
JavaScript

"use strict";exports.id=8370,exports.ids=[8370],exports.modules={95248:(e,a,t)=>{t.a(e,async(e,s)=>{try{t.d(a,{A:()=>h});var r=t(8732),l=t(82015),n=t.n(l),o=t(58548),d=t(46437),i=t(63715),c=t(32415),u=t(77826),m=t(87730),p=e([m]);function h(e){let{singleUser:a,database:t,user:s}=n().useContext(m.SingleDbUserContext),l=Object.keys(a).filter(e=>!e.match(/^id$|^date_|^user_id$|^social_|^disk_usage|user_type/)),[p,h]=n().useState(!1),[g,_]=n().useState(a.image);return(0,r.jsxs)(n().Fragment,{children:[(0,r.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,r.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(d.A,{}),g&&(0,r.jsx)("img",{src:g,alt:"",className:"avatar large outlined"}),(0,r.jsxs)("h1",{className:"text-3xl m-0",children:[a.first_name," ",a.last_name]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:`/admin/${s?.id}/databases/${t.db_slug}/users/${a.id}/change-password`,className:"button outlined gray",children:"Change Password"}),(0,r.jsx)("button",{className:"bg-red-500",onClick:e=>{h(!0),window.confirm("Delete this user?")&&(0,i.A)("/api/deleteDbUser",{method:"post",body:{userId:a.id,dbFullName:t.db_full_name}},!0).then(e=>{e.success&&(window.location.pathname=`/admin/${s?.id}/databases/${t.db_slug}/users`)})},children:"Delete User"})]})]}),(0,r.jsx)(o.A,{user:s})]}),(0,r.jsxs)("section",{className:"paper",children:[p&&(0,r.jsx)(c.A,{}),(0,r.jsx)("div",{className:"w-full flex-col items-stretch",children:(0,r.jsxs)("form",{className:"flex flex-col items-stretch gap-4",onSubmit:e=>{e.preventDefault(),h(!0);let s=e.target,r=Array.from(s),l={};r.forEach(e=>{!e?.nodeName?.match(/button/i)&&e?.name&&e?.value?.match(/./)&&(e?.name?.match(/username|email/)||(l[e.name]=e.value))});let n={dbFullName:t.db_full_name,payload:{...l,id:a.id}};(0,i.A)("/api/updateDbUser",{method:"post",body:n},!0).then(e=>{g?.imageBase64?(g.imageName=`${t.db_slug}-user-${a.id}`,g.mimeType="jpeg",delete g.imageBase64Full,(0,i.A)("/api/addUserMedia",{method:"post",body:{media:[g],folder:t.db_slug.replace(/_/g,"-"),type:"image"}},!0).then(e=>{e&&e.mediaData&&e.mediaData[0]?.media_url?(0,i.A)("/api/updateDbUser",{method:"post",body:{dbFullName:t.db_full_name,payload:{id:a.id,image:e.mediaData[0].media_url,image_thumbnail:e.mediaData[0].media_thumbnail_url}}},!0).then(e=>{e.success&&window.location.reload(),setTimeout(()=>{h(!1)},500)}):window.location.reload()})):window.location.reload()})},children:[l.map((e,t)=>e?.match(/password|^database|email|username/)?(0,r.jsxs)("div",{className:"flex-col items-start w-full gap-1",children:[(0,r.jsx)("label",{htmlFor:e,children:e}),(0,r.jsx)("input",{type:"text",name:e,id:e,value:a[e],placeholder:e,className:"opacity-40 pointer-events-none",onChange:e=>{e.preventDefault()}},t+1)]},t+1):e?.match(/more_user_data/)?(0,r.jsxs)("div",{className:"flex-col items-start w-full gap-1",children:[(0,r.jsx)("label",{htmlFor:e,children:e}),(0,r.jsx)("textarea",{name:e,id:e,defaultValue:a[e]?a[e]:void 0,placeholder:e,rows:6},t+1)]},t+1):(0,r.jsxs)("div",{className:"flex-col items-start w-full gap-1",children:[(0,r.jsx)("label",{htmlFor:e,children:e}),(0,r.jsx)("input",{type:"text",name:e,id:e,defaultValue:a[e]?a[e]:void 0,placeholder:e},t+1)]},t+1)),(0,r.jsxs)("div",{className:"border border-slate-300 dark:border-slate-600 border-solid bg-slate-100 dark:bg-slate-700 rounded p-6 flex-col items-start w-full",children:[(0,r.jsx)("h3",{className:"m-0 text-lg font-semibold mb-1 text-slate-600",children:"Update Image"}),(0,r.jsx)(u.A,{userImage:g,setUserImage:_,className:"w-full"})]}),(0,r.jsx)("button",{children:"Update User"})]})})]})]})}m=(p.then?(await p)():p)[0],s()}catch(e){s(e)}})},31651:(e,a,t)=>{t(81630);let s=t(77463);e.exports=async function({request:e,databaseSlug:a,user:t,query:r}){try{let l=t.id,n=null;if(!r?.delegated)return{dbUserId:l};let o=r.dbUserId,d=`${process.env.DSQL_USER_DB_PREFIX}${o}_${a}`,i=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${d}`;try{if(!e.cookies?.[i])throw Error("Cookie not present");let t=s({encryptedString:e.cookies[i]});if(!t)throw Error("Invalid Token");if((n=JSON.parse(t)).databaseSlug===a)return{dbUserId:l=n.rootUserId,rootUserId:n.rootUserId,rootUserName:n.rootUserName,rootUserEmail:n.rootUserEmail,rootUserImage:n.rootUserImage,databaseFullName:n.databaseFullName,databaseSlug:n.databaseSlug,allowedTables:n.allowedTables,priviledges:n.priviledges,database:n.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:l}}catch(e){return null}}},48987:(e,a,t)=>{var s=t(24994);a.A=void 0;var r=s(t(30887)),l=t(8732);a.A=(0,r.default)([(0,l.jsx)("path",{d:"M7 3h10v1H7zm0 17h10v1H7z",opacity:".3"},"0"),(0,l.jsx)("path",{d:"m22 12-4-4v3h-5v2h5v3zm-5 6H7V6h10v1h2V3c0-1.1-.9-2-2-2L7 1.01C5.9 1.01 5 1.9 5 3v18c0 1.1.9 2 2 2h10c1.1 0 2-.9 2-2v-4h-2zM7 3h10v1H7zm10 18H7v-1h10z"},"1")],"SendToMobileTwoTone")},42125:(e,a,t)=>{var s=t(24994);a.A=void 0;var r=s(t(30887)),l=t(8732);a.A=(0,r.default)([(0,l.jsx)("path",{d:"M14 5H5v14h14v-9h-5zM8 17c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1m0-4c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1m0-4c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1",opacity:".3"},"0"),(0,l.jsx)("circle",{cx:"8",cy:"8",r:"1"},"1"),(0,l.jsx)("path",{d:"M15 3H5c-1.1 0-1.99.9-1.99 2L3 19c0 1.1.89 2 1.99 2H19c1.1 0 2-.9 2-2V9zm4 16H5V5h9v5h5z"},"2"),(0,l.jsx)("circle",{cx:"8",cy:"12",r:"1"},"3"),(0,l.jsx)("circle",{cx:"8",cy:"16",r:"1"},"4")],"SummarizeTwoTone")},50993:(e,a,t)=>{var s=t(24994);a.A=void 0;var r=s(t(30887)),l=t(8732);a.A=(0,r.default)([(0,l.jsx)("path",{d:"M14.5 9.5C14.5 6.47 12.03 4 9 4S3.5 6.47 3.5 9.5c0 2.47 1.49 3.89 2.35 4.5h6.3c.86-.61 2.35-2.03 2.35-4.5",opacity:".3"},"0"),(0,l.jsx)("path",{d:"M7 20h4c0 1.1-.9 2-2 2s-2-.9-2-2m-2-1h8v-2H5zm11.5-9.5c0 3.82-2.66 5.86-3.77 6.5H5.27c-1.11-.64-3.77-2.68-3.77-6.5C1.5 5.36 4.86 2 9 2s7.5 3.36 7.5 7.5m-2 0C14.5 6.47 12.03 4 9 4S3.5 6.47 3.5 9.5c0 2.47 1.49 3.89 2.35 4.5h6.3c.86-.61 2.35-2.03 2.35-4.5m6.87-2.13L20 8l1.37.63L22 10l.63-1.37L24 8l-1.37-.63L22 6zM19 6l.94-2.06L22 3l-2.06-.94L19 0l-.94 2.06L16 3l2.06.94z"},"1")],"TipsAndUpdatesTwoTone")},96089:(e,a,t)=>{t.d(a,{A:()=>s});let s=(0,t(82544).A)("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]])},98136:(e,a,t)=>{t.d(a,{A:()=>s});let s=(0,t(82544).A)("SquareTerminal",[["path",{d:"m7 11 2-2-2-2",key:"1lz0vl"}],["path",{d:"M11 13h4",key:"1p7l4v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}]])},68743:e=>{e.exports=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/},89545:(e,a,t)=>{let s=t(77463),r=t(68743);e.exports=async function({unparsedResults:e,tableSchema:a}){let t=[];try{for(let l=0;l<e.length;l++){let n=e[l],o=Object.keys(n);for(let e=0;e<o.length;e++){let t=o[e],l=a?.fields[e];if(t?.match(r))continue;let d=n[t];("number"==typeof d||d)&&l?.encrypted&&d?.match(/./)&&(n[t]=s({encryptedString:d}))}t.push(n)}return t}catch(a){return console.log("ERROR in parseDbResults Function =>",a.message),e}}},22373:(e,a,t)=>{let s=t(29021),{IncomingMessage:r}=t(81630);e.exports=async function({user:e,message:a,component:t,noMail:r,req:l}){let n=new Date,o=(()=>{if(!l)return null;try{let e=l.headers["x-forwarded-for"],a=l.headers["x-real-ip"],t=l.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],r=t||s||a||l.socket.remoteAddress;if(!r)return null;return String(r)}catch(e){return null}})();try{let r=`🚀 SERVER ERROR ===========================
Error Message: ${a}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(r+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),l?.url&&(r+=`
URL: ${l.url}`),l?.body&&(r+=`
Request Body: ${JSON.stringify(l.body,null,4)}`),o&&(r+=`
IP: ${o}`),r+=`
Date: ${n.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",r),s.appendFileSync("./.tmp/error.log",`
${d}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},90378:(e,a,t)=>{t(29021);let s=t(89545),r=t(22373),l=t(67216),n=t(1231),o=t(88896);e.exports=async function({queryString:e,queryValuesArray:a,database:t,tableSchema:d,useLocal:i}){let c;let u=!!t?.match(/^datasquirel$/),m=i?o:u?l:n;try{c=e&&a&&Array.isArray(a)&&a[0]?u?await m(e,a):await m({paradigm:"Full Access",database:t,queryString:e,queryValues:a}):u?await m(e):await m({paradigm:"Full Access",database:t,queryString:e})}catch(e){r({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(c&&d)try{let e=c;return await s({unparsedResults:e,tableSchema:d})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),r({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(c)return c;else return null}},1231:(e,a,t)=>{let s=t(29021);t(33873);let r=t(9973),l=t(31976),n=r({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,charset:"utf8mb4",ssl:l()}});e.exports=function({paradigm:e,database:a,queryString:t,queryValues:o}){try{return new Promise((d,i)=>{let c=!!e?.match(/full.access|^fa$/i);try{function u(e){n.end(),d(JSON.parse(JSON.stringify(e)))}function m(e){n.end(),d({error:e.message,queryStringGenerated:t,queryValuesGenerated:o,sql:e.sql})}n=c?r({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,database:a,ssl:l()}}):r({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,database:a,ssl:l()}}),o&&Array.isArray(o)&&o[0]?n.query(t,o).then(u).catch(m):n.query(t).then(u).catch(m)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),d({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},88896:(e,a,t)=>{let s=t(9973),r=t(31976);async function l(...e){let a=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:r()},onConnect:()=>{console.log("Connection Successful!")},onConnectError:e=>{console.log("Connection Error",e.message)},onError:e=>{console.log("Client Error",e.message)}});console.log("Querying ...");try{let t=await a.query(...e);return await a.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e.message),{success:!1,error:e.message}}}e.exports=l},87730:(e,a,t)=>{t.a(e,async(e,s)=>{try{t.r(a),t.d(a,{SingleDbUserContext:()=>D,default:()=>x,getServerSideProps:()=>y});var r=t(8732),l=t(82015),n=t.n(l),o=t(95222),d=t(20048),i=t.n(d),c=t(64098),u=t(31651),m=t.n(u),p=t(95248),h=t(67216),g=t.n(h),_=t(90378),b=t.n(_),f=e([c,p]);[c,p]=f.then?(await f)():f;let S=t(29021),D=n().createContext({});function x({user:e,database:a,table:t,dbSchemaData:s,singleUser:l,query:n,confirmedDelegetedUser:d}){let i=`${l.first_name} ${l.last_name} Users | Datasquirel"`,u=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("title",{children:i}),(0,r.jsx)("meta",{name:"description",content:"Welcome to your data app"})]});return(0,r.jsx)(o.A,{head:u,user:e,extraHeaderContent:(0,r.jsx)(c.A,{database:a,query:n,confirmedDelegetedUser:d,user:e}),children:(0,r.jsx)(D.Provider,{value:{user:e,database:a,table:t,dbSchemaData:s,singleUser:l,query:n,confirmedDelegetedUser:d},children:(0,r.jsx)(p.A,{})})})}async function y({req:e,res:a,query:t}){let s=await i()(e,a);if(!s?.logged_in_status)return{redirect:{destination:"/logout",permanent:!1}};let r=await m()({request:e,user:s,databaseSlug:t.single,query:t});if(!r)return{redirect:{destination:"/admin",permanent:!1}};let{dbUserId:l,rootUserId:n}=r,o=await g()(`SELECT * FROM user_databases WHERE user_id='${l}' AND db_slug='${t.single}'`);if(!o||!o[0])return console.log("Database Not Found"),{redirect:{destination:`/admin/${s?.id}/databases`,permanent:!1}};let d=JSON.parse(S.readFileSync(`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${l}/main.json`,"utf-8")),c=(d.filter(e=>e.dbFullName===o[0].db_full_name)[0]?.tables).filter(e=>"users"===e.tableName)[0],u=await b()({database:o[0].db_full_name,queryString:`SELECT * FROM users WHERE id='${t.user}'`,tableSchema:c});return u?.[0]?{props:{user:s,database:o?.[0]||null,table:c||{},dbSchemaData:d,singleUser:u?.[0]||null,query:t,confirmedDelegetedUser:r}}:{redirect:{destination:`/admin/${s?.id}/databases/${o[0].db_slug}/users`,permanent:!1}}}s()}catch(e){s(e)}})}};