Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nj5Lhar9tgd2sY35EYatva
1 line
6.6 KiB
JavaScript
1 line
6.6 KiB
JavaScript
import{q as S,r as h,j as t,P,B as g,w as $,T as y,x as C,F as b,Z as E,t as _,W as B,c as j,C as F,_ as A}from"./index-D7EYWwBs.js";import{b as v,f as I,A as L}from"./downloads-B9pqFegV.js";import{u as O,E as W,R as T}from"./EntityList-DD3vf6ut.js";import"./SortableList-B2IgNCfB.js";import"./sortable.esm-C1TKvDDJ.js";import"./grip-vertical-DzrLyKEU.js";const M={title:"",description:"",sort_order:0},R={audio:"play",video:"play",image:"image"};function N(m,n,c){return new Promise((r,l)=>{const i=new XMLHttpRequest;i.open("POST",`${A}${m}`),i.withCredentials=!0,i.upload.onprogress=a=>{a.lengthComputable&&c(a.loaded/a.total)},i.onload=()=>{let a=null;try{a=JSON.parse(i.responseText)}catch{}i.status>=200&&i.status<300?r(a):l(new Error((a==null?void 0:a.error)||(i.status===413?"Die Datei ist zu groß für diesen Server.":`Fehler ${i.status}`)))},i.onerror=()=>l(new Error("Netzwerkfehler beim Hochladen")),i.send(n)})}function q(){const m=S(),[n,c]=h.useState(void 0),[r,l]=h.useState(""),[i,a]=h.useState(!1),[s,f]=h.useState("");h.useEffect(()=>{j.get("/settings/downloads").then(o=>{c(o.password),l(o.password||"")}).catch(o=>f(o.message))},[]);const x=async o=>{o.preventDefault(),a(!0),f("");try{const p=await j.put("/settings/downloads",{password:r});c(p.password),l(p.password||""),m.success(p.password?"Gespeichert – der Bereich ist jetzt geschützt.":"Gespeichert – der Bereich ist jetzt öffentlich.")}catch(p){f(p.message)}finally{a(!1)}},w=(n||"")===r.trim();return t.jsx(F,{title:"Zugriffsschutz",description:"Mit Passwort sehen nur Kunden die Dateien, denen ihr den Code gebt.",actions:n===void 0?null:n?t.jsx(y,{tone:"brand",children:"Geschützt"}):t.jsx(y,{tone:"amber",children:"Öffentlich"}),children:t.jsxs("form",{onSubmit:x,children:[t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end",children:[t.jsx(b,{label:"Zugangspasswort",error:s,className:"flex-1",children:t.jsx(_,{value:r,maxLength:100,autoComplete:"off",onChange:o=>l(o.target.value),placeholder:"Leer lassen = öffentlich"})}),t.jsx(g,{type:"submit",disabled:i||n===void 0||w,children:"Speichern"})]}),t.jsx("p",{className:"mt-2 text-xs text-neutral-500 dark:text-neutral-400",children:"Das Passwort bleibt hier jederzeit einsehbar. Direkte Links zu einzelnen Dateien funktionieren auch ohne Passwort."})]})})}function J(){const m=S(),[n,c]=h.useState(null),[r,l]=h.useState(null),[i,a]=h.useState(null),s=O({endpoint:"/downloads",listEndpoint:"/downloads/manage",reorderKey:"downloads",source:"downloads",emptyForm:M,toForm:e=>({title:e.title,description:e.description||"",sort_order:e.sort_order}),labels:{created:"Datei hochgeladen.",saved:"Download gespeichert.",deleted:"Download gelöscht."},save:async({editing:e,form:u})=>{try{if(e!=="new"){if(await j.put(`/downloads/${e}`,u),n){const d=new FormData;d.append("file",n),l(0),await N(`/downloads/${e}/file`,d,l)}}else{const d=new FormData;d.append("file",n),d.append("title",u.title),d.append("description",u.description),l(0),await N("/downloads",d,l)}c(null)}finally{l(null)}}}),{form:f,change:x}=s,w=s.isNew?null:(s.items||[]).find(e=>e.id===s.editing),o=e=>{c(null),s.openPanel(e)},p=e=>{c(e),s.setExtraDirty(!0)},k=e=>{if(e.preventDefault(),s.isNew&&!n){s.setError("Bitte eine Datei auswählen.");return}s.submit()},z=async e=>{a(e.id);try{const u=await j.patch(`/downloads/${e.id}/visibility`,{is_hidden:!e.is_hidden});s.setItems(d=>d.map(D=>D.id===e.id?{...D,is_hidden:u.is_hidden}:D)),m.success(u.is_hidden?`„${e.title}“ ist jetzt ausgeblendet.`:`„${e.title}“ ist wieder sichtbar.`)}catch(u){m.error(`Sichtbarkeit konnte nicht geändert werden: ${u.message}`)}finally{a(null)}};return t.jsxs("div",{className:"space-y-6",children:[t.jsx(P,{title:"Downloads",description:"Songs, Anleitungen und andere Dateien für eure Kunden. Der Menüpunkt erscheint auf der Website, sobald eine Datei sichtbar ist. Reihenfolge am Griff links ziehen.",className:"!mb-0",actions:t.jsxs(t.Fragment,{children:[t.jsx(g,{variant:"secondary",icon:"eye",href:"/downloads",target:"_blank",rel:"noopener noreferrer",children:"Ansehen"}),t.jsx(g,{icon:"plus",onClick:()=>o(null),children:"Datei hochladen"})]})}),t.jsx(W,{items:s.items,editingId:s.editing,onReorder:s.reorder,onOpen:o,onDelete:e=>s.remove(e,`„${e.title}“ inkl. Datei wirklich löschen?`),searchText:e=>`${e.title} ${e.file_name}`,searchPlaceholder:"Datei suchen …",empty:{icon:"download",title:"Noch keine Dateien",description:"Lade z. B. Demo-Songs oder Bedienungsanleitungen hoch.",actions:t.jsx(g,{icon:"plus",onClick:()=>o(null),children:"Datei hochladen"})},renderRow:e=>({media:t.jsx(T,{icon:R[I(e.file_name)]||"file"}),title:e.title,subtitle:t.jsxs(t.Fragment,{children:[!!e.is_hidden&&t.jsx(y,{tone:"amber",className:"mr-2",children:"Ausgeblendet"}),e.file_name," · ",v(e.file_size)]}),muted:!!e.is_hidden,actions:t.jsx($,{icon:e.is_hidden?"eyeOff":"eye",label:e.is_hidden?"Wieder auf der Website anzeigen":"Auf der Website ausblenden",disabled:i===e.id,onClick:()=>z(e)})})}),t.jsx(q,{}),t.jsxs(C,{as:"form",onSubmit:k,open:s.editing!==null,onClose:s.closePanel,size:"lg",title:s.isNew?"Datei hochladen":"Download bearbeiten",footer:t.jsxs(t.Fragment,{children:[t.jsx(g,{variant:"secondary",onClick:s.closePanel,disabled:s.saving,children:"Abbrechen"}),t.jsx(g,{type:"submit",disabled:s.saving||!s.isNew&&!s.dirty,children:s.saving?r!==null&&r<1?`Lädt hoch … ${Math.round(r*100)} %`:"Speichere…":s.isNew?"Hochladen":"Speichern"})]}),children:[s.error&&t.jsx("p",{className:"rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700 dark:bg-red-950/40 dark:text-red-300",children:s.error}),t.jsx(b,{label:s.isNew?"Datei":"Datei ersetzen (optional)",required:s.isNew,children:t.jsx(E,{file:n,onChange:p,disabled:s.saving,accept:L.map(e=>`.${e}`).join(","),current:w?`${w.file_name} (${v(w.file_size)})`:null,hint:"Musik, Videos, PDFs, Bilder, Office-Dateien oder ZIP. Andere Typen bitte als ZIP."})}),r!==null&&t.jsxs("div",{children:[t.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-neutral-200 dark:bg-neutral-800",children:t.jsx("div",{className:"h-full rounded-full bg-brand-500 transition-[width]",style:{width:`${Math.round(r*100)}%`}})}),t.jsx("p",{className:"mt-1 text-xs text-neutral-500 dark:text-neutral-400",children:r<1?`Wird hochgeladen … ${Math.round(r*100)} %`:"Wird gespeichert …"})]}),t.jsx(b,{label:"Titel",required:!s.isNew,hint:s.isNew?"Leer lassen = Dateiname":null,children:t.jsx(_,{required:!s.isNew,maxLength:150,value:f.title,onChange:e=>x({title:e.target.value}),placeholder:s.isNew&&(n==null?void 0:n.name)||""})}),t.jsx(b,{label:"Beschreibung (optional)",children:t.jsx(B,{rows:3,value:f.description,onChange:e=>x({description:e.target.value})})})]})]})}export{J as default};
|