veza/apps/web/dist_verification/assets/LibraryPage-Xac4xZs3.js

7 lines
20 KiB
JavaScript
Raw Normal View History

import{j as e,a as l}from"./vendor-react-C9dYU-TK.js";import{c as P,F as ce,B as L,D as de,l as ue,E as me,C as xe,S as U,i as pe,h as fe}from"./index-BMBS6scK.js";import{C as he}from"./ContentFadeIn-BtLzuDVj.js";import{ah as ge}from"./vendor-CjLUfV8Y.js";import{b as be,u as je}from"./vendor-tanstack-C4XaEYj2.js";import{t as ye}from"./tracks-0_sMTeS6.js";import{a as ve}from"./trackService-Dud99AaM.js";import{u as Ne,D as we,a as ke,b as Ce,c as B}from"./useIsRateLimited-8kuXO8Mx.js";import{aQ as V,X as Se,e as De,R as Ae,a6 as K,Y as Ee,al as Ue,r as Y,c as Me,aJ as Pe,aa as Le,i as Re,S as Te,aR as Fe,aE as ze,P as Ie}from"./vendor-icons-BSV6HBy1.js";import{a as Ve}from"./progress-DFVonymQ.js";import{A as _e}from"./alert-Bql2WpQW.js";import{L as I,I as M}from"./input-DeoQfymd.js";import{p as Ge,i as Qe,a as Oe}from"./vendor-utils-D0JLFg89.js";import{m as q}from"./vendor-motion-CbAtAbUE.js";import{u as Be}from"./vendor-router-Dr0ZB7zf.js";import"./vendor-http-CctT3C58.js";import"./vendor-i18n-PN7w4axr.js";import"./vendor-security-DsrNJhpn.js";import"./dropdown-CPqsiWN7.js";function qe({children:s,variant:r="default",className:t}){return e.jsx("div",{className:P("p-8",r==="alert"&&"text-destructive",t),children:s})}function Ke({children:s,className:r}){return e.jsx("div",{className:P("flex items-center justify-end gap-2 p-8 border-t border-border",r),children:s})}const O={all:["library"],tracks:s=>[...O.all,"tracks",{userId:s}]};function Ye(s=1,r=50){const{user:t}=ce();return be({queryKey:[...O.tracks(t?.id),{page:s,limit:r}],queryFn:()=>ve({userId:t?.id,page:s,limit:r}),enabled:!!t?.id,placeholderData:d=>d})}const $e=100*1024*1024,We={"audio/mpeg":[".mp3"],"audio/wav":[".wav"],"audio/ogg":[".ogg"],"audio/flac":[".flac"],"audio/mp4":[".m4a"],"audio/aac":[".aac"]},Q=3;function Xe({onClose:s}){const[r,t]=l.useState(null),[d,a]=l.useState(0),[n,x]=l.useState(!1),[v,i]=l.useState(null),[h,g]=l.useState(null),[N,b]=l.useState(!1),[j,p]=l.useState(0),[D,y]=l.useState(!1),[u,w]=l.useState({file:null,title:"",artist:"",album:"",genre:""}),[R,S]=l.useState({}),m=Ne(),A=je(),k=l.useCallback(()=>{w({file:null,title:"",artist:"",album:"",genre:""}),S({})},[]),_=l.useCallback(()=>{n||(t(null),a(0),i(null),g(null),b(!1),p(0),y(!1),k(),s())},[n,k,s]),E=l.useCallback((o,c)=>{w(f=>({...f,[o]:c}))},[]),G=l.useCallback(()=>u,[u]),T=l.useCallback(async(o,c=1)=>{if(!o.file){i("Veuillez sélectionner un fichier"),g(null),b(!1);return}x(!0),i(null),g(null),b(!1),y(!1),a(0);try{const f={title:o.title||o.file.name.replace(/\.[^/.]+$/,""),artist:o.artist,album:o.album,genre:o.genre,is_public:!1};await ye.create(o.file,f,C=>{a(C)}),y(!0),a(100),p(0),A.invalidateQueries({queryKey:O.all}),A.invalidateQueries({queryKey:["tracks"]}),setTimeout(()=>_(),1500)}catch(f){let C="Erreur lors de l'upload",F=null,z=!1;if(f instanceof Error){C=f.message;const oe=/network|réseau|timeout|econnaborted|etimedout|se connecter/i.test(C),ie=/serveur|server|500|503|502/i.test(C),ne=/format|taille|invalide|trop volumineux|non supporté|400|413|415/i.test(C);oe?(F="NETWORK",z=c<Q):ie?(F="SERVER",z=c<Q):ne&&(F="VALIDATION",z=!1)}i(C),g(F),b(z),a(0),p(c)}finally{x(!1)}},[A,_]),J=l.useCallback(o=>{const c=o[0];if(c){t(c),i(null),y(!1),E("file",c);const f=c.name.replace(/\.[^/.]+$/,"");u.title||E("title",f)}},[E,u.title]),{getRootProps:Z,getInputProps:H,isDragActive:ee}=ge({onDrop:J,accept:We,maxSize:$e,multiple:!1,onError:o=>i(`Erreur lors de la sélection du fichier: ${o.message}`),onDropRejected:o=>{const c=o[0];c?.errors[0]?.code==="file-too-large"?i("Le fichier est trop volumineux (max 100 MB)"):c?.errors[0]?.code==="file-invalid-type"?i("Format de fichier non supporté. Formats acceptés: MP3, WAV, OGG, FLAC, M4A, AAC"):i(c?.errors[0]?.message||"Erreur lors de la sélection du fichier")}}),se=o=>({value:u[o]instanceof File?"":u[o]||"",onChange:c=>{w(f=>({...f,[o]:c.target.value}))}}),re=l.useCallback((o,c)=>f=>{if(f.preventDefault(),!u.file){S({file:"Veuillez sélectionner un fichier"}),c?.({file:{message:"Veuillez sélectionner un fichier"}});return}S({}),o(u)},[u]),
border-2 border-dashed rounded-lg p-12 text-center cursor-pointer
transition-colors
${t?"border-primary bg-primary/5":"border-muted-foreground/25"}
hover:border-primary hover:bg-primary/5
`,children:[e.jsx("input",{...r()}),e.jsx(V,{className:"mx-auto h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"text-lg font-medium mb-2",children:t?"Déposez le fichier ici":"Glissez-déposez un fichier audio"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"ou cliquez pour sélectionner"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Formats acceptés: MP3, WAV, OGG, FLAC, M4A, AAC (max 100 MB)"})]})}function Ze({file:s,isUploading:r,onRemove:t}){return e.jsx("div",{className:"border rounded-lg p-4","data-testid":"upload-file-display",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(V,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium","data-testid":"upload-file-name",children:s.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[(s.size/1024/1024).toFixed(2)," MB"]})]})]}),!r&&e.jsx(L,{type:"button",variant:"ghost",size:"icon",onClick:t,className:"h-8 w-8",children:e.jsx(Se,{className:"h-4 w-4"})})]})})}function He({progress:s}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{children:"Upload en cours..."}),e.jsxs("span",{children:[s,"%"]})]}),e.jsx(Ve,{value:s})]})}function es({error:s,errorCode:r,retryCount:t,isRetryable:d,isUploading:a,onRetry:n}){return e.jsx(_e,{variant:"destructive","data-testid":"upload-error",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(De,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s}),r&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Code d'erreur: ",r]}),t>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Tentative ",t,"/",Q]})]}),d&&e.jsxs(L,{type:"button",variant:"outline",size:"sm",onClick:n,disabled:a,className:"mt-2",children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Réessayer"]})]})]})})}function ss({register:s,errors:r}){return e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsx("h3",{className:"font-medium",children:"Métadonnées (optionnel)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"title",children:"Titre *"}),e.jsx(M,{id:"title",...s("title"),placeholder:"Titre du morceau"}),r.title&&e.jsx("p",{className:"text-sm text-destructive",children:r.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"artist",children:"Artiste"}),e.jsx(M,{id:"artist",...s("artist"),placeholder:"Nom de l'artiste"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"album",children:"Album"}),e.jsx(M,{id:"album",...s("album"),placeholder:"Nom de l'album"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"genre",children:"Genre"}),e.jsx(M,{id:"genre",...s("genre"),placeholder:"Genre musical"})]})]})]})}function rs({open:s,onClose:r}){const{file:t,uploadProgress:d,isUploading:a,error:n,errorCode:x,isRetryable:v,retryCount:i,success:h,formErrors:g,register:N,handleSubmit:b,onSubmit:j,getRootProps:p,getInputProps:D,isDragActive:y,handleClose:u,handleRetry:w,handleRemoveFile:R,isRateLimited:S}=Xe({onClose:r});return e.jsx(de,{open:s,onClose:u,title:"Uploader un fichier audio",size:"lg",children:e.jsxs("form",{id:"upload-track-form",onSubmit:b(j,m=>{ue.warn("Form validation errors:",{errors:m})}),children:[e.jsx(qe,{children:e.jsxs("div",{className:"space-y-6",children:[t?e.jsx(Ze,{file:t,isUploading:a,onRemove:R}):e.jsx(Je,{getRootProps:p,getInputProps:D,isDragActive:y}),a&&e.jsx(He,{progress:d}),n&&e.jsx(es,{error:n,errorCode:x,retryCount:i,isRetryable:v,isUploading:a,onRetry:w}),h&&e.jsxs("div",{className:"rounded-lg border bg-success/10 border-success p-4 flex items-center gap-2 text-success",children:[e.jsx(K,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{children: