- Deleted apps/web/src/utils/optimisticStoreUpdates.ts (unused file) - File was unused - no imports found in codebase - Mutations already use React Query's onMutate pattern - No TypeScript errors after deletion - Actions 4.4.1.2 and 4.4.1.3 complete
7 lines
15 KiB
JavaScript
7 lines
15 KiB
JavaScript
import{u as de,n as ue,T as G,o as j,A as pe,r as u,j as e,c as y,X as W,p as Y,q as me,s as fe,I as he,t as ge,v as xe,D as we,w as ye,F as K,B as L,x as je,y as be,z as R,G as F,H as ve,U as ke,l as Ne}from"./chunk-m7Vgm5hx.js";import{A as b}from"./chunk-CbPYJovs.js";const Le=()=>{const{isAuthenticated:a,logout:s}=de(),{data:t}=ue(),r=async()=>{await s()},n=G.getAccessToken();return{user:t??null,accessToken:n||null,refreshToken:G.getRefreshToken()||null,isAuthenticated:a,logout:r}};async function Ee(a,s){let n=0;for(;n<120;)try{const o=(await j.get(`/tracks/${a}`)).data;if(s){let p=0;o.status==="uploading"?p=30:o.status==="processing"?p=70:o.status==="completed"&&(p=100),s(p)}if(o.status==="completed")return o;if(o.status==="failed")throw new Error(o.status_message||"Le traitement du fichier a échoué");await new Promise(p=>setTimeout(p,1e3)),n++}catch(i){if(i instanceof b&&i.response?.status===404){await new Promise(o=>setTimeout(o,1e3)),n++;continue}throw i}throw new Error("Le traitement du fichier prend plus de temps que prévu. Veuillez réessayer plus tard.")}async function Ce(a,s={},t){try{const r=new FormData;r.append("file",a),s.title&&r.append("title",s.title),s.artist&&r.append("artist",s.artist),s.album&&r.append("album",s.album),s.genre&&r.append("genre",s.genre),s.year&&r.append("year",s.year.toString()),s.is_public!==void 0&&r.append("is_public",s.is_public.toString());const n={onUploadProgress:o=>{if(o.total&&t){const p=Math.round(o.loaded*100/o.total);t(Math.min(p*.2,20))}},timeout:pe.UPLOAD},i=await j.post("/tracks",r,n);if(i.status===202){const p=i.data.track_id;return t&&t(25),await Ee(p,t)}return i.data}catch(r){if(r instanceof b){if(r.response?.status===400){const i=r.response?.data?.error?.message||r.response?.data?.message||"Format ou taille invalide";throw new Error(i)}if(r.response?.status===413)throw new Error("Fichier trop volumineux");if(r.response?.status===415)throw new Error("Format de fichier non supporté");if(r.response?.status===500)throw new Error("Erreur serveur: Impossible de traiter le fichier. Veuillez réessayer plus tard.");if(r.code==="ECONNABORTED"||r.code==="ETIMEDOUT"||!r.response)throw new Error("Erreur réseau: Impossible de se connecter au serveur.");const n=r.response?.data?.error?.message||r.response?.data?.message||r.message||"Erreur lors de l'upload";throw new Error(n)}throw r}}async function Re(a=1,s=20,t){try{const r=new URLSearchParams;r.append("page",a.toString()),r.append("limit",s.toString()),t?.userId!==void 0&&r.append("user_id",t.userId.toString()),t?.genre&&r.append("genre",t.genre),t?.format&&r.append("format",t.format),t?.search&&r.append("search",t.search),t?.sortBy&&r.append("sort_by",t.sortBy),t?.sortOrder&&r.append("sort_order",t.sortOrder);const n=r.toString(),i=`/tracks${n?`?${n}`:""}`;return(await j.get(i)).data}catch(r){if(r instanceof b){if(r.response?.status===500)throw new Error("Erreur serveur: Impossible de récupérer les tracks. Veuillez réessayer plus tard.");if(r.code==="ECONNABORTED"||r.code==="ETIMEDOUT"||!r.response)throw new Error("Erreur réseau: Impossible de se connecter au serveur.");const n=r.response?.data?.error?.message||r.response?.data?.message||r.message||"Échec de la récupération des tracks";throw new Error(n)}throw r}}async function Fe(a,s){try{const{data:t}=await j.post(`/tracks/${a}/share`,s);return t.share}catch(t){if(t instanceof b){if(t.response?.status===404)throw new Error("Track introuvable");const r=t.response?.data?.error?.message||t.response?.data?.message||t.message||"Échec de la création du lien de partage";throw new Error(r)}throw t}}async function _e(a){try{const{data:s}=await j.post("/tracks/batch/delete",{track_ids:a});return s}catch(s){if(s instanceof b){const t=s.response?.data?.error?.message||s.response?.data?.message||s.message||"Échec de la suppression en masse";throw new Error(t)}throw s}}async function Ue(a,s){try{const{data:t}=await j.post("/tracks/batch/update",{track_ids:a,updates:s});return t}catch(t){if(t instanceof b){const r=t.response?.data?.error?.message||t.response?.data?.message||t.message||"Échec de la mise à jour en masse";throw new Error(r)}throw t}}const Q=u.forwardRef(({value:a,max:s=100,variant:t="default",color:r="cyan",labelLeft:n,labelRight:i,className:o,...p},g)=>{const m=Math.min(100,Math.max(0,a/s*100)),x={cyan:"bg-kodo-cyan",magenta:"bg-kodo-magenta",lime:"bg-kodo-lime",gold:"bg-kodo-gold"},h={gold:"from-kodo-gold to-orange-500"};return t==="gaming"?e.jsxs("div",{className:y("relative",o),ref:g,...p,children:[e.jsx("div",{className:"h-4 bg-kodo-void rounded-full overflow-hidden border border-kodo-gold/30",children:e.jsx("div",{className:y("h-full bg-gradient-to-r shadow-[0_0_10px_rgba(255,215,0,0.5)] transition-all duration-500",h.gold),style:{width:`${m}%`}})}),(n||i)&&e.jsxs("div",{className:"flex justify-between text-[10px] font-mono font-bold text-kodo-gold mt-1 uppercase tracking-wider",children:[e.jsx("span",{children:n}),e.jsx("span",{children:i})]})]}):e.jsxs("div",{className:y("w-full",o),ref:g,...p,children:[e.jsx("div",{className:"h-2 bg-kodo-steel rounded-full overflow-hidden",children:e.jsx("div",{className:y("h-full transition-all duration-300 shadow-[0_0_10px_currentColor]",x[r]),style:{width:`${m}%`}})}),(n||i)&&e.jsxs("div",{className:"flex justify-between text-xs text-gray-500 mt-1 font-mono",children:[e.jsx("span",{children:n}),e.jsx("span",{children:i})]})]})});Q.displayName="Progress";const B=u.forwardRef(({variant:a="default",title:s,onClose:t,className:r,children:n,...i},o)=>{const g={destructive:"error",default:"info"}[a]||a,m={info:"bg-kodo-cyan/10 border-kodo-cyan/30 text-kodo-cyan",success:"bg-kodo-lime/10 border-kodo-lime/30 text-kodo-lime",warning:"bg-kodo-gold/10 border-kodo-gold/30 text-kodo-gold",error:"bg-kodo-red/10 border-kodo-red/30 text-kodo-red"},x={info:e.jsx(he,{className:"w-5 h-5 flex-shrink-0"}),success:e.jsx(fe,{className:"w-5 h-5 flex-shrink-0"}),warning:e.jsx(me,{className:"w-5 h-5 flex-shrink-0"}),error:e.jsx(Y,{className:"w-5 h-5 flex-shrink-0"})},h=g;return e.jsxs("div",{ref:o,role:"alert",className:y("p-4 rounded-lg border flex gap-3",m[h]||m.info,r),...i,children:[x[h]||x.info,e.jsxs("div",{className:"flex-1",children:[s&&e.jsx("h5",{className:"font-bold mb-1",children:s}),e.jsx("div",{className:"text-sm opacity-90",children:n})]}),t&&e.jsx("button",{onClick:t,className:"opacity-70 hover:opacity-100 transition-opacity",children:e.jsx(W,{className:"w-4 h-4"})})]})});B.displayName="Alert";const Te=u.forwardRef(({className:a,...s},t)=>e.jsx("h5",{ref:t,className:y("mb-1 font-bold leading-none tracking-tight text-white",a),...s}));Te.displayName="AlertTitle";const Ae=u.forwardRef(({className:a,...s},t)=>e.jsx("div",{ref:t,className:y("text-sm opacity-90 [&_p]:leading-relaxed",a),...s}));Ae.displayName="AlertDescription";class w extends Error{constructor(s,t,r=!1,n){super(s),this.code=t,this.retryable=r,this.originalError=n,this.name="TrackServiceError"}}async function Oe(a){try{return(await j.get(`/tracks/${a}`)).data.track}catch(s){if(s instanceof b){if(s.response?.status===401)throw new w("Non autorisé: Veuillez vous connecter pour voir ce track","VALIDATION",!1,s);if(s.response?.status===404)throw new w("Track introuvable","VALIDATION",!1,s);if(s.response?.status===500)throw new w("Erreur serveur: Impossible de récupérer le track. Veuillez réessayer plus tard.","SERVER",!0,s);if(s.code==="ECONNABORTED"||s.code==="ETIMEDOUT"||!s.response)throw new w("Erreur réseau: Impossible de se connecter au serveur.","NETWORK",!0,s);const t=s.response?.data?.error||s.message||"Échec de la récupération du track";throw new w(t,"UNKNOWN",!1,s)}throw s instanceof w?s:new w("Erreur inconnue lors de la récupération du track","UNKNOWN",!1,s)}}const X={all:["library"],tracks:a=>[...X.all,"tracks",{userId:a}]},Se=100*1024*1024,Ie={"audio/mpeg":[".mp3"],"audio/wav":[".wav"],"audio/ogg":[".ogg"],"audio/flac":[".flac"],"audio/mp4":[".m4a"],"audio/aac":[".aac"]},P=3;function Ve({open:a,onClose:s}){const[t,r]=u.useState(null),[n,i]=u.useState(0),[o,p]=u.useState(!1),[g,m]=u.useState(null),[x,h]=u.useState(null),[H,k]=u.useState(!1),[N,_]=u.useState(0),[E,v]=u.useState(!1),U=ge(),[C,O]=u.useState({file:null,title:"",artist:"",album:"",genre:""}),[Z,V]=u.useState({}),T=l=>({value:C[l],onChange:d=>{O(f=>({...f,[l]:d.target.value}))}}),A=(l,d)=>{O(f=>({...f,[l]:d}))},S=()=>C,J=()=>{O({file:null,title:"",artist:"",album:"",genre:""}),V({})},ee=(l,d)=>f=>{if(f.preventDefault(),!C.file){V({file:"Veuillez sélectionner un fichier"}),d?.({file:{message:"Veuillez sélectionner un fichier"}});return}V({}),l(C)},$=Z,se=u.useCallback(l=>{const d=l[0];if(d){r(d),m(null),v(!1),A("file",d);const f=d.name.replace(/\.[^/.]+$/,"");S()||A("title",f)}},[A,S]),{getRootProps:re,getInputProps:te,isDragActive:q}=xe({onDrop:se,accept:Ie,maxSize:Se,multiple:!1,onError:l=>{m(`Erreur lors de la sélection du fichier: ${l.message}`)},onDropRejected:l=>{const d=l[0];d.errors[0]?.code==="file-too-large"?m("Le fichier est trop volumineux (max 100 MB)"):d.errors[0]?.code==="file-invalid-type"?m("Format de fichier non supporté. Formats acceptés: MP3, WAV, OGG, FLAC, M4A, AAC"):m(d.errors[0]?.message||"Erreur lors de la sélection du fichier")}}),I=u.useCallback(async(l,d=1)=>{if(!l.file){m("Veuillez sélectionner un fichier"),h(null),k(!1);return}p(!0),m(null),h(null),k(!1),v(!1),i(0);try{const f={title:l.title||l.file.name.replace(/\.[^/.]+$/,""),artist:l.artist,album:l.album,genre:l.genre,is_public:!1};await Ce(l.file,f,c=>{i(c)}),v(!0),i(100),_(0),U.invalidateQueries({queryKey:X.all}),U.invalidateQueries({queryKey:["tracks"]}),setTimeout(()=>{z()},1500)}catch(f){let c="Erreur lors de l'upload",M=null,D=!1;if(f instanceof Error){c=f.message;const ie=c.toLowerCase().includes("network")||c.toLowerCase().includes("réseau")||c.toLowerCase().includes("timeout")||c.toLowerCase().includes("econnaborted")||c.toLowerCase().includes("etimedout")||c.toLowerCase().includes("se connecter"),le=c.toLowerCase().includes("serveur")||c.toLowerCase().includes("server")||c.toLowerCase().includes("500")||c.toLowerCase().includes("503")||c.toLowerCase().includes("502"),ce=c.toLowerCase().includes("format")||c.toLowerCase().includes("taille")||c.toLowerCase().includes("invalide")||c.toLowerCase().includes("trop volumineux")||c.toLowerCase().includes("non supporté")||c.toLowerCase().includes("400")||c.toLowerCase().includes("413")||c.toLowerCase().includes("415");ie?(M="NETWORK",D=d<P):le?(M="SERVER",D=d<P):ce&&(M="VALIDATION",D=!1)}m(c),h(M),k(D),i(0),_(d)}finally{p(!1)}},[U]),ae=u.useCallback(async l=>{await I(l,1)},[I]),oe=u.useCallback(()=>{const l=S(),d=N+1;I(l,d)},[N,S,I]),z=()=>{o||(r(null),i(0),m(null),h(null),k(!1),_(0),v(!1),J(),s())},ne=()=>{r(null),m(null),v(!1),i(0),A("file",null)};return e.jsx(we,{open:a,onClose:z,title:"Uploader un fichier audio",size:"lg",children:e.jsxs("form",{id:"upload-track-form",onSubmit:ee(ae,l=>{Ne.warn("Form validation errors:",{errors:l})}),children:[e.jsx(ye,{children:e.jsxs("div",{className:"space-y-6",children:[t?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-3",children:[e.jsx(K,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium","data-testid":"upload-file-name",children:t.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[(t.size/1024/1024).toFixed(2)," MB"]})]})]}),!o&&e.jsx(L,{type:"button",variant:"ghost",size:"icon",onClick:ne,className:"h-8 w-8",children:e.jsx(W,{className:"h-4 w-4"})})]})}):e.jsxs("div",{...re(),className:`
|
|
border-2 border-dashed rounded-lg p-12 text-center cursor-pointer
|
|
transition-colors
|
|
${q?"border-primary bg-primary/5":"border-muted-foreground/25"}
|
|
hover:border-primary hover:bg-primary/5
|
|
`,children:[e.jsx("input",{...te()}),e.jsx(K,{className:"mx-auto h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"text-lg font-medium mb-2",children:q?"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)"})]}),o&&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:[n,"%"]})]}),e.jsx(Q,{value:n})]}),g&&e.jsx(B,{variant:"destructive","data-testid":"upload-error",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Y,{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:g}),x&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Code d'erreur: ",x]}),N>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Tentative ",N,"/",P]})]}),H&&e.jsxs(L,{type:"button",variant:"outline",size:"sm",onClick:oe,disabled:o,className:"mt-2",children:[e.jsx(je,{className:"h-4 w-4 mr-2"}),"Réessayer"]})]})]})}),E&&e.jsxs(B,{className:"bg-green-50 border-green-200 text-green-800",children:[e.jsx(be,{className:"h-4 w-4"}),e.jsx("span",{children:"Fichier uploadé avec succès !"})]}),t&&!o&&!E&&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(R,{htmlFor:"title",children:"Titre *"}),e.jsx(F,{id:"title",...T("title"),placeholder:"Titre du morceau"}),$.title&&e.jsx("p",{className:"text-sm text-destructive",children:$.title.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"artist",children:"Artiste"}),e.jsx(F,{id:"artist",...T("artist"),placeholder:"Nom de l'artiste"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"album",children:"Album"}),e.jsx(F,{id:"album",...T("album"),placeholder:"Nom de l'album"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"genre",children:"Genre"}),e.jsx(F,{id:"genre",...T("genre"),placeholder:"Genre musical"})]})]})]})]})}),e.jsxs(ve,{children:[e.jsx(L,{variant:"outline",onClick:z,disabled:o,type:"button",children:E?"Fermer":"Annuler"}),!E&&e.jsxs(L,{type:"submit",form:"upload-track-form",disabled:!t||o,className:"gap-2",children:[e.jsx(ke,{className:"h-4 w-4"}),o?"Upload en cours...":"Uploader"]})]})]})})}export{B as A,Q as P,w as T,Ve as U,_e as a,Ue as b,Ae as c,Fe as d,Oe as e,Re as g,Le as u};
|
|
//# sourceMappingURL=chunk-pW9FG0iV.js.map
|