1 line
8.4 KiB
JavaScript
1 line
8.4 KiB
JavaScript
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[675],{5844:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(4848),n=t(7216);function s(){return(0,l.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,l.jsx)(n.A,{})})}t(6540)},3647:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(4848),n=t(6540);function s(e){let{confirmedDelegetedUser:a,linksArray:t,user:s}=e,[i,d]=n.useState(t||null);return(n.useEffect(()=>{var e;if(t)return;let a=window.location.pathname,l=a.split("/"),n=[];n.push({title:"Home",path:a.match(/admin/)?"/admin":"/"}),null===(e=window.location.search)||void 0===e||e.match(/delegated=true/),l.forEach((e,a,t)=>{!(null==e?void 0:e.match(/./))||1==a||e.match(/^\d+$/)&&s&&!n.find(e=>!!e.title.match(/^entries$|^users$/))||n.push({title:e,path:(()=>{let e="";for(let l=0;l<t.length;l++){let n=t[l];!(l>a)&&n.match(/./)&&(e+="/".concat(n))}return e})()})}),d(n)},[]),i&&i[1])?(0,l.jsx)("div",{className:"text-sm mt-2 flex-wrap",children:i.map((e,a,t)=>a===i.length-1?(0,l.jsx)("a",{href:e.path,className:"text-slate-400 dark:text-slate-500 pointer-events-none",children:e.title},a):(0,l.jsxs)(n.Fragment,{children:[(0,l.jsx)("a",{href:e.path,className:"query-url",children:e.title}),(0,l.jsx)("span",{className:"opacity-20",children:"|"})]},a))}):(0,l.jsx)(n.Fragment,{})}},5139:(e,a,t)=>{t.d(a,{A:()=>i});var l=t(4848);t(6540);var n=t(7220),s=t(856);function i(e){let{slugText:a,justIcon:t,noIcon:i,title:d,outlined:r,extraClasses:o}=e;return(0,l.jsxs)("div",{className:(0,s.QP)("button small-text hover:!bg-transparent",r?" outlined gray bg-white":" ghost light-gray",o),onClick:e=>{navigator.clipboard.writeText(a).then(()=>{alert('Copied: "'.concat(a,'"'))})},style:r?void 0:{padding:0},children:[!i&&(0,l.jsx)(n.A,{size:r?15:20}),!t&&(0,l.jsx)("span",{className:"text-slate-500 dark:text-slate-300",children:d||"Copy Slug"})]})}},1990:(e,a,t)=>{t.d(a,{A:()=>b});var l=t(4848),n=t(6540),s=t(5139),i=t(4839),d=t(5974),r=t(9020),o=t(1710),c=t(2027),m=t(6051),h=t(3419),u=t(4266),x=t(7290);function b(e){var a,t;let{database:d,query:r,confirmedDelegetedUser:o,user:h}=e,{active_clone:u,active_clone_parent_db:x}=d,b=null==o?void 0:o.delegated;null==o||null===(a=o.priviledges)||void 0===a||a.match(/Edit Tables/i),null==o||null===(t=o.priviledges)||void 0===t||t.match(/Delete Tables/i);let[g,f]=n.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:d.db_image,alt:"Database Image",width:20,className:"w-full h-full rounded-full object-cover"}),(null==o?void 0:o.delegated)&&(0,l.jsxs)("div",{className:" absolute -bottom-2 left-5 gap-1",children:[(0,l.jsx)("img",{src:o.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:o.rootUserEmail})]})]}),(0,l.jsx)("span",{className:"font-semibold text-base"+((null==o?void 0:o.delegated)?" -mt-3":""),children:d.db_name})]}),(0,l.jsx)(c.A,{size:17}),(0,l.jsxs)("div",{className:"dropdown p-0",children:[(0,l.jsx)("hr",{className:"m-0"}),(0,l.jsx)("a",{href:"/admin/".concat(null==h?void 0:h.id,"/databases/").concat(d.db_slug,"/edit-database"),className:"button plain-text more-padding normal-weight",children:"Edit Database"}),(0,l.jsx)("hr",{className:"m-0"}),!u&&(0,l.jsxs)(n.Fragment,{children:[(0,l.jsx)("a",{href:"/admin/".concat(null==h?void 0:h.id,"/databases/add-database?duplicate=").concat(d.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/".concat(null==h?void 0:h.id,"/databases/").concat(d.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/".concat(null==h?void 0:h.id,"/databases/").concat(d.db_slug,"/users"),className:"button plain-text more-padding normal-weight",children:"Database Users"}),!b&&(0,l.jsx)(p,{database:d,user:h})]})]}),(0,l.jsx)("hr",{className:"vertical"}),(0,l.jsx)(s.A,{slugText:d.db_slug,title:"Db Slug"}),(0,l.jsx)("div",{className:"-mt-1 gap-1",children:(0,l.jsx)(s.A,{slugText:d.db_full_name,title:"Full DB Name"})}),!b&&(0,l.jsxs)(n.Fragment,{children:[(0,l.jsx)("hr",{className:"vertical"}),(0,l.jsxs)("a",{href:"/admin/".concat(null==h?void 0:h.id,"/databases/").concat(d.db_slug,"/shell"),className:"button ghost small-text",style:{height:"30px",padding:0},children:[(0,l.jsx)(m.A,{size:17}),(0,l.jsx)("span",{className:"text-sm font-semibold",children:"Shell"})]})]}),(0,l.jsx)("hr",{className:"vertical"}),(0,l.jsx)(i.A,{})]})}function p(e){let{database:a,user:t}=e,[s,i]=n.useState(!1),c=n.useRef();return(0,l.jsxs)(n.Fragment,{children:[s&&(0,l.jsx)(o.A,{width:"20px"}),(0,l.jsx)("hr",{className:"m-0"}),(0,l.jsx)("a",{href:"/admin/".concat(null==t?void 0:t.id,"/databases/").concat(a.db_slug,"/shell"),className:"button plain-text more-padding normal-weight",children:"Shell"}),(0,l.jsx)("hr",{className:"m-0"}),(null==a?void 0:a.remote_connected)==1?(0,l.jsx)(g,{database:a}):(0,l.jsx)("a",{href:"/admin/".concat(null==t?void 0:t.id,"/databases/").concat(a.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:e=>{window.confirm("Export ".concat(a.db_name,"?"))&&(0,d.A)({url:"/api/admin/databases/".concat(a.id,"/export"),fileName:"".concat(a.db_full_name,".zip")})},children:[(0,l.jsx)(h.A,{size:17}),(0,l.jsx)("span",{children:"Export Database"})]}),(0,l.jsx)("input",{type:"file",name:"upload-update-schema",id:"",ref:c,className:"hidden"}),(0,l.jsxs)("button",{className:"button gray outlined more-padding normal-weight w-full rounded-none -mb-[1px]",onClick:e=>{var t;c.current&&(c.current.addEventListener("change",e=>{let t=null===(l=e.target.files)||void 0===l?void 0:l[0];if(!t){alert("No File Selected");return}var l,n=new FileReader;n.onload=function(e){var t,l=null===(t=e.target)||void 0===t?void 0:t.result;l||alert("Invalid File!");try{let e=null==l?void 0:l.toString();if(!e)throw Error("Invalid File!");let t=JSON.parse(e);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?")&&(i(!0),(0,r.A)("/api/user-schema/replace-database-schema",{method:"POST",body:{schema:t,dbId:a.id}},!0).then(e=>{e.success&&window.location.reload()}).finally(()=>{i(!1)}))}catch(e){alert("Invalid File. Please enter a valid JSON file")}},n.readAsText(t)}),null===(t=c.current)||void 0===t||t.click())},children:[(0,l.jsx)(u.A,{size:17}),(0,l.jsx)("span",{children:"Update From Schema"})]}),(0,l.jsxs)("button",{className:"button gray outlined more-padding normal-weight w-full rounded-none",onClick:e=>{(0,d.A)({url:"/api/downloadDatabaseSchema?dbName=".concat(a.db_full_name),fileName:"".concat(a.db_full_name,".json")})},children:[(0,l.jsx)(x.A,{size:17}),(0,l.jsx)("span",{children:"Download Schema"})]})]})}function g(e){let{database:a}=e;return(0,l.jsx)("button",{className:"button plain-text more-padding normal-weight w-full",onClick:e=>{window.confirm("Disconnect this Database from the remote host?")&&(0,r.A)("/api/connect/disconnect",{method:"POST",body:{dbId:a.id}},!0).then(e=>{e.success?window.location.reload():alert(e.msg||"Remote disconnection failed. Please try again.")})},children:"Disconnect"})}},5974:(e,a,t)=>{t.d(a,{A:()=>n});var l=t(1212);function n(e){let{url:a,fileName:t,setLoading:n}=e;n&&n(!0),fetch(a,{method:"GET",headers:{"x-csrf-key":localStorage.getItem(l.B.CSRF)||"none"}}).then(e=>e.body).then(e=>{let a=null==e?void 0:e.getReader();if(a)return new ReadableStream({start:e=>(function t(){return null==a?void 0:a.read().then(a=>{let{done:l,value:n}=a;if(l){e.close();return}return e.enqueue(n),t()})})()})}).then(e=>new Response(e)).then(e=>e.blob()).then(e=>URL.createObjectURL(e)).then(e=>{let a=document.createElement("a");a.href=e,a.download=t,a.style.display="none",document.body.appendChild(a),a.click(),URL.revokeObjectURL(e),document.body.removeChild(a),setTimeout(()=>{n&&n(!1)},1e3)}).catch(e=>{console.log(e),setTimeout(()=>{n&&n(!1)},1e3)})}}}]); |