UNPKG

@aplus-frontend/ui

Version:

63 lines (62 loc) 1.58 kB
import { message as i } from "@aplus-frontend/antdv"; import { fileMatchesAccept as g } from "./accept.mjs"; import { getOssInstance as f } from "../hook/useOss.mjs"; let o; function U(e) { o = e; } function m(e, r, a) { e.status = r, e.error = a; } function S(e, r, a) { if (a?.maxCount && a.maxCount > 1 && r.length >= a.maxCount) { const t = a?.maxCountErrorMsg || o("ap.apUpload.maxUploadFiles", { maxCount: a.maxCount }); return i.warning(t), m(e, "error", t), !1; } if (a?.maxSize && (e?.size || 0) > a?.maxSize * 1024 * 1024) { const t = a?.maxSizeErrorMsg || o("ap.apUpload.maxUploadFileSize", { maxSize: a?.maxSize }); return i.warning(t), m(e, "error", t), !1; } if (!g(e, a.accept)) { const t = a?.acceptErrorMsg || o("ap.apUpload.fileFormatNotSupported"); return i.warning(t), m(e, "error", t), !1; } return !0; } const C = async (e, r) => { const { file: a, onError: t, onProgress: u, onSuccess: l } = e; try { const n = await (await f())?.put({ dirName: r?.dirName, fileName: a?.name, data: a, progressCallBack: (s) => { u?.({ percent: s }); } }); if (n.status === 204) return; if (n.status === 200) { const { saveUrl: s } = n; l?.({ fileName: a?.name, path: s }); } else t?.(n?.message || o("ap.apUpload.networkAnomaly")); } catch (c) { t?.(c); } }; export { m as changeFileStatus, U as injectUtilUpload, S as uploadBeforeUpload, C as uploadCustomRequest };