1import{r as e,j as t}from"./vendor-react-D0h46m16.js";import{a as s}from"./legacy-article-redirect-fp3isHR7.js";import{S as r}from"./DonationThankYou-D9g4qmKo.js";import{C as a,b as n,d as i,e as l,a as c}from"./altTextGenerator-DWCIDCE5.js";import{u as o,B as d}from"./button-CykUDgWQ.js";import{z as m,B as h}from"./use-profile-CuRxmWYi.js";import{s as u}from"./use-search-history-Boqjf0_n.js";import{A as x,b as g,c as p,d as j,e as f,f as v,g as N,h as b}from"./alert-dialog-BiNpIDn_.js";import{E as y}from"./EditorialLayout-CetJLmv0.js";import{d as S,aZ as w,a8 as D,am as k,v as L,e as B}from"./vendor-icons-BbYfpdOz.js";import"./vendor-query-Dr68jqlw.js";import"./Footer-C-QL4pp4.js";import"./weatherTime-Y9ihW93L.js";import"./whatsNew--tlXZLzZ.js";import"./index-DqZvI2U2.js";import"./vendor-radix-D7CZeoLk.js";import"./vendor-radix-core-BVUYVtAx.js";import"./vendor-api-B4hs_cPm.js";import"./index.esm-B2IzwMux.js";import"./ScrollToTop-BbnbJAtN.js";import"./exports-cWTammwm.js";import"./sidebar-NOdMlSz1.js";import"./use-campaign-participation-C7Qsjmdf.js";import"./Imprint-_-bc-Cou.js";import"./PageLoader-CuOLERt0.js";import"./use-section-tracking-D1IaNRxi.js";import"./schemaGenerators-CEodAQEs.js";import"./sitemap-index-Cq_Imzq3.js";import"./reactrouterv6-DTS0VFAF.js";import"./helpers-EawpXZ78.js";import"./use-regenerate-feed-DLitAIVb.js";import"./use-articles-admin-CsOMYdKH.js";import"./use-moderation-logs-DVWptnU4.js";import"./StaticPageRoute-BGDHSsAS.js";const z=()=>{const z=s(),{toast:A}=o(),{isAdmin:F,isLoading:E}=m(),[$,M]=e.useState(!1),[T,C]=e.useState(!1),[G,I]=e.useState([]),[K,R]=e.useState(!1),[P,J]=e.useState(0),[O,V]=e.useState(0),[q,U]=e.useState({current:0,total:0,phase:""}),[Z,_]=e.useState(!0);if(!E&&!F)return z("/"),null;const H=async()=>{M(!0),I([]),V(0),J(0),U({current:0,total:0,phase:"Initialisierung..."});try{const e=[];let t=0;const s=1e3;let r=!0;for(U({current:0,total:0,phase:"Lade Dateien aus Storage..."});r;){const{data:a,error:n}=await u.storage.from("article-images").list("",{limit:s,offset:t,sortBy:{column:"name",order:"asc"}});if(n)throw n;a&&a.length>0?(a.forEach(t=>{e.push({name:t.name,size:t.metadata?.size||0,created:new Date(t.created_at||Date.now())})}),t+=a.length,U({current:e.length,total:e.length,phase:`${e.length.toLocaleString()} Dateien geladen...`}),a.length<s&&(r=!1)):r=!1}if(0===e.length)return void A({title:"Keine Dateien gefunden",variant:"destructive"});V(e.length),U({current:e.length,total:e.length,phase:"Analysiere Duplikate..."});const a=new Map;e.forEach(e=>{const t=e.name.match(/^article-(\d+)-/);if(t){const s=t[1],r=a.get(s)??[];r.push(e),a.set(s,r)}});const n=[];let i=0;a.forEach((e,t)=>{if(e.length>1){e.sort((e,t)=>t.created.getTime()-e.created.getTime());const s=e.reduce((e,t)=>e+t.size,0),r=e.slice(1).reduce((e,t)=>e+t.size,0);i+=r,n.push({articleId:t,files:e.map(e=>({name:e.name,created_at:e.created.toISOString(),size:e.size})),totalSize:s,wasteSize:r})}}),n.sort((e,t)=>t.wasteSize-e.wasteSize);const l=n.reduce((e,t)=>e+t.files.length-1,0);I(n),J(i),U({current:0,total:0,phase:""}),A({title:"Analyse abgeschlossen",description:`${n.length.toLocaleString()} Artikel mit ${l.toLocaleString()} Duplikaten gefunden (${Q(i)} Verschwendung)`})}catch(e){console.error("Error analyzing storage:",e),A({title:"Fehler bei der Analyse",variant:"destructive"}),U({current:0,total:0,phase:""})}finally{M(!1)}},Q=e=>{if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return Math.round(e/Math.pow(1024,t)*100)/100+" "+["Bytes","KB","MB","GB"][t]};if(E)return t.jsx(y,{children:t.jsx("div",{className:"flex items-center justify-center py-20",children:t.jsx(S,{className:"h-8 w-8 animate-spin text-primary"})})});const X=G.reduce((e,t)=>e+t.files.length-1,0);return t.jsxs(y,{children:[t.jsx(r,{title:"Storage Bereinigung",description:"Duplikate analysieren und entfernen",canonical:"/redaktion/storage-cleanup",noindex:!0}),t.jsxs("div",{className:"max-w-6xl mx-auto",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-8",children:[t.jsx(w,{className:"h-8 w-8 text-primary"}),t.jsxs("div",{children:[t.jsx("h1",{className:"text-3xl font-bold",children:"Storage Bereinigung"}),t.jsx("p",{className:"text-muted-foreground",children:"Duplikate analysieren und entfernen"})]})]}),t.jsxs(a,{className:"mb-6",children:[t.jsxs(n,{children:[t.jsx(i,{children:"Storage Ãbersicht"}),t.jsx(l,{children:"Vollständige Analyse aller Dateien im article-images Bucket mit Pagination"})]}),t.jsx(c,{children:t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[t.jsxs("div",{className:"p-4 border rounded-lg",children:[t.jsx("div",{className:"text-sm text-muted-foreground mb-1",children:"Gesamt Dateien"}),t.jsx("div",{className:"text-2xl font-bold",children:O.toLocaleStr
1ing()})]}),t.jsxs("div",{className:"p-4 border rounded-lg",children:[t.jsx("div",{className:"text-sm text-muted-foreground mb-1",children:"Artikel mit Duplikaten"}),t.jsx("div",{className:"text-2xl font-bold text-orange-500",children:G.length.toLocaleString()})]}),t.jsxs("div",{className:"p-4 border rounded-lg",children:[t.jsx("div",{className:"text-sm text-muted-foreground mb-1",children:"Verschwendeter Speicher"}),t.jsx("div",{className:"text-2xl font-bold text-destructive",children:Q(P)}),t.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["â ",(P/1024**3).toFixed(2)," GB"]})]}),t.jsxs("div",{className:"p-4 border rounded-lg",children:[t.jsx("div",{className:"text-sm text-muted-foreground mb-1",children:"Zu löschende Dateien"}),t.jsx("div",{className:"text-2xl font-bold text-orange-500",children:X.toLocaleString()})]})]})})]}),q.phase&&t.jsx(a,{className:"mb-6 border-blue-500",children:t.jsx(c,{className:"pt-6",children:t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex justify-between text-sm",children:[t.jsx("span",{className:"font-medium",children:q.phase}),q.total>0&&t.jsxs("span",{className:"text-muted-foreground",children:[q.current.toLocaleString()," / ",q.total.toLocaleString()]})]}),q.total>0&&t.jsx("div",{className:"w-full bg-secondary rounded-full h-2",children:t.jsx("div",{className:"bg-primary h-2 rounded-full transition-all duration-300",style:{width:`${Math.min(100,q.current/q.total*100)}%`}})})]})})}),t.jsx(a,{className:"mb-6",children:t.jsx(c,{className:"pt-6",children:t.jsxs("div",{className:"flex flex-wrap gap-3 items-center",children:[t.jsx(d,{onClick:H,disabled:$||T,children:$?t.jsxs(t.Fragment,{children:[t.jsx(S,{className:"mr-2 h-4 w-4 animate-spin"}),"Analysiere..."]}):t.jsxs(t.Fragment,{children:[t.jsx(D,{className:"mr-2 h-4 w-4"}),"Duplikate analysieren"]})}),G.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-muted rounded-md",children:[t.jsx("input",{type:"checkbox",id:"dryRun",checked:Z,onChange:e=>_(e.target.checked),className:"h-4 w-4 cursor-pointer"}),t.jsx("label",{htmlFor:"dryRun",className:"text-sm cursor-pointer select-none",children:"Dry-Run (nur simulieren)"})]}),t.jsx(d,{variant:Z?"secondary":"destructive",onClick:()=>R(!0),disabled:$||T,children:T?t.jsxs(t.Fragment,{children:[t.jsx(S,{className:"mr-2 h-4 w-4 animate-spin"}),"Bereinige..."]}):t.jsxs(t.Fragment,{children:[t.jsx(k,{className:"mr-2 h-4 w-4"}),Z?"Bereinigung simulieren":"Duplikate löschen"]})})]})]})})}),0===G.length&&!$&&!q.phase&&t.jsx(a,{children:t.jsxs(c,{className:"py-12 text-center",children:[t.jsx(D,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),t.jsx("p",{className:"text-muted-foreground mb-2",children:"Keine Analyse durchgeführt"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:'Klicke auf "Duplikate analysieren" um den Storage zu prüfen'})]})}),G.length>0&&t.jsxs(a,{children:[t.jsxs(n,{children:[t.jsxs(i,{children:["Gefundene Duplikate (",G.length.toLocaleString(),")"]}),t.jsx(l,{children:"Sortiert nach Speicherverschwendung (höchste zuerst)"})]}),t.jsx(c,{children:t.jsxs("div",{className:"max-h-96 overflow-y-auto space-y-3",children:[G.slice(0,100).map(e=>t.jsxs("div",{className:"p-3 border rounded-lg",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("span",{className:"font-medium",children:["Artikel #",e.articleId]}),t.jsxs("div",{className:"flex gap-2",children:[t.jsxs(h,{variant:"outline",children:[e.files.length," Dateien"]}),t.jsxs(h,{variant:"destructive",children:["-",Q(e.wasteSize)]})]})]}),t.jsx("div",{className:"space-y-1 text-xs text-muted-foreground",children:e.files.map((e,s)=>t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("span",{className:0===s?"text-green-600 font-medium":"",children:[0===s?"â ":"â ",e.name]}),t.jsx("span",{children:Q(e.size)})]},e.name))})]},e.articleId)),G.length>100&&t.jsxs("p",{className:"text-center text-muted-foreground py-4",children:["... und ",(G.length-100).toLocaleStr
1ing()," weitere"]})]})})]})]}),t.jsx(x,{open:K,onOpenChange:R,children:t.jsxs(g,{children:[t.jsxs(p,{children:[t.jsxs(j,{className:"flex items-center gap-2",children:[t.jsx(L,{className:"h-5 w-5 text-destructive"}),Z?"Simulation starten?":"Duplikate endgültig löschen?"]}),t.jsx(f,{children:Z?"Dies ist eine Simulation. Keine Dateien werden gelöscht.":t.jsxs(t.Fragment,{children:[t.jsx("strong",{className:"text-destructive",children:"ACHTUNG:"})," Diese Aktion kann nicht rückgängig gemacht werden!",t.jsx("br",{}),t.jsx("br",{}),"Es werden ",t.jsx("strong",{children:X.toLocaleString()})," Dateien gelöscht und ",t.jsx("strong",{children:Q(P)})," Speicher freigegeben."]})})]}),t.jsxs(v,{children:[t.jsx(N,{children:"Abbrechen"}),t.jsxs(b,{onClick:async()=>{if(Z)return A({title:"Dry-Run Modus",description:"Keine Dateien wurden gelöscht (nur Simulation)"}),void R(!1);C(!0),R(!1);try{let e=0,t=0;G.forEach(e=>{t+=e.files.length-1}),U({current:0,total:t,phase:"Lösche Duplikate..."});const s=[];G.forEach(e=>{const t=e.files.slice(1).map(e=>e.name);s.push(...t)});const r=100;let a=0;for(let l=0;l<s.length;l+=r){const n=s.slice(l,l+r),{error:i}=await u.storage.from("article-images").remove(n);i?(console.error(`Failed to delete batch ${Math.floor(l/r)+1}:`,i),A({title:"Fehler",description:`Batch ${Math.floor(l/r)+1} konnte nicht gelöscht werden`,variant:"destructive"})):(e+=n.length,n.forEach(e=>{G.forEach(t=>{const s=t.files.find(t=>t.name===e);s&&(a+=s.size)})}),U({current:e,total:t,phase:`${e.toLocaleString()}/${t.toLocaleString()} Dateien gelöscht...`})),l+r<s.length&&await new Promise(e=>setTimeout(e,100))}const n=Q(a),i=(a/1024**3).toFixed(2);A({title:"Bereinigung erfolgreich!",description:`${e.toLocaleString()} Dateien gelöscht, ${n} (${i} GB) freigegeben`}),U({current:0,total:0,phase:""}),await H()}catch(e){console.error("Error during cleanup:",e),A({title:"Fehler bei der Bereinigung",variant:"destructive"}),U({current:0,total:0,phase:""})}finally{C(!1)}},className:Z?"":"bg-destructive hover:bg-destructive/90",children:[t.jsx(B,{className:"mr-2 h-4 w-4"}),Z?"Simulation starten":"Ja, endgültig löschen"]})]})]})})]})};export{z 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.