import{_ as v,cm as x,cB as E,cV as q}from"./index-dNe6i2rS.js";var R=v(function(n,e){for(var o=x(e),a=0;a<o.length;){var c=o[a];n(e[c],c,e),a+=1}return e});const M=(t=7)=>{const n=[],e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",o=e.length;for(let a=0;a<t;a+=1)n.push(e.charAt(Math.floor(Math.random()*o)));return n.join("")},B=t=>t&&t.uploadId||(t==null?void 0:t.name),_=(t,n)=>{const e=t;return e&&!e.uploadId&&(e.uploadId=`${n?`${n}::`:""}${M()}`),t},D=async(t,n={flowChunkNumber:1,beginningOfTheChunk:0,flowIdentifier:M()})=>{var C,w,z,T,I,$,y;const{file:e,projectId:o,options:a,uploadPath:c,helperForNewArr:s,name:U,uploadChunkSize:i}=t,{flowChunkNumber:u,beginningOfTheChunk:f,flowIdentifier:k}=n,d=U||e.name,b=e.size,m=e.size>f+2*i?f+i:e.size,O=e.size>i?Math.ceil(e.size/i)-1:1,h=e.size===0?1:O,P=m-f,S=e.slice(f,m),j=K({flowChunkNumber:u,flowChunkSize:i,flowCurrentChunkSize:P,flowTotalSize:b,flowIdentifier:k,flowFilename:d,flowRelativePath:d,flowTotalChunks:h,file:S}),l={name:d,path:`${c}/${d}`,id:`${c}/${d}`,uploadKey:B(e),isNewFile:!0,isUploading:!0,chunks:h};try{u===1&&(s==null||s({...l,percentage:0},a));const r=await H({data:j,projectId:o,uploadPath:c});if(r.status===200){if(u===h)return Promise.resolve({...l,isUploading:!1,percentage:100});const g=u/h*100;return s==null||s({...l,percentage:g},a),D(t,{flowChunkNumber:u+1,beginningOfTheChunk:m,flowIdentifier:k})}const p=((C=r.data)==null?void 0:C.usrMsg)||((w=r.data)==null?void 0:w.errorMsg)||`Upload failed (HTTP ${r.status})`;return s==null||s({...l,isUploading:!1,percentage:100,failed:!0,message:p}),Promise.reject(new Error(p))}catch(r){const p=(z=r.response)==null?void 0:z.status,g=((I=(T=r.response)==null?void 0:T.data)==null?void 0:I.usrMsg)||((y=($=r.response)==null?void 0:$.data)==null?void 0:y.errorMsg)||(p?`Upload failed (HTTP ${p})`:"Upload failed");return s==null||s({...l,isUploading:!1,percentage:100,failed:!0,message:g}),Promise.reject(new Error(g))}},H=({data:t,projectId:n,uploadPath:e})=>new E(`/project/${n}/dataset/upload`).request({url:encodeURIComponent(e??""),type:q.post,data:t}),K=t=>{const n=new FormData;return R((e,o)=>n.append(o,typeof e=="number"?`${e}`:e),t),n};export{B as a,D as b,_ as t,M as u};
