dsql-admin/dsql-app/.local_dist/server/chunks/5134.js
Benjamin Toby 7a06e83a46 Updates
2024-12-08 20:56:57 +01:00

1 line
7.2 KiB
JavaScript

"use strict";exports.id=5134,exports.ids=[5134],exports.modules={46437:(e,a,t)=>{t.d(a,{A:()=>n});var s=t(8732);t(82015);var l=t(42178);function n(){return(0,s.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,s.jsx)(l.A,{color:"inherit",className:"opacity-50 text-black",fontSize:"small"})})}},94010:(e,a,t)=>{t.a(e,async(e,s)=>{try{t.d(a,{A:()=>d});var l=t(8732);t(82015);var n=t(96089),i=t(75979),r=e([i]);function d({slugText:e,justIcon:a,noIcon:t,title:s,outlined:r,extraClasses:d}){return(0,l.jsxs)("div",{className:(0,i.twMerge)("button small-text",r?" outlined gray bg-white":" ghost light-gray",d),onClick:a=>{navigator.clipboard.writeText(e).then(()=>{alert(`Copied: "${e}"`)})},style:r?void 0:{padding:0},children:[!t&&(0,l.jsx)(n.A,{size:r?15:20}),!a&&(0,l.jsx)("span",{className:"text-slate-500 dark:text-slate-300",children:s||"Copy Slug"})]})}i=(r.then?(await r)():r)[0],s()}catch(e){s(e)}})},64098:(e,a,t)=>{t.a(e,async(e,s)=>{try{t.d(a,{A:()=>f});var l=t(8732),n=t(82015),i=t.n(n),r=t(94010),d=t(36605),o=t(22603),c=t(48987),m=t(42125),h=t(50993),u=t(63715),x=t(32415),b=t(58526),g=t(98136),p=e([r]);function f({database:e,query:a,confirmedDelegetedUser:t,user:s}){let{active_clone:n,active_clone_parent_db:o}=e,c=t?.delegated;t?.priviledges?.match(/Edit Tables/i),t?.priviledges?.match(/Delete Tables/i);let[m,h]=i().useState(null);return(0,l.jsxs)("div",{className:"flex-wrap justify-center gap-4",children:[(0,l.jsxs)("div",{className:"dropdown-wrapper gap-4",children:[(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsxs)("div",{className:"w-8 h-8 relative",children:[(0,l.jsx)("img",{src:e.db_image,alt:"Database Image",width:20,className:"w-full h-full rounded-full object-cover"}),t?.delegated&&(0,l.jsxs)("div",{className:" absolute -bottom-2 left-5 gap-1",children:[(0,l.jsx)("img",{src:t.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,l.jsx)("span",{className:"text-xs",children:t.rootUserEmail})]})]}),(0,l.jsx)("span",{className:"font-semibold text-base"+(t?.delegated?" -mt-3":""),children:e.db_name})]}),(0,l.jsx)(b.A,{size:20}),(0,l.jsxs)("div",{className:"dropdown p-0",children:[(0,l.jsx)("hr",{className:"m-0"}),(0,l.jsx)("a",{href:`/admin/${s?.id}/databases/${e.db_slug}/edit-database`,className:"button plain-text more-padding normal-weight",children:"Edit Database"}),(0,l.jsx)("hr",{className:"m-0"}),!n&&(0,l.jsxs)(i().Fragment,{children:[(0,l.jsx)("a",{href:`/admin/${s?.id}/databases/add-database?duplicate=${e.db_full_name}`,className:"button plain-text more-padding normal-weight",children:"Duplicate Database"}),(0,l.jsx)("hr",{className:"m-0"})]}),(0,l.jsx)("a",{href:`/admin/${s?.id}/databases/${e.db_slug}/schema`,className:"button plain-text more-padding normal-weight",children:"Schema"}),(0,l.jsx)("hr",{className:"m-0"}),(0,l.jsx)("a",{href:`/admin/${s?.id}/databases/${e.db_slug}/users`,className:"button plain-text more-padding normal-weight",children:"Database Users"}),!c&&(0,l.jsx)(j,{database:e,user:s})]})]}),(0,l.jsx)("hr",{className:"vertical"}),(0,l.jsx)(r.A,{slugText:e.db_slug,title:"Db Slug"}),(0,l.jsx)("div",{className:"-mt-1 gap-1",children:(0,l.jsx)(r.A,{slugText:e.db_full_name,title:"Full DB Name"})}),!c&&(0,l.jsxs)(i().Fragment,{children:[(0,l.jsx)("hr",{className:"vertical"}),(0,l.jsxs)("a",{href:`/admin/${s?.id}/databases/${e.db_slug}/shell`,className:"button ghost small-text",style:{height:"30px",padding:0},children:[(0,l.jsx)(g.A,{size:20}),(0,l.jsx)("span",{className:"text-sm font-semibold",children:"Shell"})]})]}),(0,l.jsx)("hr",{className:"vertical"}),(0,l.jsx)(d.A,{})]})}function j({database:e,user:a}){let[t,s]=i().useState(!1),n=i().useRef();return(0,l.jsxs)(i().Fragment,{children:[t&&(0,l.jsx)(x.A,{width:"20px"}),(0,l.jsx)("hr",{className:"m-0"}),(0,l.jsx)("a",{href:`/admin/${a?.id}/databases/${e.db_slug}/shell`,className:"button plain-text more-padding normal-weight",children:"Shell"}),(0,l.jsx)("hr",{className:"m-0"}),e?.remote_connected==1?(0,l.jsx)(w,{database:e}):(0,l.jsx)("a",{href:`/admin/${a?.id}/databases/${e.db_slug}/connect`,className:"button plain-text more-padding normal-weight",children:"Connect"}),(0,l.jsx)("hr",{className:"m-0"}),(0,l.jsxs)("button",{className:"button plain-text more-padding normal-weight w-full",onClick:a=>{(0,o.A)({url:`/api/exportDatabase?dbName=${e.db_full_name}`,fileName:`${e.db_full_name}.sql`})},children:[(0,l.jsx)(c.A,{fontSize:"small",color:"action",className:"opacity-50"}),(0,l.jsx)("span",{children:"Export Database"})]}),(0,l.jsx)("input",{type:"file",name:"upload-update-schema",id:"",ref:n,className:"hidden"}),(0,l.jsxs)("button",{className:"button green outlined more-padding normal-weight w-full rounded-none -mb-[1px]",onClick:a=>{n.current&&(n.current.addEventListener("change",a=>{let t=a.target,l=t.files?.[0];if(!l){alert("No File Selected");return}var n=new FileReader;n.onload=function(a){var t=a.target?.result;t||alert("Invalid File!");try{let a=t?.toString();if(!a)throw Error("Invalid File!");let l=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?")&&(s(!0),(0,u.A)("/api/user-schema/replace-database-schema",{method:"POST",body:{schema:l,dbId:e.id}},!0).then(e=>{e.success&&window.location.reload()}).finally(()=>{s(!1)}))}catch(e){alert("Invalid File. Please enter a valid JSON file")}},n.readAsText(l)}),n.current?.click())},children:[(0,l.jsx)(h.A,{fontSize:"small",color:"action",className:"opacity-50 text-inherit"}),(0,l.jsx)("span",{children:"Update From Schema"})]}),(0,l.jsxs)("button",{className:"button secondary outlined more-padding normal-weight w-full rounded-none",onClick:a=>{(0,o.A)({url:`/api/downloadDatabaseSchema?dbName=${e.db_full_name}`,fileName:`${e.db_full_name}.json`})},children:[(0,l.jsx)(m.A,{fontSize:"small",color:"action",className:"opacity-50 text-inherit"}),(0,l.jsx)("span",{children:"Download Schema"})]})]})}function w({database:e}){return(0,l.jsx)("button",{className:"button plain-text more-padding normal-weight w-full",onClick:a=>{window.confirm("Disconnect this Database from the remote host?")&&(0,u.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"})}r=(p.then?(await p)():p)[0],s()}catch(e){s(e)}})},22603:(e,a,t)=>{t.d(a,{A:()=>s});function s({url:e,fileName:a,setLoading:t}){t&&t(!0),fetch(e,{method:"GET",headers:{"x-csrf-auth":localStorage.getItem("csrf")}}).then(e=>e.body).then(e=>{let a=e?.getReader();if(a)return new ReadableStream({start:e=>(function t(){return a?.read().then(({done:a,value:s})=>{if(a){e.close();return}return e.enqueue(s),t()})})()})}).then(e=>new Response(e)).then(e=>e.blob()).then(e=>URL.createObjectURL(e)).then(e=>{let s=document.createElement("a");s.href=e,s.download=a,s.style.display="none",document.body.appendChild(s),s.click(),URL.revokeObjectURL(e),document.body.removeChild(s),setTimeout(()=>{t&&t(!1)},1e3)}).catch(e=>{console.log(e),setTimeout(()=>{t&&t(!1)},1e3)})}}};