PageSourceSearch

https://www.d1v.ai/assets/storage-section-VdJlr4Ui.js

js d1v.ai collected 2026-10-05 15:33:35 UTC 9,026 bytes, 1 lines download raw bytes

1import{j as e}from"./jsx-runtime-BjG_zV1W.js";import{u as L}from"./useQuery-FAAHPYCA.js";import{u as X}from"./QueryClientProvider-DjWDGX5B.js";import{u as Y}from"./useMutation-CvxJyMge.js";import{r as d}from"./index-DeA8mjT8.js";import{B as c}from"./button-BGG7fLGV.js";import{C as P,a as T,b as q,d as Z,c as U}from"./card-BUilLIYJ.js";import{D as E,a as I,b as R,c as K,d as _,e as ee}from"./dialog-DGaV7CJ3.js";import{S as O}from"./skeleton-cbytkmJT.js";import{t as se}from"./toast--axIgTaB.js";import{t as ae}from"./error-toast-C6yWlb1L.js";import{u as te}from"./hooks-gSRFWfA6.js";import{o as ie,i as $,q as re,s as ne,u as M}from"./request-DgUJLOl6.js";import{L as Q}from"./loader-circle-DWpmGfxY.js";import{D as oe}from"./database-2b5QDN6K.js";import{D as le}from"./download-Zm-Vpr9b.js";import{W}from"./wrench-RGTGVrtw.js";import{S as me}from"./search-E_XzArOW.js";import{E as de}from"./eye-DtOBGkz5.js";import{T as ce}from"./trash-2-h64WGwY8.js";import{I as ue}from"./image-gJR8QvxV.js";import{F as xe,a as ge}from"./file-text-1tRSlZ7K.js";import"./mutation-B7vRXR1G.js";import"./vendor-crypto-C45Slrpb.js";import"./index-hJ1Cy72F.js";import"./utils-DVq-zWX3.js";import"./index-UjkdtFUI.js";import"./index-XjpsRpqP.js";import"./index-C9pHAyON.js";import"./Combination-BS63puwr.js";import"./index-CYB6rWUR.js";import"./react-icons.esm-24ueafAT.js";import"./copy-CogiR6mN.js";import"./x-NeCWjQi8.js";import"./circle-alert-DvJ9BebQ.js";import"./components-g2oH73Zm.js";import"./index-CceQDpYs.js";import"./storage-uDu243RH.js";function N(s){const a=Number(s||0);if(!Number.isFinite(a)||a<=0)return"0 B";const n=["B","KB","MB","GB","TB"];let o=0,m=a;for(;m>=1024&&o<n.length-1;)m/=1024,o+=1;return`${m.toFixed(m>=10||o===0?0:1)} ${n[o]}`}function z(s){const a=Number(s||0);return!Number.isFinite(a)||a<=0?"0":new Intl.NumberFormat("en-US",{notation:"compact",maximumFractionDigits:1}).format(a)}function he(s){if(!s)return"-";const a=new Date(s);return Number.isNaN(a.getTime())?s:new Intl.DateTimeFormat(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(a)}function f({title:s,value:a,icon:n}){return e.jsxs("div",{className:"min-w-0 border-l border-border/70 px-4 first:border-l-0 sm:px-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(n,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:s})]}),e.jsx("div",{className:"mt-2 truncate text-xl font-semibold tabular-nums sm:text-2xl",children:a})]})}function fe({name:s,mimeType:a}){var o;const n=((o=s.split(".").pop())==null?void 0:o.toLowerCase())||"";return a!=null&&a.startsWith("image/")||["png","jpg","jpeg","gif","webp","svg"].includes(n)?e.jsx(ue,{className:"h-4 w-4 shrink-0 text-emerald-600 dark:text-emerald-400"}):["js","jsx","ts","tsx","py","go","rs","java","json","html","css"].includes(n)?e.jsx(xe,{className:"h-4 w-4 shrink-0 text-blue-600 dark:text-blue-400"}):e.jsx(ge,{className:"h-4 w-4 shrink-0 text-muted-foreground"})}function ss({project:s}){var C,S,D,k,B;const a=te(),n=X(),[o,m]=d.useState(""),[r,p]=d.useState(null),[u,y]=d.useState(null),[l,x]=d.useState(null),[g,w]=d.useState(!1),{data:i,isLoading:A}=L({queryKey:["project-storage-status",s==null?void 0:s.id],queryFn:async()=>{const t=await ie((s==null?void 0:s.id)||"");return $(t).data},enabled:!!(s!=null&&s.id)}),{data:j}=L({queryKey:["project-storage-files",s==null?void 0:s.id],queryFn:async()=>$(await re((s==null?void 0:s.id)||"")).data.files,enabled:!!(s!=null&&s.id&&(i!=null&&i.enabled)&&(i!=null&&i.provisioned))}),b=Y({mutationFn:async()=>{if(!(s!=null&&s.id))throw new Error("Project is required");return ne(s.id,{storage:!0})},onSuccess:async()=>{se.success(a("project.storage.toast.activated")),await Promise.all([n.invalidateQueries({queryKey:["project",s==null?void 0:s.id]}),n.invalidateQueries({queryKey:["project-storage-status",s==null?void 0:s.id]})])},onError:t=>{ae(t,a("project.storage.toast.activateFailed"))}}),v=d.useMemo(()=>(j||[]).filter(t=>(t.originalName||t.name||"").toLowerCase().includes(o.toLowerCase())),[j,o]);if(A)return e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx(O,{className:"h-28 w-full"}),e.jsx(O,{className:"h-48 w-full"})]});const H=!!(i!=null&&i.enabled&&(i!=null&&i.provisioned)),G=async t=>{var F;if(!((F=t.mimeType)!=null&&F.startsWith("image/")))return;const h=await M.get(`/api/projects/${s==null?void 0:s.id}/integrations/storage-files/${t.id}`,{responseType:"blob"}),V=URL.createObjectURL(h.data);y(V),p(t)},J=async()=>
1{if(l){w(!0);try{await M.delete(`/api/projects/${s==null?void 0:s.id}/integrations/storage-files/${l.id}`),x(null),await n.invalidateQueries({queryKey:["project-storage-files",s==null?void 0:s.id]})}finally{w(!1)}}};return H?e.jsxs("div",{className:"p-4 sm:p-6",children:[e.jsxs(P,{children:[e.jsx(T,{className:"pb-4",children:e.jsx(q,{className:"text-base",children:a("project.storage.usage.cardLabel")})}),e.jsxs(U,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-y-5 sm:grid-cols-4 sm:gap-y-0",children:[e.jsx(f,{title:a("project.storage.usage.stored"),value:N((C=i==null?void 0:i.usage)==null?void 0:C.storedBytes),icon:oe}),e.jsx(f,{title:a("project.storage.download.cardLabel"),value:N((S=i==null?void 0:i.usage)==null?void 0:S.downloadBytes),icon:le}),e.jsx(f,{title:a("project.storage.ops.cardLabel"),value:z((D=i==null?void 0:i.usage)==null?void 0:D.writeOps),icon:W}),e.jsx(f,{title:"Read",value:z((k=i==null?void 0:i.usage)==null?void 0:k.readOps),icon:W})]}),e.jsxs("div",{className:"border-t border-border/70 pt-4 text-sm sm:flex sm:items-center sm:justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:a("project.storage.hero.syncLabel")}),e.jsx("span",{className:"mt-1 block font-medium tabular-nums sm:mt-0",children:he((B=i==null?void 0:i.billing)==null?void 0:B.lastUsageSyncedAt)})]}),e.jsxs("div",{className:"border-t border-border/70 pt-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Files"}),e.jsxs("div",{className:"relative w-44",children:[e.jsx(me,{className:"absolute left-2 top-2.5 h-3.5 w-3.5 text-muted-foreground"}),e.jsx("input",{value:o,onChange:t=>m(t.target.value),placeholder:"Search files",className:"h-8 w-full rounded border bg-background pl-7 pr-2 text-xs"})]})]}),v.length?e.jsx("div",{className:"divide-y divide-border/70",children:v.map(t=>{var h;return e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-4 py-2 text-sm",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2 truncate",children:[e.jsx(fe,{name:t.originalName||t.name||t.id,mimeType:t.mimeType}),e.jsx("span",{className:"truncate",children:t.originalName||t.name||t.id})]}),e.jsx("span",{className:"shrink-0 text-muted-foreground tabular-nums",children:N(t.size)}),e.jsxs("span",{className:"flex shrink-0 gap-1",children:[e.jsx(c,{variant:"ghost",size:"icon",className:"h-7 w-7",disabled:!((h=t.mimeType)!=null&&h.startsWith("image/")),onClick:()=>G(t),children:e.jsx(de,{className:"h-4 w-4"})}),e.jsx(c,{variant:"ghost",size:"icon",className:"h-7 w-7 text-destructive",onClick:()=>x(t),children:e.jsx(ce,{className:"h-4 w-4"})})]})]},t.id)})}):e.jsx("div",{className:"text-sm text-muted-foreground",children:"No files yet."})]})]})]}),e.jsx(E,{open:!!r,onOpenChange:t=>{t||(u&&URL.revokeObjectURL(u),y(null),p(null))},children:e.jsxs(I,{className:"max-h-[90svh] max-w-3xl overflow-auto",children:[e.jsx(R,{children:e.jsx(K,{children:(r==null?void 0:r.originalName)||(r==null?void 0:r.name)})}),u&&e.jsx("img",{src:u,alt:(r==null?void 0:r.originalName)||(r==null?void 0:r.name)||"",className:"mx-auto max-h-[70svh] max-w-full object-contain"})]})}),e.jsx(E,{open:!!l,onOpenChange:t=>!t&&!g&&x(null),children:e.jsxs(I,{children:[e.jsxs(R,{children:[e.jsx(K,{children:a("project.delete.dialog.title")}),e.jsx(_,{children:a("project.delete.dialog.description")})]}),e.jsx("p",{className:"truncate text-sm font-medium",children:(l==null?void 0:l.originalName)||(l==null?void 0:l.name)}),e.jsxs(ee,{children:[e.jsx(c,{variant:"outline",disabled:g,onClick:()=>x(null),children:a("project.common.cancel")}),e.jsxs(c,{variant:"destructive",disabled:g,onClick:J,children:[g?e.jsx(Q,{className:"mr-2 h-4 w-4 animate-spin"}):null,a("project.common.delete")]})]})]})})]}):e.jsx("div",{className:"flex min-h-[400px] items-center justify-center p-6",children:e.jsxs(P,{className:"w-full max-w-xl",children:[e.jsxs(T,{children:[e.jsx(q,{className:"text-xl",children:a("project.storage.enable.title")}),e.jsx(Z,{children:a("project.storage.enable.description")})]}),e.jsx(U,{children:e.jsx(c,{className:"w-full",disabled:!(s!=null&&s.id)||b.isPending,onClick:()=>b.mutate(),children:b.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"mr-2 h-4 w-4 animate-spin"}),a("project.storage.enable.pending")]}):a("project.storage.enable.button")})})]})})}export{ss as StorageSection};

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.