57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
import { merge as m, cloneDeep as d } from "lodash-es";
|
||
import { b as g, u as y } from "./index-50ffe046.mjs";
|
||
import p from "cos-js-sdk-v5";
|
||
import w from "dayjs";
|
||
import "vue";
|
||
import "@fast-crud/fast-crud";
|
||
function h(e) {
|
||
let n = null;
|
||
const c = e.secretId, r = e.secretKey, t = e.getAuthorization;
|
||
return !c && !r && t ? n = new p({
|
||
// 必选参数
|
||
getAuthorization(i, a) {
|
||
t(e).then((o) => {
|
||
o.ExpiredTime && typeof o.ExpiredTime == "string" && (o.ExpiredTime = w(o.ExpiredTime).unix()), a(o);
|
||
});
|
||
}
|
||
}) : (console.warn("您还未配置getAuthorization,将使用SecretKey授权进行上传"), n = new p({
|
||
SecretId: c,
|
||
SecretKey: r
|
||
})), n;
|
||
}
|
||
async function K({ file: e, fileName: n, onProgress: c, options: r }) {
|
||
const t = await g(e, n, r), i = r, a = h(i);
|
||
return new Promise((o, f) => {
|
||
a.putObject({
|
||
Bucket: i.bucket,
|
||
Region: i.region,
|
||
Key: t,
|
||
Body: e,
|
||
onProgress(u) {
|
||
const s = u;
|
||
s.total > 0 && (s.percent = Math.floor(s.loaded / s.total * 100)), c(s);
|
||
}
|
||
}, async function(u, s) {
|
||
if (u != null) {
|
||
console.error(u), f(u);
|
||
return;
|
||
}
|
||
let l = { url: i.domain + "/" + t, key: t };
|
||
if (i.successHandle) {
|
||
l = await i.successHandle(l), o(l);
|
||
return;
|
||
}
|
||
o(l);
|
||
});
|
||
});
|
||
}
|
||
async function T(e) {
|
||
const { getConfig: n } = y(), c = n("cos"), r = e.options, t = m(d(c), r);
|
||
return e.options = t, await K(e);
|
||
}
|
||
export {
|
||
h as getOssClient,
|
||
T as upload
|
||
};
|
||
//# sourceMappingURL=uploader-cos-e64b150f.mjs.map
|