1 line
8.2 KiB
JavaScript
1 line
8.2 KiB
JavaScript
"use strict";exports.id=7769,exports.ids=[7769],exports.modules={59023:(e,a,s)=>{s.d(a,{A:()=>r});var t=s(8732),n=s(23293);function r(){return(0,t.jsx)("button",{className:"outlined gray p-2 w-9 h-9 flex items-center justify-center rounded-full",onClick:e=>{window.history.back()},children:(0,t.jsx)(n.A,{})})}s(82015)},73872:(e,a,s)=>{s.a(e,async(e,t)=>{try{s.d(a,{A:()=>o});var n=s(8732);s(82015);var r=s(96089),l=s(75979),i=e([l]);function o({slugText:e,justIcon:a,noIcon:s,title:t,outlined:i,extraClasses:o}){return(0,n.jsxs)("div",{className:(0,l.twMerge)("button small-text hover:!bg-transparent",i?" outlined gray bg-white":" ghost light-gray",o),onClick:a=>{navigator.clipboard.writeText(e).then(()=>{alert(`Copied: "${e}"`)})},style:i?void 0:{padding:0},children:[!s&&(0,n.jsx)(r.A,{size:i?15:20}),!a&&(0,n.jsx)("span",{className:"text-slate-500 dark:text-slate-300",children:t||"Copy Slug"})]})}l=(i.then?(await i)():i)[0],t()}catch(e){t(e)}})},55880:(e,a,s)=>{s.a(e,async(e,t)=>{try{s.d(a,{A:()=>f});var n=s(8732),r=s(82015),l=s.n(r),i=s(73872),o=s(87639),d=s(63025),c=s(46169),m=s(16757),h=s(58526),u=s(98136),b=s(71296),p=s(72935),x=s(25088),g=e([i]);function f({database:e,query:a,confirmedDelegetedUser:s,user:t}){let{active_clone:r,active_clone_parent_db:d}=e,c=s?.delegated;s?.priviledges?.match(/Edit Tables/i),s?.priviledges?.match(/Delete Tables/i);let[m,b]=l().useState(null);return(0,n.jsxs)("div",{className:"flex-wrap justify-center gap-4",children:[(0,n.jsxs)("div",{className:"dropdown-wrapper gap-4",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsxs)("div",{className:"w-8 h-8 relative",children:[(0,n.jsx)("img",{src:e.db_image,alt:"Database Image",width:20,className:"w-full h-full rounded-full object-cover"}),s?.delegated&&(0,n.jsxs)("div",{className:" absolute -bottom-2 left-5 gap-1",children:[(0,n.jsx)("img",{src:s.rootUserImage,alt:"Root User Image",className:"w-5 h-5 rounded-full object-cover border-2 border-white dark:border-slate-800 border-solid"}),(0,n.jsx)("span",{className:"text-xs",children:s.rootUserEmail})]})]}),(0,n.jsx)("span",{className:"font-semibold text-base"+(s?.delegated?" -mt-3":""),children:e.db_name})]}),(0,n.jsx)(h.A,{size:20}),(0,n.jsxs)("div",{className:"dropdown p-0",children:[(0,n.jsx)("hr",{className:"m-0"}),(0,n.jsx)("a",{href:`/admin/${t?.id}/databases/${e.db_slug}/edit-database`,className:"button plain-text more-padding normal-weight",children:"Edit Database"}),(0,n.jsx)("hr",{className:"m-0"}),!r&&(0,n.jsxs)(l().Fragment,{children:[(0,n.jsx)("a",{href:`/admin/${t?.id}/databases/add-database?duplicate=${e.db_full_name}`,className:"button plain-text more-padding normal-weight",children:"Duplicate Database"}),(0,n.jsx)("hr",{className:"m-0"})]}),(0,n.jsx)("a",{href:`/admin/${t?.id}/databases/${e.db_slug}/schema`,className:"button plain-text more-padding normal-weight",children:"Schema"}),(0,n.jsx)("hr",{className:"m-0"}),(0,n.jsx)("a",{href:`/admin/${t?.id}/databases/${e.db_slug}/users`,className:"button plain-text more-padding normal-weight",children:"Database Users"}),!c&&(0,n.jsx)(_,{database:e,user:t})]})]}),(0,n.jsx)("hr",{className:"vertical"}),(0,n.jsx)(i.A,{slugText:e.db_slug,title:"Db Slug"}),(0,n.jsx)("div",{className:"-mt-1 gap-1",children:(0,n.jsx)(i.A,{slugText:e.db_full_name,title:"Full DB Name"})}),!c&&(0,n.jsxs)(l().Fragment,{children:[(0,n.jsx)("hr",{className:"vertical"}),(0,n.jsxs)("a",{href:`/admin/${t?.id}/databases/${e.db_slug}/shell`,className:"button ghost small-text",style:{height:"30px",padding:0},children:[(0,n.jsx)(u.A,{size:20}),(0,n.jsx)("span",{className:"text-sm font-semibold",children:"Shell"})]})]}),(0,n.jsx)("hr",{className:"vertical"}),(0,n.jsx)(o.A,{})]})}function _({database:e,user:a}){let[s,t]=l().useState(!1),r=l().useRef();return(0,n.jsxs)(l().Fragment,{children:[s&&(0,n.jsx)(m.A,{width:"20px"}),(0,n.jsx)("hr",{className:"m-0"}),(0,n.jsx)("a",{href:`/admin/${a?.id}/databases/${e.db_slug}/shell`,className:"button plain-text more-padding normal-weight",children:"Shell"}),(0,n.jsx)("hr",{className:"m-0"}),e?.remote_connected==1?(0,n.jsx)(N,{database:e}):(0,n.jsx)("a",{href:`/admin/${a?.id}/databases/${e.db_slug}/connect`,className:"button plain-text more-padding normal-weight",children:"Connect"}),(0,n.jsx)("hr",{className:"m-0"}),(0,n.jsxs)("button",{className:"button plain-text more-padding normal-weight w-full",onClick:a=>{(0,d.A)({url:`/api/exportDatabase?dbName=${e.db_full_name}`,fileName:`${e.db_full_name}.sql`})},children:[(0,n.jsx)(b.A,{size:20}),(0,n.jsx)("span",{children:"Export Database"})]}),(0,n.jsx)("input",{type:"file",name:"upload-update-schema",id:"",ref:r,className:"hidden"}),(0,n.jsxs)("button",{className:"button gray outlined more-padding normal-weight w-full rounded-none -mb-[1px]",onClick:a=>{r.current&&(r.current.addEventListener("change",a=>{let s=a.target,n=s.files?.[0];if(!n){alert("No File Selected");return}var r=new FileReader;r.onload=function(a){var s=a.target?.result;s||alert("Invalid File!");try{let a=s?.toString();if(!a)throw Error("Invalid File!");let n=JSON.parse(a);window.confirm("Are you sure you want to use this schema file for the current database?")&&window.confirm("Remember if any existing table doesn't exist in the new schema file that table and all its content will be erased forever. Continue?")&&(t(!0),(0,c.A)("/api/user-schema/replace-database-schema",{method:"POST",body:{schema:n,dbId:e.id}},!0).then(e=>{e.success&&window.location.reload()}).finally(()=>{t(!1)}))}catch(e){alert("Invalid File. Please enter a valid JSON file")}},r.readAsText(n)}),r.current?.click())},children:[(0,n.jsx)(p.A,{size:20}),(0,n.jsx)("span",{children:"Update From Schema"})]}),(0,n.jsxs)("button",{className:"button gray outlined more-padding normal-weight w-full rounded-none",onClick:a=>{(0,d.A)({url:`/api/downloadDatabaseSchema?dbName=${e.db_full_name}`,fileName:`${e.db_full_name}.json`})},children:[(0,n.jsx)(x.A,{size:20}),(0,n.jsx)("span",{children:"Download Schema"})]})]})}function N({database:e}){return(0,n.jsx)("button",{className:"button plain-text more-padding normal-weight w-full",onClick:a=>{window.confirm("Disconnect this Database from the remote host?")&&(0,c.A)("/api/connect/disconnect",{method:"POST",body:{dbId:e.id}},!0).then(e=>{e.success?window.location.reload():(console.log(e),alert(e.msg||"Remote disconnection failed. Please try again."))})},children:"Disconnect"})}i=(g.then?(await g)():g)[0],t()}catch(e){t(e)}})},63025:(e,a,s)=>{s.d(a,{A:()=>t});function t({url:e,fileName:a,setLoading:s}){s&&s(!0),fetch(e,{method:"GET",headers:{[localStorage.getItem("csrf")||"none"]:"true"}}).then(e=>e.body).then(e=>{let a=e?.getReader();if(a)return new ReadableStream({start:e=>(function s(){return a?.read().then(({done:a,value:t})=>{if(a){e.close();return}return e.enqueue(t),s()})})()})}).then(e=>new Response(e)).then(e=>e.blob()).then(e=>URL.createObjectURL(e)).then(e=>{let t=document.createElement("a");t.href=e,t.download=a,t.style.display="none",document.body.appendChild(t),t.click(),URL.revokeObjectURL(e),document.body.removeChild(t),setTimeout(()=>{s&&s(!1)},1e3)}).catch(e=>{console.log(e),setTimeout(()=>{s&&s(!1)},1e3)})}},71934:(e,a,s)=>{s.d(a,{A:()=>n});var t=s(51779);async function n(...e){let a=(0,t.A)();try{if(!a)throw Error("No Connection provided to DB_HANDLER function!");let s=await a.query(...e);return JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await a?.end()}}},51779:(e,a,s)=>{s.d(a,{A:()=>r});var t=s(9973),n=s.n(t);function r(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}}}; |