PageSourceSearch

https://dgf-de.lovable.app/assets/AdminStorageMigration-BElsGGGl.js

js dgf-de.lovable.app collected 2026-10-03 03:26:57 UTC 7,509 bytes, 1 lines download raw bytes

1import{j as e}from"./ui-B-jAfBIu.js";import{e as $,r as u}from"./vendor-DFDkvaNg.js";import{s as o,a6 as i,B as h,W as C,a3 as F,X as Z}from"./index-BCsAUAr3.js";import{C as x,a as g,b as p,d as D,c as f}from"./card-FDTNR4GW.js";import{P as B}from"./progress-DaSDJPFo.js";import{A as G}from"./arrow-left-AER8uK4l.js";import{C as I}from"./circle-alert-D0uUIXsZ.js";import{U as _}from"./upload-CLVy7zpO.js";import"./supabase-DM3UDwCf.js";import"./query-BNFXhbss.js";const L=["/test-documents/2026_DGF_Vorstellungspräsentation.pdf","/test-documents/DGF_GmbH_Vorlage.dotx","/test-documents/Fördermittel_QuickCheck.docx"];function Y(){const l=$(),[c,b]=u.useState(!1),[a,N]=u.useState([]),[w,d]=u.useState(0);u.useEffect(()=>{S(),M()},[]);const S=async()=>{try{const{data:{session:s}}=await o.auth.getSession();if(!s){l("/auth");return}const{data:t}=await o.from("user_roles").select("role").eq("user_id",s.user.id);if(!(t==null?void 0:t.some(r=>r.role==="admin"))){i.error("Nur Admins haben Zugriff"),l("/admin/showroom");return}}catch(s){console.error("Access check error:",s),l("/admin/showroom")}},M=()=>{const s=L.map(t=>({publicPath:t,fileName:t.split("/").pop()||"",status:"pending"}));N(s)},j=(s,t)=>{N(n=>n.map((r,m)=>m===s?{...r,...t}:r))},E=async(s,t)=>{try{j(t,{status:"uploading"});const n=await fetch(s.publicPath);if(!n.ok)throw new Error("Datei konnte nicht geladen werden");const r=await n.blob(),m=s.fileName.split(".").pop(),v=`templates/${s.fileName}`,{error:y}=await o.storage.from("showroom-documents").upload(v,r,{contentType:r.type,upsert:!0});if(y)throw y;const{data:T}=o.storage.from("showroom-documents").getPublicUrl(v);return j(t,{status:"success",storageUrl:T.publicUrl}),!0}catch(n){return console.error(`Error migrating ${s.fileName}:`,n),j(t,{status:"error",error:n.message}),!1}},A=async()=>{try{const s=a.filter(t=>t.status==="success");for(const t of s){const n=t.publicPath,{error:r}=await o.from("showroom_document_templates").update({file_url:t.storageUrl}).eq("file_url",n);if(r)throw console.error("Error updating database:",r),r}return i.success("Datenbank erfolgreich aktualisiert"),!0}catch(s){return console.error("Database update error:",s),i.error("Fehler beim Aktualisieren der Datenbank"),!1}},P=async()=>{b(!0),d(0);try{let s=0;for(let r=0;r<a.length;r++){const m=await E(a[r],r);s++,d(s/a.length*70),m||console.warn(`Failed to migrate ${a[r].fileName}, continuing...`)}d(80),await A(),d(100);const t=a.filter(r=>r.status==="success").length,n=a.filter(r=>r.status==="error").length;n===0?i.success(`Migration abgeschlossen! ${t} Dateien erfolgreich migriert.`):i.warning(`Migration teilweise erfolgreich: ${t} erfolgreich, ${n} fehlgeschlagen`)}catch(s){console.error("Migration error:",s),i.error("Fehler während der Migration")}finally{b(!1)}},k=a.every(s=>s.status==="success"),U=a.some(s=>s.status==="error"),z=a.filter(s=>s.status==="pending").length;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("div",{className:"border-b bg-card",children:e.jsx("div",{className:"container mx-auto px-4 py-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(h,{variant:"ghost",size:"icon",onClick:()=>l("/admin/showroom"),children:e.jsx(G,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Storage Migration"}),e.jsx("p",{className:"text-muted-foreground",children:"Migriere Dokumente von /public/test-documents/ zu Supabase Storage"})]})]})})}),e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-4xl",children:[e.jsxs(x,{className:"mb-6 border-blue-200 bg-blue-50/50 dark:bg-blue-950/20",children:[e.jsxs(g,{children:[e.jsxs(p,{className:"flex items-center gap-2 text-blue-900 dark:text-blue-100",children:[e.jsx(I,{className:"h-5 w-5"}),"Migration Information"]}),e.jsx(D,{className:"text-blue-800 dark:text-blue-200",children:"Dieser Prozess wird:"})]}),e.jsxs(f,{className:"text-sm text-blue-900 dark:text-blue-100 space-y-2",children:[e.jsx("p",{children:"✓ Dateien aus /public/test-documents/ laden"}),e.jsx("p",{children:"✓ In Supabase Storage Bucket 'showroom-documents' hochladen"}),e.jsx("p",{children:"✓ file_url in showroom_document_templates Tabelle aktualisieren"}),e.jsx("p",{className:"font-semibold mt-4",children:"Die alten Dateien in /public/ bleiben unverändert als Backup."})]})]}),c&&e.jsxs(x,{className:"mb-6",children:[e.jsx(g,{children:e.jsx(p,{children:"Migration läuft..."})}),e.jsxs(f,{children:[e.jsx(B,{value:w,className:"w-full"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-2 text-center",children:[w.toFixed(0),"% abgeschlossen"]}
1)]})]}),e.jsxs(x,{children:[e.jsxs(g,{children:[e.jsxs(p,{children:["Zu migrierende Dateien (",a.length,")"]}),e.jsx(D,{children:"Status der einzelnen Dateien"})]}),e.jsx(f,{className:"space-y-3",children:a.map((s,t)=>e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-lg",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:s.fileName}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s.publicPath}),s.storageUrl&&e.jsxs("p",{className:"text-xs text-green-600 mt-1",children:["→ ",s.storageUrl]}),s.error&&e.jsxs("p",{className:"text-xs text-red-600 mt-1",children:["Fehler: ",s.error]})]}),e.jsxs("div",{className:"ml-4",children:[s.status==="pending"&&e.jsx("div",{className:"h-8 w-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx("span",{className:"text-xs text-muted-foreground",children:"⏳"})}),s.status==="uploading"&&e.jsx(C,{className:"h-8 w-8 animate-spin text-blue-500"}),s.status==="success"&&e.jsx("div",{className:"h-8 w-8 rounded-full bg-green-100 dark:bg-green-900 flex items-center justify-center",children:e.jsx(F,{className:"h-5 w-5 text-green-600"})}),s.status==="error"&&e.jsx("div",{className:"h-8 w-8 rounded-full bg-red-100 dark:bg-red-900 flex items-center justify-center",children:e.jsx(Z,{className:"h-5 w-5 text-red-600"})})]})]},s.publicPath))})]}),e.jsxs("div",{className:"mt-6 flex gap-4 justify-end",children:[e.jsx(h,{variant:"outline",onClick:()=>l("/admin/showroom"),disabled:c,children:"Zurück"}),!k&&e.jsx(h,{onClick:P,disabled:c,size:"lg",children:c?e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"h-4 w-4 mr-2 animate-spin"}),"Migration läuft..."]}):U?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"h-4 w-4 mr-2"}),"Erneut versuchen"]}):e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"h-4 w-4 mr-2"}),"Migration starten"]})}),k&&e.jsxs(h,{variant:"default",onClick:()=>l("/admin/showroom/templates"),size:"lg",children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),"Zu Templates →"]})]}),e.jsxs(x,{className:"mt-6",children:[e.jsx(g,{children:e.jsx(p,{className:"text-lg",children:"Status Zusammenfassung"})}),e.jsxs(f,{className:"grid grid-cols-3 gap-4 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold text-muted-foreground",children:z}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ausstehend"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold text-green-600",children:a.filter(s=>s.status==="success").length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Erfolgreich"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold text-red-600",children:a.filter(s=>s.status==="error").length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Fehlgeschlagen"})]})]})]})]})]})}export{Y 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.