import{i as e,t}from"./client-BTeclN8X.js";var n=``,r=80*1024;function i(e){let t=e.match(/data:([^;]+);/)?.[1]||`image/jpeg`,n=e.includes(`,`)?e.split(`,`)[1]:e;return{mimeType:t,pureBase64:n,size:Math.floor(n.length*.75)}}async function a(t,n,r,i){let a=await e(`/api/v1/admin/media/upload`,{name:t,mimeType:r,base64:n,width:i?.width,height:i?.height});if(a.code!==0||!a.data)throw Error(a.msg||`图片上传失败`);return a.data}async function o(t,n,i,a,o){let s=Math.ceil(n.length/r),c=await e(`/api/v1/admin/media/init`,{name:t,mimeType:i,size:a,chunkCount:s,width:o?.width,height:o?.height});if(c.code!==0||!c.data?.id)throw Error(c.msg||`初始化分片上传失败`);let l=c.data.id;for(let t=0;t<s;t++){let i=n.slice(t*r,(t+1)*r),a=await e(`/api/v1/admin/media/chunk/${l}`,{chunkIndex:t,chunkData:i});if(a.code!==0)throw Error(a.msg||`分片 ${t+1}/${s} 上传失败`)}let u=await e(`/api/v1/admin/media/finalize/${l}`,{});if(u.code!==0||!u.data)throw Error(u.msg||`分片上传合并失败`);return{...u.data,size:a}}async function s(e,t,n){let{mimeType:s,pureBase64:c,size:l}=i(t);if(!c)throw Error(`图片数据为空`);if(!s.startsWith(`image/`))throw Error(`仅支持图片文件`);let u=s===`image/jpeg`?e.replace(/\.[^.]+$/,`.jpg`):e;return c.length<=r?a(u,c,s,n):o(u,c,s,l,n)}async function c(e){return(await t(`/api/v1/admin/media/${e}`)).code===0}function l(e){return`${n}/api/v1/media/${e}`}function u(e){return e?e.startsWith(`/api/v1/media/`)||e.startsWith(`${n}/api/v1/media/`):!1}function d(e){if(!e)return null;let t=e.match(/\/api\/v1\/media\/(\d+)/);return t?parseInt(t[1],10):null}export{s as a,u as i,d as n,l as r,c as t};