"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@aplus-frontend/antdv"),f=require("../hook/useOss.js"),U=require("./accept.js");let s;function x(a){s=a}function u(a,r,e){a.status=r,a.error=e}function S(a,r,e){if(e?.maxCount&&e.maxCount>1&&r.length>=e.maxCount){const t=e?.maxCountErrorMsg||s("ap.apUpload.maxUploadFiles",{maxCount:e.maxCount});return i.message.warning(t),u(a,"error",t),!1}if(e?.maxSize&&(a?.size||0)>e?.maxSize*1024*1024){const t=e?.maxSizeErrorMsg||s("ap.apUpload.maxUploadFileSize",{maxSize:e?.maxSize});return i.message.warning(t),u(a,"error",t),!1}if(!U.fileMatchesAccept(a,e.accept)){const t=e?.acceptErrorMsg||s("ap.apUpload.fileFormatNotSupported");return i.message.warning(t),u(a,"error",t),!1}return!0}const p=async(a,r)=>{const{file:e,onError:t,onProgress:m,onSuccess:d}=a;try{const{oss:c,bucket:l}=await f.getOssInstance({bucket:r?.bucket}),o=await c?.put({dirName:r?.dirName,fileName:e?.name,data:e,progressCallBack:n=>{m?.({percent:n})}});if(o.status===204)return;if(o.status===200){const{saveUrl:n}=o,g=l&&n?`${l}:${n}`:n;d?.({fileName:e?.name,path:g})}else t?.(o?.message||s("ap.apUpload.networkAnomaly"))}catch(c){t?.(c)}};exports.changeFileStatus=u;exports.injectUtilUpload=x;exports.uploadBeforeUpload=S;exports.uploadCustomRequest=p;
