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

16 lines
12 KiB
JavaScript
Raw Normal View History

2024-12-09 09:39:09 +00:00
"use strict";exports.id=9914,exports.ids=[9914],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({encrypte
2024-12-08 19:56:57 +00:00
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",`
2024-12-09 09:39:09 +00:00
${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:()=>f,getServerSideProps:()=>S});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),y=t.n(_),b=e([c,p]);[c,p]=b.then?(await b)():b;let x=t(29021),D=n().createContext({});function f({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 S({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(x.readFileSync(`${process.e