dsql-admin/dsql-app/.local_dist/server/chunks/8370.js

13 lines
11 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"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
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)}})}};