PageSourceSearch

https://hdoria.me/assets/AlbumCovers-DDWsgCh4.js

js hdoria.me collected 2026-10-05 08:56:26 UTC 5,884 bytes, 1 lines download raw bytes

1import{r as d,j as e,a1 as b,I as N,g as O,f as C,c as h,w as l}from"./index-ALTOM8bk.js";import{D as P,a as Q,b as z,c as T,f as B,u as y,P as L,U as D,T as _,d as $}from"./DeleteConfirmDialog-BOUd1pz4.js";import{A as G}from"./AdminLayout-CStrovJC.js";import{B as j}from"./button-ChrHAFJj.js";import{C as H}from"./card-C0DTPPh4.js";import"./index-BnQvLsPI.js";const J=({open:g,onClose:c,onSave:v,album:o})=>{const[t,m]=d.useState(""),[u,f]=d.useState("");d.useEffect(()=>{o?(m(o.name),f(o.filename)):(m(""),f(""))},[o,g]);const x=()=>{!t.trim()||!u.trim()||(v(t.trim(),u.trim()),c())};return e.jsx(P,{open:g,onOpenChange:c,children:e.jsxs(Q,{children:[e.jsx(z,{children:e.jsx(T,{children:o?"Editar Álbum":"Adicionar Álbum"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(b,{htmlFor:"album-name",children:"Nome do Álbum"}),e.jsx(N,{id:"album-name",value:t,onChange:i=>m(i.target.value),placeholder:"Ex: Pink Floyd - Dark Side of the Moon"})]}),e.jsxs("div",{children:[e.jsx(b,{htmlFor:"album-filename",children:"Nome do Arquivo"}),e.jsx(N,{id:"album-filename",value:u,onChange:i=>f(i.target.value),placeholder:"Ex: pink-floyd-dark-side.jpg",disabled:!!o}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Use apenas letras minúsculas, números e hífens. Extensão .jpg"})]})]}),e.jsxs(B,{children:[e.jsx(j,{variant:"outline",onClick:c,children:"Cancelar"}),e.jsx(j,{onClick:x,disabled:!t.trim()||!u.trim(),children:"Salvar"})]})]})})},ee=()=>{const[g,c]=d.useState(null),[v,o]=d.useState(!1),[t,m]=d.useState(null),[u,f]=d.useState(!1),x=O(),{data:i,isLoading:E}=C({queryKey:["albums"],queryFn:async()=>{const{data:s,error:a}=await h.from("albums").select("*").order("display_order",{ascending:!0});if(a)throw a;return s||[]}}),{data:p}=C({queryKey:["album-covers-storage"],queryFn:async()=>{const{data:s,error:a}=await h.storage.from("album-covers").list("",{limit:100});if(a)throw a;return(s==null?void 0:s.map(r=>r.name))||[]}}),q=y({mutationFn:async({file:s,filename:a})=>{const{error:r}=await h.storage.from("album-covers").upload(a,s,{contentType:"image/jpeg",upsert:!0});if(r)throw r},onSuccess:()=>{x.invalidateQueries({queryKey:["album-covers-storage"]}),l.success("Capa enviada com sucesso!"),c(null)},onError:s=>{l.error("Erro ao enviar capa: "+s.message),c(null)}}),A=y({mutationFn:async({name:s,filename:a})=>{const r=(i==null?void 0:i.reduce((I,K)=>Math.max(I,K.display_order),0))||0,{error:n}=await h.from("albums").insert({name:s,filename:a,display_order:r+1});if(n)throw n},onSuccess:()=>{x.invalidateQueries({queryKey:["albums"]}),l.success("Álbum adicionado com sucesso!")},onError:s=>{l.error("Erro ao adicionar álbum: "+s.message)}}),w=y({mutationFn:async({id:s,filename:a})=>{if(p!=null&&p.includes(a)){const{error:n}=await h.storage.from("album-covers").remove([a]);if(n)throw n}const{error:r}=await h.from("albums").delete().eq("id",s);if(r)throw r},onSuccess:()=>{x.invalidateQueries({queryKey:["albums"]}),x.invalidateQueries({queryKey:["album-covers-storage"]}),l.success("Álbum removido com sucesso!"),o(!1),m(null)},onError:s=>{l.error("Erro ao remover álbum: "+s.message)}}),F=async(s,a)=>{var n;const r=(n=a.target.files)==null?void 0:n[0];if(r){if(!r.type.startsWith("image/")){l.error("Por favor, selecione uma imagem");return}if(r.size>5*1024*1024){l.error("Imagem muito grande. Máximo 5MB");return}c(s),q.mutate({file:r,filename:s})}},S=s=>{m(s),o(!0)},k=()=>{t&&w.mutate({id:t.id,filename:t.filename})},M=(s,a)=>{A.mutate({name:s,filename:a})},U=s=>`https://bmczepksdugixqutecze.supabase.co/storage/v1/object/public/album-covers/${s}`;return e.jsxs(G,{children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Capas de Álbum"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Gerencie os álbuns e faça upload das capas (formato JPG, máximo 5MB)"})]}),e.jsxs(j,{onClick:()=>f(!0),children:[e.jsx(L,{className:"w-4 h-4 mr-2"}),"Adicionar Álbum"]})]}),E?e.jsx("div",{className:"text-center py-12",children:"Carregando..."}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:i==null?void 0:i.map(s=>{const a=p==null?void 0:p.includes(s.filename),r=g===s.filename;return e.jsx(H,{className:"p-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"aspect-square bg-muted rounded-lg overflow-hidden",children:a?e.jsx("img",{src:U(s.filename),alt:s.name,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(D,{className:"w-12 h-12 text-muted-foreground"})})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-sm",children:s.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.filename})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(b,{htmlFor:s.filename,className:"cursor-pointer",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 px-3 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-colors",children:[e.jsx(D,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:r?"Enviando...":a?"Substituir":"Upload"})]})}),e.jsx(N,{id:s.filename,type:"file",accept:"image/*",className:"hidden",onChange:n=>F(s.filename,n),disabled:r})]}),e.jsx(j,{variant:"destructive",size:"icon",onClick:()=>S(s),disabled:w.isPending,children:e.jsx(_,{className:"w-4 h-4"})})]})]})},s.filename)})})]}),e.jsx($,{open:v,onClose:()=>o(!1),onConfirm:k,title:"Confirmar exclusão",description:`Tem certeza que deseja remover o álbum "${t==null?void 0:t.name}"? A capa também será removida do storage.`}),e.jsx(J,{open:u,onClose:()=>f(!1),onSave:M})]})};export{ee 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.