dsql-admin/dsql-app/.local_dist/server/chunks/8370.js
Benjamin Toby 3ffd2d6777 Updates
2024-12-05 08:03:33 +01:00

13 lines
11 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:()=>p});var r=t(8732),l=t(82015),d=t.n(l),n=t(58548),i=t(46437),o=t(63715),c=t(32415),m=t(77826),u=t(87730),h=e([u]);function p(e){let{singleUser:a,database:t,user:s}=d().useContext(u.SingleDbUserContext),l=Object.keys(a).filter(e=>!e.match(/^id$|^date_|^user_id$|^social_|^disk_usage|user_type/)),[h,p]=d().useState(!1),[_,g]=d().useState(a.image);return(0,r.jsxs)(d().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)(i.A,{}),_&&(0,r.jsx)("img",{src:_,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=>{p(!0),window.confirm("Delete this user?")&&(0,o.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)(n.A,{user:s})]}),(0,r.jsxs)("section",{className:"paper",children:[h&&(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(),p(!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 d={dbFullName:t.db_full_name,payload:{...l,id:a.id}};(0,o.A)("/api/updateDbUser",{method:"post",body:d},!0).then(e=>{_?.imageBase64?(_.imageName=`${t.db_slug}-user-${a.id}`,_.mimeType="jpeg",delete _.imageBase64Full,(0,o.A)("/api/addUserMedia",{method:"post",body:{media:[_],folder:t.db_slug.replace(/_/g,"-"),type:"image"}},!0).then(e=>{e&&e.mediaData&&e.mediaData[0]?.media_url?(0,o.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(()=>{p(!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)(m.A,{userImage:_,setUserImage:g,className:"w-full"})]}),(0,r.jsx)("button",{children:"Update User"})]})})]})]})}u=(h.then?(await h)():h)[0],s()}catch(e){s(e)}})},31651:(e,a,t)=>{t(81630);let s=t(83007);e.exports=async function({request:e,databaseSlug:a,user:t,query:r}){try{let l=t.id,d=null;if(!r?.delegated)return{dbUserId:l};let n=r.dbUserId,i=`${process.env.DSQL_USER_DB_PREFIX}${n}_${a}`,o=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${i}`;try{if(!e.cookies?.[o])throw Error("Cookie not present");let t=s(e.cookies[o]);if(!t)throw Error("Invalid Token");if((d=JSON.parse(t)).databaseSlug===a)return{dbUserId:l=d.rootUserId,rootUserId:d.rootUserId,rootUserName:d.rootUserName,rootUserEmail:d.rootUserEmail,rootUserImage:d.rootUserImage,databaseFullName:d.databaseFullName,databaseSlug:d.databaseSlug,allowedTables:d.allowedTables,priviledges:d.priviledges,database:d.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(83007),r=t(68743);e.exports=async function({unparsedResults:e,tableSchema:a}){let t=[];try{for(let l=0;l<e.length;l++){let d=e[l],n=Object.keys(d);for(let e=0;e<n.length;e++){let t=n[e],l=a?.fields[e];if(t?.match(r))continue;let i=d[t];("number"==typeof i||i)&&l?.encrypted&&i?.match(/./)&&(d[t]=s(i))}t.push(d)}return t}catch(a){return console.log("ERROR in parseDbResults Function =>",a.message),e}}},22373:(e,a,t)=>{let s=t(29021);e.exports=async function({user:e,message:a,component:t,noMail:r}){let l=`🚀 SERVER ERROR ===========================
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}
Error Message: ${a}
Component: ${t}
Date: ${Date()}
========================================`;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",l),s.appendFileSync("./.tmp/error.log",`
${d}`)}},90378:(e,a,t)=>{t(29021);let s=t(89545),r=t(22373),l=t(67216),d=t(1231);e.exports=async function({queryString:e,queryValuesArray:a,database:t,tableSchema:n}){let i;let o=!!t?.match(/^datasquirel$/),c=o?l:d;try{i=e&&a&&Array.isArray(a)&&a[0]?o?await c(e,a):await c({paradigm:"Full Access",database:t,queryString:e,queryValues:a}):o?await c(e):await c({paradigm:"Full Access",database:t,queryString:e})}catch(e){r({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(i&&n)try{let e=i;return await s({unparsedResults:e,tableSchema:n})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),r({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(i)return i;else return null}},1231:(e,a,t)=>{let s=t(29021);t(33873);let r=t(9973),l=t(31976),d=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:n}){try{return new Promise((i,o)=>{let c=!!e?.match(/full.access|^fa$/i);try{function m(e){d.end(),i(JSON.parse(JSON.stringify(e)))}function u(e){d.end(),i({error:e.message,queryStringGenerated:t,queryValuesGenerated:n,sql:e.sql})}d=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()}}),n&&Array.isArray(n)&&n[0]?d.query(t,n).then(m).catch(u):d.query(t).then(m).catch(u)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),i({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},87730:(e,a,t)=>{t.a(e,async(e,s)=>{try{t.r(a),t.d(a,{SingleDbUserContext:()=>v,default:()=>f,getServerSideProps:()=>y});var r=t(8732),l=t(82015),d=t.n(l),n=t(95222),i=t(20048),o=t.n(i),c=t(64098),m=t(31651),u=t.n(m),h=t(95248),p=t(67216),_=t.n(p),g=t(90378),b=t.n(g),x=e([c,h]);[c,h]=x.then?(await x)():x;let S=t(29021),v=d().createContext({});function f({user:e,database:a,table:t,dbSchemaData:s,singleUser:l,query:d,confirmedDelegetedUser:i}){let o=`${l.first_name} ${l.last_name} Users | Datasquirel"`,m=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("title",{children:o}),(0,r.jsx)("meta",{name:"description",content:"Welcome to your data app"})]});return(0,r.jsx)(n.A,{head:m,user:e,extraHeaderContent:(0,r.jsx)(c.A,{database:a,query:d,confirmedDelegetedUser:i,user:e}),children:(0,r.jsx)(v.Provider,{value:{user:e,database:a,table:t,dbSchemaData:s,singleUser:l,query:d,confirmedDelegetedUser:i},children:(0,r.jsx)(h.A,{})})})}async function y({req:e,res:a,query:t}){let s=await o()(e,a);if(!s?.logged_in_status)return{redirect:{destination:"/logout",permanent:!1}};let r=await u()({request:e,user:s,databaseSlug:t.single,query:t});if(!r)return{redirect:{destination:"/admin",permanent:!1}};let{dbUserId:l,rootUserId:d}=r,n=await _()(`SELECT * FROM user_databases WHERE user_id='${l}' AND db_slug='${t.single}'`);if(!n||!n[0])return console.log("Database Not Found"),{redirect:{destination:`/admin/${s?.id}/databases`,permanent:!1}};let i=JSON.parse(S.readFileSync(`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${l}/main.json`,"utf-8")),c=(i.filter(e=>e.dbFullName===n[0].db_full_name)[0]?.tables).filter(e=>"users"===e.tableName)[0],m=await b()({database:n[0].db_full_name,queryString:`SELECT * FROM users WHERE id='${t.user}'`,tableSchema:c});return m?.[0]?{props:{user:s,database:n?.[0]||null,table:c||{},dbSchemaData:i,singleUser:m?.[0]||null,query:t,confirmedDelegetedUser:r}}:{redirect:{destination:`/admin/${s?.id}/databases/${n[0].db_slug}/users`,permanent:!1}}}s()}catch(e){s(e)}})}};