1import{e as ae,b as te,j as e,M as W,i as ne,p as re,a as I,r as B,bD as N,$ as oe,bu as le}from"./index.C_jEAofg.js";import{A as ie}from"./AccessDenied.Da_IVTEt.js";import{d as ce,r}from"./reactRouter.C6cvQAHO.js";import{E as de}from"./EditIcon.C3zEPxhx.js";import{R as ue}from"./RefreshIcon.C6h3Vb3d.js";import{t as T,g as me}from"./rateLimitError.ByypYhRt.js";import{S as pe}from"./ScrollButton.BuRsjz3s.js";import{u as _,i as fe}from"./i18n.BxWiIRpk.js";import"./recharts.DzmhKP_O.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};a.SENTRY_RELEASE={id:"aec9389561908f1f1b5366362ca3b629220ab900"},a._sentryModuleMetadata=a._sentryModuleMetadata||{},a._sentryModuleMetadata[new a.Error().stack]=function(x){for(var d=1;d<arguments.length;d++){var o=arguments[d];if(o!=null)for(var j in o)o.hasOwnProperty(j)&&(x[j]=o[j])}return x}({},a._sentryModuleMetadata[new a.Error().stack],{"_sentryBundlerPluginAppKey:tuf-website":!0});var h=new a.Error().stack;h&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[h]="d7d42dcd-b208-4d8c-9852-0ed5a11eb196",a._sentryDebugIdIdentifier="sentry-dbid-d7d42dcd-b208-4d8c-9852-0ed5a11eb196")}catch{}})();const q=500*1024*1024,he=({onUploadComplete:a,storedPassword:h,isLoadingBackups:x})=>{const{t:d}=_(["pages","common"]),[o,j]=r.useState(!1),[u,f]=r.useState(0),[g,b]=r.useState(""),[v,F]=r.useState(!1),[y,C]=r.useState(null),k=s=>s?s.size>q?(b(d("backup.upload.errors.fileTooBig",{size:A(q)})),!1):(b(""),!0):!1,$=async s=>{var n,m;if(s)try{F(!0),C(s.name),b("");const i=new FormData;i.append("backup",s),(await I.post(`${B.admin.backup.root()}/upload`,i,{headers:{"Content-Type":"multipart/form-data","X-Super-Admin-Password":h},onUploadProgress:w=>{const S=Math.round(w.loaded*100/w.total);f(S)}})).data.success&&(N.success(d("backup.notifications.uploadSuccess")),a(),C(null),f(0))}catch(i){if(console.error("Upload failed:",i),T(i)){b(me(i));return}b(((n=i.response)==null?void 0:n.status)===403?d("backup.passwordModal.errors.invalid"):d("backup.notifications.uploadFailed")),N.error(((m=i.response)==null?void 0:m.status)===403?d("backup.passwordModal.errors.invalid"):d("backup.notifications.uploadFailed")),f(0)}finally{F(!1)}},E=s=>{s.preventDefault(),s.stopPropagation()},D=s=>{s.preventDefault(),s.stopPropagation(),j(!0)},t=s=>{s.preventDefault(),s.stopPropagation(),!s.currentTarget.contains(s.relatedTarget)&&j(!1)},M=s=>{var m,i;s.preventDefault(),s.stopPropagation(),j(!1);const n=(i=(m=s.dataTransfer)==null?void 0:m.files)==null?void 0:i[0];n&&k(n)&&$(n)},L=s=>{var m;const n=(m=s.target.files)==null?void 0:m[0];n&&k(n)&&$(n),s.target.value=""};return e.jsxs("div",{className:`upload-zone ${o?"drag-over":""} ${v?"uploading":""} ${y?"has-file":""}`,onDragOver:E,onDragEnter:D,onDragLeave:t,onDrop:M,children:[e.jsx("div",{className:"icon",children:o?"ð¥":"ð¤"}),y&&v?e.jsx("p",{className:"upload-filename",children:y}):e.jsx("p",{children:d("backup.upload.dragDropMessage")}),e.jsx("input",{type:"file",onChange:L,accept:".sql",disabled:v}),v&&e.jsx("div",{className:"upload-progress",style:{width:`${u}%`}}),g&&e.jsx("p",{className:"upload-error",children:g})]})},be=({date:a})=>{const[h,x]=r.useState(""),{t:d}=_(["pages","common"]);return r.useEffect(()=>{const o=()=>{const u=Math.floor((new Date-new Date(a))/1e3);let f=u,g="second";u>=31536e3?(f=Math.floor(u/31536e3),g="year"):u>=2592e3?(f=Math.floor(u/2592e3),g="month"):u>=86400?(f=Math.floor(u/86400),g="day"):u>=3600?(f=Math.floor(u/3600),g="hour"):u>=60&&(f=Math.floor(u/60),g="minute");const b=`${g}${f!==1?"s":""}`;x(d("backup.timeAgo."+b,{count:f}))};o();const j=setInterval(o,6e4);return()=>clearInterval(j)},[a]),e.jsx("span",{className:"time-ago",children:h})},ge=({backups:a,isLoadingBackups:h,showConfirmation:x,storedPassword:d})=>{const{t:o}=_(["pages","common"]),[j,u]=r.useState(null),[f,g]=r.useState(""),[b,v]=r.useState(!1),[F,y]=r.useState({}),[C,k]=r.useState({}),[$,E]=r.useState({}),D=s=>{const n=s.lastIndexOf(".");return n===-1?[s,""]:[s.slice(0,n),s.slice(n)]},t=async s=>{if(f.trim())try{v(!0),(await I.post(`${B.admin.backup.root()}/rename/${s.filename}`,{newName:f+D(s.filename)[1]},{headers:{"X-Super-Admin-Password":d}})).data.success&&(N.success(o("backup.notifications.renameSuccess")),u(null),g(""))}catch(n){console.error("Failed to rename backup:",n),T(n)||N.error(o("backup.notifications.renameFailed"))}finally{v(!1)}},M=(s,n)=>{s==="restore"?x("restore","restore",{filename:n.filename}):s==="delete"?x("delete","delete",{filename:n.filename}):s==="download"?L(n):s==="rename"&&t(n)},L=async s=>{if(!$[s.filename])try{E(c=>({...c,[s.filename]:!0})),y(c=>({...c,[s.filename]:0})),k(c=>({...c,[s.filename]:!0}));const n=await I.get(`${B.admin.backup.root()}/download/${s.filename}`,{headers:{"X-Super-Admin-Password":d},responseType:"blob",onDownloadProgress:c=>{const w=c.total;if(w!=null&&w>0){const S=Math.min(100,Math.round(c.loaded*100/w));y(P=>({...P,[s.filename]:S})),k(P=>({...P,[s.filename]:!1}))}}}),m=window.URL.createObjectURL(new Blob([n.data])),i=document.createElement("a");i.href=m,i.setAttribute("download",s.filename),document.body.appendChild(i),i.click(),i.parentNode.removeChild(i),window.URL.revokeObjectURL(m),y(c=>({...c,[s.filename]:100})),k(c=>({...c,[s.filename]:!1})),setTimeout(()=>{y(c=>({...c,[s.filename]:0})),k(c=>({...c,[s.filename]:!1})),E(c=>({...c,[s.filename]:!1}))},400)}catch(n){console.error("Failed to download backup:",n),N.error(o("backup.notifications.downloadFailed")),E(m=>({...m,[s.filename]:!1})),y(m=>({...m,[s.filename]:0})),k(m=>({...m,[s.filename]:!1}))}};return!a||a.length===0?e.jsxs("div",{className:"no-backups-message",children:[e.jsx("h2",{children:o("backup.noBackups.title")}),e.jsx("p",{children:o("backup.noBackups.message")})]}):e.jsx("div",{className:"backup-section",children:e.jsx("div",{className:"backup-list",children:a.map(s=>{var U;const[n,m]=D(s.filename),i=F[s.filename]??0,c=C[s.filename],w=$[s.filename],S=2*Math.PI*10,P=S-i/100*S;return e.jsxs("div",{className:"backup-item",children:[e.jsxs("div",{className:"download-wrapper",children:[e.jsx("div",{className:`download-progress ${w?"visible":""}`,children:e.jsxs("svg",{className:"progress-circle",width:"24",height:"24",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"progress-background",cx:"12",cy:"12",r:"10"}),e.jsx("circle",{className:`progress-bar ${c&&w?"indeterminate":""}`,cx:"12",cy:"12",r:"10",strokeDasharray:S,strokeDashoffset:c&&w?0:P})]})}),e.jsx("button",{className:`download-btn ${w?"downloading":""}`,onClick:()=>M("download",s),disabled:h||b||w,children:e.jsx("svg",{className:"svg-stroke",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M17 17H17.01M17.4 14H18C18.9319 14 19.3978 14 19.7654 14.1522C20.2554 14.3552 20.6448 14.7446 20.8478 15.2346C21 15.6022 21 16.0681 21 17C21 17.9319 21 18.3978 20.8478 18.7654C20.6448 19.2554 20.2554 19.6448 19.7654 19.8478C19.3978 20 18.9319 20 18 20H6C5.06812 20 4.60218 20 4.23463 19.8478C3.74458 19.6448 3.35523 19.2554 3.15224 18.7654C3 18.3978 3 17.9319 3 17C3 16.0681 3 15.6022 3.15224 15.2346C3.35523 14.7446 3.74458 14.3552 4.23463 14.1522C4.60218 14 5.06812 14 6 14H6.
16M12 15V4M12 15L9 12M12 15L15 12",fill:"none",stroke:"#ffffff",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e.jsx("div",{className:"backup-info",children:j===s.filename?e.jsxs("div",{className:"rename-controls",children:[e.jsxs("div",{className:"rename-input-container",children:[e.jsx("input",{type:"text",value:f,onChange:O=>g(O.target.value),placeholder:o("backup.fileInfo.newName"),className:"rename-input"}),e.jsx("span",{className:"file-extension",children:m})]}),e.jsxs("div",{className:"rename-buttons",children:[e.jsx("button",{className:"save-rename-btn",onClick:()=>M("rename",s),disabled:b||!f.trim(),children:b?o("loading.saving",{ns:"common"}):o("buttons.save",{ns:"common"})}),e.jsx("button",{className:"cancel-rename-btn",onClick:()=>{u(null),g("")},disabled:b,children:o("buttons.cancel",{ns:"common"})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"filename-container",children:[e.jsx("h3",{children:s.filename}),e.jsx("button",{className:"edit-btn",onClick:()=>{u(s.filename),g(n)},disabled:h||b,children:e.jsx(de,{color:"#fffa",size:"24px"})})]}),e.jsxs("div",{className:"backup-details",children:[e.jsxs("p",{className:"backup-date",children:[o("backup.fileInfo.created",{date:oe(s.created,(U=fe)==null?void 0:U.language)}),e.jsx(be,{date:s.created})]}),e.jsx("p",{className:"backup-size",children:o("backup.fileInfo.size",{size:A(s.size)})})]})]})}),e.jsxs("div",{className:"backup-actions",children:[e.jsx("button",{className:"restore-btn",onClick:()=>M("restore",s),disabled:h||b,children:o("backup.buttons.restore")}),e.jsx("button",{className:"delete-btn",onClick:()=>M("delete",s),disabled:h||b,children:o("buttons.delete",{ns:"common"})})]})]},s.filename)})})})},A=a=>{if(a===0)return"0 B";const h=1024,x=["B","KB","MB","GB"],d=Math.floor(Math.log(a)/Math.log(h));return`${parseFloat((a/Math.pow(h,d)).toFixed(2))} ${x[d]}`},Ce=()=>{const{t:a}=_(["pages","common"]),{user:h}=ae(),x=ce(),d=r.useMemo(()=>te({title:a("backup.meta.title"),description:a("backup.meta.description"),pathname:x.pathname,image:"/og-image.jpg",noindex:!0}),[a,x.pathname]),[o,j]=r.useState([]),[u,f]=r.useState("newest"),[g,b]=r.useState(!0),[v,F]=r.useState(""),[y,C]=r.useState(""),[k,$]=r.useState(""),[E,D]=r.useState(!1),[t,M]=r.useState(null),[L,s]=r.useState(!1),[n,m]=r.useState(!1),[i,c]=r.useState(!1),[w,S]=r.useState(!1),[P,U]=r.useState(!1),O=async l=>{try{return s(!0),await I.head(`${le}${B.admin.verifyPassword()}?origin=backup`,{headers:{"X-Super-Admin-Password":l}}),!0}catch(p){return T(p),!1}finally{s(!1)}},K=async()=>{try{await O(v)?($(v),b(!1),F(""),C(""),await z()):C(a("backup.passwordModal.errors.invalid"))}catch(l){T(l)||C(a("backup.passwordModal.errors.generic"))}},Z=async()=>{if(!t)return;const{type:l,action:p,params:R}=t;try{l==="create"?await G(R):l==="delete"?await Y(R.filename):l==="restore"&&await J(R.filename)}finally{D(!1),M(null)}},X=(l,p,R)=>{M({type:l,action:p,params:R}),D(!0)},G=async()=>{try{c(!0),(await I.post(`${B.admin.backup.root()}/create`,{},{headers:{"X-Super-Admin-Password":k}})).data.success&&(N.success(a("backup.notifications.backupCreated")),await z())}catch(l){console.error("Failed to create backup:",l),T(l)||N.error(a("backup.notifications.createFailed"))}finally{c(!1)}},Y=async l=>{try{S(!0),(await I.delete(`${B.admin.backup.root()}/delete/${l}`,{headers:{"X-Super-Admin-Password":k}})).data.success&&(N.success(a("backup.notifications.backupDeleted")),await z())}catch(p){console.error("Failed to delete backup:",p),T(p)||N.error(a("backup.notifications.deleteFailed"))}finally{S(!1)}},J=async l=>{try{U(!0),(await I.post(`${B.admin.backup.root()}/restore/${l}`,{},{headers:{"X-Super-Admin-Password":k}})).data.success&&N.success(a("backup.notifications.backupRestored"))}catch(p){console.error("Failed to restore backup:",p),T(p)||N.error(a("backup.notifications.restoreFailed"))}finally{U(!1)}},z=async()=>{var l;try{m(!0);const p=await I.get(`${B.admin.backup.root()}/list`);j(((l=p==null?void 0:p.data)==null?void 0:l.mysql)||[])}catch(p){console.error("Failed to load backups:",p),N.error(a("backup.notifications.loadFailed"))}finally{m(!1)}};r.useEffect(()=>{z()},[]);const Q=()=>{X("create","create",{})},ee=r.useMemo(()=>[...o].sort((p,R)=>{const V=new Date(p.created).getTime(),H=new Date(R.created).getTime();return u==="newest"?H-V:V-H}),[o,u]),se=r.useMemo(()=>o.reduce((l,p)=>l+p.size,0),[o]);return h.permissionFlags===void 0?e.jsxs("div",{className:"admin-backup-page",children:[e.jsx(W,{...d}),e.jsx("div",{className:"admin-backup-body page-content",children:e.jsx("div",{className:"loader-shell loader-shell--tall",children:e.jsx("div",{className:"loader loader-relative"})})})]}):ne(h,re.SUPER_ADMIN)?e.jsxs("div",{className:"admin-backup-page",children:[e.jsx(W,{...d}),e.jsxs("div",{className:"admin-backup-body page-content",children:[e.jsxs("div",{className:"header-container",children:[e.jsx("div",{className:"total-size",children:a("backup.stats.totalSize",{size:A(se)})}),e.jsx("h1",{children:a("backup.header.title")}),e.jsx("button",{className:"refresh-button",onClick:z,disabled:n,"aria-label":a("backup.header.refresh"),children:e.jsx(ue,{color:"#fff",size:"36px"})})]}),e.jsxs("div",{className:"backup-header",children:[e.jsx("div",{className:"header-left",children:e.jsxs("div",{className:"sort-buttons",children:[e.jsx("button",{className:`s
1ort-btn ${u==="newest"?"active":""}`,onClick:()=>f("newest"),children:a("backup.sort.newest")}),e.jsx("button",{className:`sort-btn ${u==="oldest"?"active":""}`,onClick:()=>f("oldest"),children:a("backup.sort.oldest")})]})}),e.jsx("div",{className:"header-right",children:e.jsx("button",{className:"create-backup-btn",onClick:Q,disabled:i,children:i?a("loading.creating",{ns:"common"}):a("backup.buttons.create")})})]}),e.jsx(he,{onUploadComplete:z,storedPassword:k,isLoadingBackups:n}),e.jsx(ge,{backups:ee,isLoadingBackups:n,showConfirmation:X,storedPassword:k})]}),e.jsx(pe,{}),g&&e.jsx("div",{className:"password-modal",children:e.jsxs("div",{className:"password-modal-content",children:[e.jsx("h3",{children:a("backup.passwordModal.title")}),e.jsx("p",{children:a("backup.passwordModal.initialMessage")}),e.jsx("input",{type:"password",autoComplete:"section-password-super-admin",value:v,onChange:l=>F(l.target.value),placeholder:a("backup.passwordModal.placeholder")}),y&&e.jsx("p",{className:"error-message",children:y}),e.jsx("div",{className:"password-modal-actions",children:e.jsx("button",{className:"confirm-btn btn-fill-primary",onClick:K,style:{pointerEvents:!v||L?"none":"auto"},disabled:!v||L,children:L?a("backup.buttons.verifying"):a("buttons.confirm",{ns:"common"})})})]})}),E&&e.jsx("div",{className:"password-modal",children:e.jsxs("div",{className:"password-modal-content",children:[e.jsx("h3",{children:a("backup.confirmation.title")}),e.jsxs("p",{children:[(t==null?void 0:t.type)==="create"&&a("backup.confirmation.createMessage"),(t==null?void 0:t.type)==="delete"&&a("backup.confirmation.deleteMessage"),(t==null?void 0:t.type)==="restore"&&a("backup.confirmation.restoreMessage")]}),e.jsxs("div",{className:"password-modal-actions",children:[e.jsx("button",{className:"confirm-btn btn-fill-primary",onClick:Z,disabled:(t==null?void 0:t.type)==="create"&&i||(t==null?void 0:t.type)==="delete"&&w||(t==null?void 0:t.type)==="restore"&&P,children:a("buttons.confirm",{ns:"common"})}),e.jsx("button",{className:"cancel-btn btn-fill-neutral-dark",onClick:()=>{D(!1),M(null)},disabled:(t==null?void 0:t.type)==="create"&&i||(t==null?void 0:t.type)==="delete"&&w||(t==null?void 0:t.type)==="restore"&&P,children:a("buttons.cancel",{ns:"common"})})]})]})})]}):e.jsx(ie,{metaTitle:a("backup.meta.title"),metaDescription:a("backup.meta.description")})};export{Ce as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.