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

13 lines
13 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"use strict";exports.id=2996,exports.ids=[2996],exports.modules={55312:(e,a,t)=>{t.d(a,{A:()=>o});var s=t(8732),l=t(82015),i=t.n(l),r=t(32415),n=t(2471);t(27462),t(55158);var d=t(56987),c=t(12042);function o(e){let{user:a,dbImage:t,setDbImage:l,query:o}=i().useContext(n.AddDatabaseContext);if(!a)return(0,s.jsx)(i().Fragment,{});let[u,m]=i().useState(null),[p,g]=i().useState(!1);return(0,s.jsx)("section",{className:"card",children:(0,s.jsxs)("div",{className:"w-full grid grid-cols-1 xl:grid-cols-2 gap-6 items-stretch",children:[p&&(0,s.jsx)(r.A,{}),(0,s.jsxs)("div",{className:"flex-col items-start",children:[(0,s.jsx)("h2",{className:"text-xl m-0 text-left w-full",children:"New Database Information"}),a&&t&&l&&(0,s.jsx)(d.A,{user:a,dbImage:t,setDbImage:l,setLoading:g,query:o})]}),a&&t&&l&&(0,s.jsx)(c.A,{user:a,dbImage:t,setDbImage:l})]})})}},56987:(e,a,t)=>{let s;t.d(a,{A:()=>g});var l=t(8732),i=t(82015),r=t.n(i),n=t(27462),d=t(64535);t(22326);var c=t(63715),o=t(86152);async function u({e,setLoading:a,dbImage:t,database:s,user:l}){a(!0);let i={db_description:e.target.database_description?.value?.match(/./)?e.target.database_description.value:null,db_name:e.target.database_name?.value?.match(/./)?e.target.database_name.value:null,db_slug:e.target.database_slug?.value?.match(/./)?e.target.database_slug.value:null,db_full_name:s.db_full_name,id:s.id,active_clone:s.active_clone,active_clone_parent_db:s.active_clone_parent_db};if(t){if("string"==typeof t)i.db_image=t;else if("object"==typeof t){let e=await (0,c.A)("/api/addUserMedia",{method:"post",body:{media:[t],folder:i.db_slug.replace(/_/g,"-"),type:"image"}},!0);i.db_image=e?.mediaData[0]?.media_thumbnail_url?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}else i.db_image="/images/database-placeholder.png";(0,c.A)("/api/updateUserDatabase",{method:"post",body:i},!0).then(e=>{e.success?(0,o.A)().then(()=>{window.location.pathname=`/admin/${l?.id}/databases`,setTimeout(()=>{a(!1)},1e3)}):(alert("Error! Please Try Again"),setTimeout(()=>{a(!1)},1e3))})}async function m({e,setLoading:a,dbImage:t,keepUpdated:s,keepDataUpdated:l,query:i,user:r}){a(!0);let n={db_name:e.target.database_name.value,db_slug:e.target.database_slug.value,db_description:e.target.database_description?.value?.match(/./)?e.target.database_description.value:null};if(t){if("string"==typeof t)n.db_image=t;else if("object"==typeof t){let e=await (0,c.A)("/api/addUserMedia",{method:"post",body:{media:[t],folder:n.db_slug.replace(/_/g,"-"),type:"image"}},!0);n.db_image=e?.mediaData[0]?.media_thumbnail_url?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}i?.duplicate&&(n.duplicate=i.duplicate,n.keepUpdated=!!s&&s,n.keepDataUpdated=!!l&&l),(0,c.A)("/api/createUserDatabase",{method:"post",body:n},!0).then(e=>{e.success?(0,o.A)().then(()=>{window.location.pathname=`/admin/${r?.id}/databases/${n.db_slug}`}):setTimeout(()=>{a(!1)},1e3)})}var p=t(58403);function g({user:e,dbImage:a,setDbImage:t,database:i,setLoading:c,query:o}){async function g(a){return i?.db_slug===a?null:await (0,n.A)({tableName:"user_databases",columnName:"db_slug",value:a,userId:e.id})}let[h,b]=r().useState(null),[x,f]=r().useState(!1),[_,w]=r().useState(!1);return(0,l.jsxs)("form",{className:"w-full max-w-none xl:max-w-lg flex flex-col items-start gap-4 relative",onSubmit:t=>{t.preventDefault(),i?u({e:t,setLoading:c,dbImage:a,database:i,user:e}):m({e:t,setLoading:c,dbImage:a,keepUpdated:x,keepDataUpdated:_,query:o,user:e})},children:[h&&(0,l.jsx)(d.A,{message:h}),(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,l.jsx)("label",{htmlFor:"database_name",children:"Name"}),(0,l.jsx)("input",{type:"text",name:"database_name",id:"database_name",placeholder:"Database Name",onInput:async e=>{let a=e.target,t=a.closest("form");if(a.value.match(/./)?(a.classList.remove("warning"),b(null)):a.classList.add("warning"),t){t.database_slug.value=a.value.toLowerCase().replace(/ /g,"_").replace(/[^a-zA-Z0-9-_]/g,"");let e=t.database_slug.value;window.clearTimeout(s),s=setTimeout(()=>{
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 r=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",i),s.appendFileSync("./.tmp/error.log",`
${r}`)}},13608:(e,a,t)=>{let s=t(9973),l=t(31976),i=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,charset:"utf8mb4",ssl:l()}});e.exports=function(...e){try{return new Promise((a,t)=>{i.query(...e).then(e=>{i.end(),a(JSON.parse(JSON.stringify(e)))}).catch(e=>{i.end(),a({error:e.message,sql:e.sql})})})}catch(e){return{success:!1,error:e.message}}}},2471:(e,a,t)=>{t.r(a),t.d(a,{AddDatabaseContext:()=>f,default:()=>_,getServerSideProps:()=>w});var s=t(8732),l=t(82015),i=t.n(l),r=t(95222),n=t(20048),d=t.n(n),c=t(41658),o=t.n(c),u=t(46437),m=t(58548),p=t(55312);function g(e){let{query:a,duplicateDb:t,user:l}=i().useContext(f),r=a?.duplicate?(0,s.jsxs)("span",{children:["Duplicate"," ",(0,s.jsx)("a",{href:`/admin/${l?.id}/databases/${t?.db_slug}`,target:"_blank",children:t?.db_name})," ","Database"]}):"Add A New Database";return(0,s.jsxs)(i().Fragment,{children:[(0,s.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,s.jsxs)("div",{className:"flex-wrap",children:[(0,s.jsx)(u.A,{}),(0,s.jsx)("h1",{className:"text-3xl m-0",children:r})]}),(0,s.jsx)(m.A,{user:l})]}),(0,s.jsx)(p.A,{})]})}var h=t(42105),b=t(67216),x=t.n(b);let f=i().createContext({});function _({user:e,databases:a,query:t,duplicateDb:l}){let n=(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("title",{children:"Add Database | Datasquirel"}),(0,s.jsx)("meta",{name:"description",content:"Add a database"})]}),[d,c]=i().useState("/images/database-placeholder.png");return(0,s.jsx)(r.A,{head:n,user:e,children:(0,s.jsxs)(f.Provider,{value:{user:e,databases:a,dbImage:d,setDbImage:c,query:t,duplicateDb:l},children:[(0,s.jsx)(g,{}),(0,s.jsx)(h.A,{setDbImage:c})]})})}async function w({req:e,res:a,query:t}){let s=await d()(e,a);if(!s?.logged_in_status)return{redirect:{destination:"/login",permanent:!1}};if(!s?.verification_status?.toString()?.match(/1/))return{redirect:{destination:"/admin",permanent:!1}};let l=await o()(`SELECT SCHEMA_NAME AS dbFullName FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME LIKE 'user_${s.id}%'`),i={};if(t.duplicate){let e=await x()(`SELECT * FROM user_databases WHERE db_full_name='${t.duplicate}'`);e&&e[0]&&(i=e[0])}return{props:{user:s,databases:l,query:t,duplicateDb:i}}}}};