naive-upload
Version:
<p align="left"> <a href="https://www.npmjs.org/package/naive-upload"> <img src="https://img.shields.io/npm/v/naive-upload.svg"> </a> <a href="https://bundlephobia.com/package/naive-upload@latest"> <img src="https://img.shields.io/bundl
614 lines (613 loc) • 26.3 kB
JavaScript
var S = Object.defineProperty;
var m = (d, e, t) => e in d ? S(d, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : d[e] = t;
var l = (d, e, t) => (m(d, typeof e != "symbol" ? e + "" : e, t), t);
import { reactive as D, watch as b } from "vue-demi";
import h from "../Extention/UploadError.js";
import C from "../Model/RawFile.js";
import k from "../Model/SelectedFile.js";
import L from "../Extention/SimpleGuid.js";
import { FileType as E } from "../Model/FileType.js";
import p from "../Extention/FileSizeHelper.js";
import y from "../Model/ChunkFile.js";
import { RunMode as w } from "../Model/RunMode.js";
import A from "../Extention/HashHelper.js";
import $ from "../Extention/UploadHelper.js";
class F {
constructor(e, t) {
l(this, "reactive", D);
l(this, "settings");
l(this, "apiService");
l(this, "config");
l(this, "rawFileList");
l(this, "selectedFileList");
l(this, "selectedFileSortMap");
l(this, "checkQueue", []);
l(this, "checkHandlerCount", 0);
l(this, "uploadQueue", []);
l(this, "pausedQueue", /* @__PURE__ */ new Map());
l(this, "uploadHandlerCount", 0);
l(this, "tokenWithIndex", /* @__PURE__ */ new Map());
l(this, "layoutChanged", []);
l(this, "configChanged", []);
l(this, "selectedFileListChanged", []);
l(this, "selectedFileSortMapChanged", []);
l(this, "userFileInfoListChanged", []);
l(this, "alertError", []);
l(this, "beforeCheck");
l(this, "afterCheck");
l(this, "afterCheckAll");
l(this, "afterUpload");
l(this, "afterUploadAll");
l(this, "handlerError");
this.settings = this.reactive(e), this.apiService = t, this.rawFileList = this.reactive([]), this.selectedFileList = this.reactive([]), this.selectedFileSortMap = this.reactive(/* @__PURE__ */ new Map());
}
updateConfig() {
return new Promise((e, t) => {
this.apiService.config(this.settings.configCode).then((i) => {
this.config = this.reactive(i), this.settings.debug && console.debug("\u914D\u7F6E\u5DF2\u53D8\u66F4:", Object.assign({}, this.config)), e();
}).catch((i) => {
t(new h("\u66F4\u65B0\u6587\u4EF6\u4E0A\u4F20\u914D\u7F6E\u9519\u8BEF", i));
});
});
}
watchSettings() {
b(
() => this.settings.configCode,
async (e, t) => {
var i;
console.debug(666666666), e != t && (await this.updateConfig(), (i = this.configChanged) == null || i.forEach((n) => n(this.config)));
}
), b(
() => this.settings.layout,
async (e, t) => {
var i;
e != t && ((i = this.layoutChanged) == null || i.forEach((n) => n(e)));
}
), b(
() => this.selectedFileList,
async (e, t) => {
var i;
(i = this.selectedFileListChanged) == null || i.forEach((n) => n(this.getSelectedFileList(!0)));
},
{ deep: !0 }
);
}
selectedFileSortMapChangedTrigger() {
var e;
(e = this.selectedFileSortMapChanged) == null || e.forEach((t) => t(this.getSelectedFileSortMap()));
}
userFileInfoListChangedTrigger() {
var e;
(e = this.userFileInfoListChanged) == null || e.forEach((t) => t(this.getUserFileInfoList(!0)));
}
appendFile(e) {
let t = (u, s) => {
const a = L.new();
let r = new C(u);
r.name = s.name, r.extension = s.extension, r.configCode = this.config.code, r.token = a, this.rawFileList.push(r), s.rawIndex = this.rawFileList.length - 1, s.token = a, this.tokenWithIndex.set(a, this.selectedFileList.length), this.selectedFileList.push(s), this.selectedFileSortMap.set(this.selectedFileSortMap.size + 1, this.selectedFileList.length - 1), this.selectedFileSortMapChangedTrigger(), this.handleFile(this.selectedFileList.length - 1), this.settings.debug && console.debug("\u5DF2\u6DFB\u52A0\u6587\u4EF6", Object.assign({}, r));
};
if (this.selectedFileList.filter((u) => {
var s;
return !u.canceled && ((s = this.rawFileList[u.rawIndex].file) == null ? void 0 : s.name) == e.name;
}).length > 0) {
this.settings.debug && console.debug("\u91CD\u590D\u7684\u6587\u4EF6", e);
return;
}
if (this.limited()) {
this.throwError(new h(`\u5F53\u524D\u53EA\u5141\u8BB8\u4E0A\u4F20${this.getConfig().upperLimit}\u4E2A\u6587\u4EF6`));
return;
}
const i = e.name.substring(e.name.lastIndexOf("."));
if (this.config.allowedTypeList.length !== 0) {
let u = !1;
for (const s of this.config.allowedTypeList)
if (s != null && s.length > 0 && (s[0] === "." && s.toLowerCase() === i.toLowerCase() || new RegExp(s.replace("/*", "//*"), "gi").test(e.type))) {
u = !0;
break;
}
if (!u) {
console.warn(i, e.type), this.throwError(new h("\u6587\u4EF6\u7C7B\u578B\u4E0D\u5408\u6CD5"));
return;
}
}
if (this.config.prohibitedTypeList.length !== 0) {
for (const u of this.config.prohibitedTypeList)
if (u != null && u.length > 0 && (u[0] === "." && u.toLowerCase() === i.toLowerCase() || new RegExp(u.replace("/*", "//*"), "gi").test(e.type))) {
console.warn(u, i, e.type), this.throwError(new h("\u6587\u4EF6\u7C7B\u578B\u4E0D\u5408\u6CD5"));
return;
}
}
if (this.config.lowerSingleSize && this.config.lowerSingleSize > e.size) {
this.throwError(new h(`\u6587\u4EF6\u4E0D\u53EF\u5C0F\u4E8E${p.getSize(this.config.lowerSingleSize)}`));
return;
}
if (this.config.upperSingleSize && this.config.upperSingleSize < e.size) {
this.throwError(new h(`\u6587\u4EF6\u4E0D\u53EF\u5927\u4E8E${p.getSize(this.config.upperSingleSize)}`));
return;
}
if (this.config.upperTotalSize && this.config.upperTotalSize < this.totalSize() + e.size) {
this.throwError(new h(`\u6240\u6709\u6587\u4EF6\u7684\u603B\u5927\u5C0F\u4E0D\u53EF\u5927\u4E8E${p.getSize(this.config.upperTotalSize)}`));
return;
}
let n = new k(e);
if (this.beforeCheck) {
const u = this.beforeCheck(e);
u && u.then && u.then((s) => {
s && t(e, n);
});
} else
t(e, n);
}
appendUploadedFile(e) {
return new Promise(async (t, i) => {
let n;
try {
n = await this.apiService.getUserFile(e);
const u = L.new();
let s = new C(null);
s.size = parseInt(n.bytes), s.name = n.name, s.extension = n.extension, s.configCode = this.config.code, s.echo = !0, s.token = u, s.userFileInfo = n, s.objectURL = this.apiService.getUserFileBrowseUrl(n.id), this.rawFileList.push(s);
let a = { name: `${n.name}${n.extension}` }, r = new k(a);
r.rawIndex = this.rawFileList.length - 1, r.echo = !0, r.checked = !0, r.uploaded = !0, r.done = !0, r.canceled = !1, r.thumbnail = this.apiService.getUserFilePreviewUrl(n.id, 100, 100), r.fileType = n.fileType, r.size = n.size, r.token = u, this.tokenWithIndex.set(u, this.selectedFileList.length), this.selectedFileList.push(r), this.selectedFileSortMap.set(this.selectedFileSortMap.size + 1, this.selectedFileList.length - 1), this.selectedFileSortMapChangedTrigger(), this.settings.debug && console.debug("\u5DF2\u6DFB\u52A0\u5386\u53F2\u6587\u4EF6", e, Object.assign({}, s), Object.assign({}, r)), t();
} catch (u) {
i(new h("\u83B7\u53D6\u7528\u6237\u6587\u4EF6\u4FE1\u606F\u5931\u8D25", u));
}
});
}
getFileType(e) {
return new Promise(async (t) => {
let i;
e.rawIndex == -1 ? i = {
file: { type: null }
} : i = this.getRawFile(e);
try {
e.fileType = i.file.type === null || i.file.type === "" || i.file.type === "application/octet-stream" ? await this.apiService.getFileTypeByExtension(e.extensionLower) : await this.apiService.getFileTypeByMIME(i.file.type);
} catch {
e.fileType = E.\u672A\u77E5;
}
t();
});
}
checkImage(e) {
if (e.fileType === E.\u672A\u77E5) {
e.thumbnail = this.apiService.getUnknowFileTypeImageUrl();
return;
}
if (e.fileType !== E.\u56FE\u7247)
return;
const t = this.getRawFile(e).objectURL;
t && (e.thumbnail = t);
}
getRawFile(e) {
return this.rawFileList[e.rawIndex];
}
getChunks(e) {
let t = this.getRawFile(e);
if (t.size > this.settings.chunkSize)
t.needSection = !0, t.specs = this.settings.chunkSize;
else
return;
let i = 0;
for (; i < t.size; )
t.chunkIndexQueue.push(t.chunks.length), t.chunks.push(new y(t.chunks.length, t.file.slice(i, i + this.settings.chunkSize))), i += this.settings.chunkSize;
this.settings.debug && console.debug("\u6587\u4EF6\u5DF2\u5207\u7247\u5904\u7406", Object.assign({}, t));
}
handleFile(e) {
const t = this.selectedFileList[e];
t.thumbnail = this.apiService.getFileTypeImageUrl(t.extensionLower), this.getFileType(t).then(() => {
this.checkImage(t);
}), t.size = p.getSize(this.getRawFile(t).size), this.settings.enableChunk && this.getChunks(t), this.pushToCheckQueue(e);
}
pushToCheckQueue(e) {
this.checkQueue.push(e), (this.settings.runMode === w.\u5168\u81EA\u52A8 || this.settings.runMode === w.\u534A\u81EA\u52A8) && this.checkMD5();
}
pushToUploadQueue(e) {
this.uploadQueue.push(e), this.settings.runMode == w.\u5168\u81EA\u52A8 && this.upload();
}
async checkMD5() {
if (this.checkHandlerCount >= this.settings.concurrentFile || this.checkQueue.length === 0) {
this.checkQueue.length != 0 && this.settings.debug && console.debug(`NaiveUpload \u6587\u4EF6\u6821\u9A8C \u5DF2\u8FBE\u5230\u6700\u5927\u5E76\u53D1\u6570\uFF1A${this.settings.concurrentFile}\uFF0C\u5F53\u524D\u961F\u5217\u957F\u5EA6\uFF1A${this.checkQueue.length}`), this.checkHandlerCount == 0 && this.checkQueue.length === 0 && this.afterCheckAll && this.afterCheckAll && await this.afterCheckAll(this.rawFileList);
return;
}
this.checkHandlerCount++;
const e = () => {
if (this.checkHandlerCount--, this.afterCheck) {
const o = this.afterCheck(a);
if (o && o.then) {
o.then(() => {
this.checkMD5();
});
return;
}
}
this.settings.debug && console.debug("\u6821\u9A8C\u4E0B\u4E00\u4E2A\u6587\u4EF6"), this.checkMD5();
}, t = (o) => {
this.pausedQueue.has(u) ? this.pausedQueue.get(u).continue = !1 : this.pausedQueue.set(u, { step: 0, helper: o }), o && o.pause(), o && this.settings.debug && console.debug("HashHelper Instance \u5DF2\u6682\u505C", Object.assign({}, r)), s.virtualPercentBeforPaused = s.virtualPercent, s.percentBeforPaused = s.percent, this.settings.debug && console.debug("\u6682\u505C\u6821\u9A8C\u6587\u4EF6", Object.assign({}, a)), e();
}, i = async (o) => {
await o.continue(), this.settings.debug && console.debug("HashHelper Instance \u5DF2\u6062\u590D", Object.assign({}, r)), this.settings.debug && console.debug("\u6062\u590D\u6821\u9A8C\u6587\u4EF6", Object.assign({}, a));
}, n = (o) => {
o && o.cancel(), o && this.settings.debug && console.debug("HashHelper Instance \u5DF2\u53D6\u6D88", Object.assign({}, r)), this.settings.debug && console.debug("\u53D6\u6D88\u6821\u9A8C\u6587\u4EF6", Object.assign({}, a)), e();
}, u = this.checkQueue.shift(), s = this.selectedFileList[u], a = this.getRawFile(s);
if (s.canceled) {
n();
return;
}
if (s.paused) {
t(), e();
return;
}
s.checking = !0;
let r = null;
if (this.pausedQueue.has(u) && (r = this.pausedQueue.get(u).helper, this.pausedQueue.delete(u), r)) {
this.settings.debug && console.debug("HashHelper Instance \u5DF2\u83B7\u53D6\uFF08\u6682\u505C\u524D\u7684\u5B9E\u4F8B\uFF09", Object.assign({}, r)), await i(r);
return;
}
r == null && (r = await A.getInstance(this.settings.concurrentChunkFile, this.settings.enableWorker, this.settings.debug), this.settings.debug && console.debug("HashHelper Instance \u5DF2\u521B\u5EFA", Object.assign({}, r)));
const f = () => {
r.close(), this.settings.debug && console.debug("HashHelper Instance \u5DF2\u5173\u95ED", Object.assign({}, r));
};
try {
if (this.settings.debug && console.debug("\u5F00\u59CB\u6821\u9A8C\u6587\u4EF6", Object.assign({}, a)), await r.handler(a, (o) => {
F.calcPercent(s, o), s.canceled && n(), s.paused && t(r);
}), s.canceled)
return;
s.virtualPercent = 100, s.percent = 100, s.checking = !1, s.checked = !0, this.settings.debug && console.debug("\u6587\u4EF6\u6821\u9A8C\u7ED3\u675F", Object.assign({}, a)), this.pushToUploadQueue(u);
} catch (o) {
const c = new h("\u6587\u4EF6\u6821\u9A8C\u5931\u8D25.", o);
this.checkError(u, `${c.message} ${o.message}`, !0, c);
}
f(), e();
}
async upload() {
var o;
if (this.config.lowerTotalSize && this.config.lowerTotalSize > this.totalSize()) {
this.throwError(new h(`\u6240\u6709\u6587\u4EF6\u7684\u603B\u5927\u5C0F\u4E0D\u53EF\u5C0F\u4E8E${p.getSize(this.config.lowerTotalSize)}`));
return;
}
if (this.uploadHandlerCount >= this.settings.concurrentFile) {
this.settings.debug && console.debug(`NaiveUpload \u6587\u4EF6\u4E0A\u4F20 \u5DF2\u8FBE\u5230\u6700\u5927\u5E76\u53D1\u6570\uFF1A${this.settings.concurrentFile}\uFF0C\u5F53\u524D\u961F\u5217\u957F\u5EA6\uFF1A${this.uploadQueue.length}`);
return;
}
if (this.uploadQueue.length === 0) {
this.checkHandlerCount === 0 && this.uploadHandlerCount === 0 && this.afterUploadAll && this.afterUploadAll(this.getRawFileList(!0));
return;
}
this.uploadHandlerCount++;
const e = (c) => {
if (this.uploadHandlerCount--, c && this.afterUpload) {
const g = this.afterUpload(a);
g && g.then && g.then(() => {
this.upload();
});
}
this.settings.debug && console.debug("\u4E0A\u4F20\u4E0B\u4E00\u4E2A\u6587\u4EF6"), this.upload();
}, t = (c) => {
this.pausedQueue.has(u) ? this.pausedQueue.get(u).continue = !1 : this.pausedQueue.set(u, { step: 1, helper: c }), c && c.pause(), c && this.settings.debug && console.debug("UploadHelper Instance \u5DF2\u6682\u505C", Object.assign({}, r)), s.virtualPercentBeforPaused = s.virtualPercent, s.percentBeforPaused = s.percent, this.settings.debug && console.debug("\u6682\u505C\u4E0A\u4F20\u6587\u4EF6", Object.assign({}, a)), e(!1);
}, i = async (c) => {
await c.continue(), this.settings.debug && console.debug("UploadHelper Instance \u5DF2\u6062\u590D", Object.assign({}, r)), this.settings.debug && console.debug("\u6062\u590D\u4E0A\u4F20\u6587\u4EF6", Object.assign({}, a));
}, n = (c) => {
c && c.cancel(), c && this.settings.debug && console.debug("UploadHelper Instance \u5DF2\u53D6\u6D88", Object.assign({}, r)), this.settings.debug && console.debug("\u53D6\u6D88\u4E0A\u4F20\u6587\u4EF6", Object.assign({}, a)), e(!1);
}, u = this.uploadQueue.shift(), s = this.selectedFileList[u], a = this.getRawFile(s);
if (s.canceled) {
n();
return;
}
if (s.paused) {
t();
return;
}
s.uploading = !0, s.virtualPercent = 0, s.percent = 0;
let r = null;
if (this.pausedQueue.has(u) && (r = this.pausedQueue.get(u).helper, this.pausedQueue.delete(u), r)) {
this.settings.debug && console.debug("UploadHelper Instance \u5DF2\u83B7\u53D6\uFF08\u6682\u505C\u524D\u7684\u5B9E\u4F8B\uFF09", Object.assign({}, r)), await i(r);
return;
}
r == null && (r = await $.getInstance(this.settings.concurrentChunkFile, this.settings.enableWorker, this.apiService, this.settings.debug), this.settings.debug && console.debug("UploadHelper Instance \u5DF2\u521B\u5EFA", Object.assign({}, r)));
const f = () => {
r.close(), this.settings.debug && console.debug("UploadHelper Instance \u5DF2\u5173\u95ED", Object.assign({}, r));
};
try {
if (this.settings.debug && console.debug("\u5F00\u59CB\u4E0A\u4F20\u6587\u4EF6", Object.assign({}, a)), await r.handler(a, (c) => {
F.calcPercent(s, c), s.canceled && n(), s.paused && this.rawFileList[s.rawIndex].needSection && t(r);
}), s.canceled)
return;
s.name = a.userFileInfo.name, s.extension = a.userFileInfo.extension, s.extensionLower = (o = a.userFileInfo.extension) == null ? void 0 : o.toLowerCase(), s.size = a.userFileInfo.size, s.fileType = a.userFileInfo.fileType, s.virtualPercent = 100, s.percent = 100, s.uploading = !1, s.uploaded = !0, s.done = !0, this.settings.debug && console.debug("\u6587\u4EF6\u4E0A\u4F20\u7ED3\u675F", Object.assign({}, a)), this.checkImage(s), this.userFileInfoListChangedTrigger();
} catch (c) {
const g = new h("\u6587\u4EF6\u4E0A\u4F20\u5931\u8D25.", c);
this.uploadError(u, `${g.message} ${c.message}`, !0, g);
}
f(), e(!0);
}
static calcPercent(e, t) {
const i = parseFloat((t.preLoaded / t.total * 100).toFixed(2)), n = parseFloat((t.loaded / t.total * 100).toFixed(2));
e.virtualPercentBeforPaused < i && (e.virtualPercent = i), e.percentBeforPaused < n && (e.percent = n);
}
throwError(e) {
this.settings.debug && console.debug("\u53D1\u751F\u5F02\u5E38", e), this.alertError.forEach((t) => t(e)), this.handlerError && this.handlerError(e);
}
error(e, t, i, n) {
const u = this.selectedFileList[e];
if (!i || u.reTry - 1 >= this.settings.retry) {
u.error = !0, u.errorMessage = t;
return;
}
u.reTry++, setTimeout(() => {
n && n(e);
}, 1500);
}
checkError(e, t, i, n) {
n && h.consoleWrite(n);
const u = this.selectedFileList[e];
u.checking = !1, u.uploading = !1, this.error(e, t, i, (s) => {
this.pushToCheckQueue(s);
});
}
uploadError(e, t, i, n) {
n && h.consoleWrite(n);
const u = this.selectedFileList[e];
u.uploading = !1, this.error(e, t, i, (s) => {
this.pushToUploadQueue(s);
});
}
async renameByIndex(e, t) {
return new Promise((i) => {
let n = this.getRawFile(e);
const u = (s) => {
s && (e.name = t, n.name = e.name, e.uploaded && (n.userFileInfo.name = e.name)), i();
};
e.uploaded ? this.apiService.rename(n.userFileInfo.id, t).then(() => {
u(!0);
}).catch((s) => {
this.handlerError && this.handlerError(new h(`\u6587\u4EF6\u91CD\u547D\u540D\u5931\u8D25\uFF1A${s.message}`, s)), u(!1);
}) : u(!0);
});
}
continueByIndex(e) {
if (this.selectedFileList[e].paused = !1, !this.pausedQueue.has(e) || this.pausedQueue.get(e).continue)
return;
const t = this.pausedQueue.get(e);
switch (t.step) {
case 0:
this.checkQueue.push(e);
break;
case 1:
this.uploadQueue.push(e);
break;
default:
return;
}
t.continue = !0;
}
static async getInstance(e, t) {
return new Promise(async (i, n) => {
try {
let u = new F(e, t);
u.watchSettings(), await u.updateConfig(), i(u);
} catch (u) {
n(new h("\u83B7\u53D6\u4E0A\u4F20\u5DE5\u5177\u5B9E\u4F8B\u65F6\u53D1\u751F\u5F02\u5E38", u));
}
});
}
getSettings() {
return this.settings;
}
getConfig() {
return this.config;
}
checkNow() {
this.checkMD5();
}
uploadNow() {
this.upload();
}
pause(e) {
if (e) {
const t = this.tokenWithIndex.get(e);
if (t == -1)
return;
this.selectedFileList[t].done || (this.selectedFileList[t].paused = !0);
} else
for (let t of this.selectedFileList)
t.done || (t.paused = !0);
}
continue(e) {
if (e) {
const t = this.tokenWithIndex.get(e);
if (t == -1)
return;
this.continueByIndex(t);
} else
for (let t = 0; t < this.selectedFileList.length; t++)
this.continueByIndex(t);
this.checkNow(), this.uploadNow();
}
remove(e) {
const t = this.tokenWithIndex.get(e);
t != -1 && (this.selectedFileList[t].canceled = !0, this.userFileInfoListChangedTrigger());
}
clean() {
for (let e of this.selectedFileList)
e.canceled = !0;
}
reset() {
this.checkQueue.length = 0, this.uploadQueue.length = 0, this.rawFileList.length = 0, this.selectedFileList.length = 0, this.tokenWithIndex.clear();
}
getOpenApi() {
return {
startCheck: () => {
for (let e = 0; e < this.settings.concurrentFile; e++)
this.checkNow();
},
startUpload: () => {
for (let e = 0; e < this.settings.concurrentFile; e++)
this.uploadNow();
},
pause: (e) => {
this.pause(e);
},
continue: (e) => {
this.continue(e);
},
remove: (e) => {
this.remove(e);
},
clean: () => {
this.clean();
},
finished: () => this.checkQueue.length === 0 && this.uploadQueue.length === 0 && this.pausedQueue.size === 0,
getUserFileInfoList: () => this.getUserFileInfoList(!0)
};
}
async rename(e, t) {
const i = this.tokenWithIndex.get(e);
if (i == -1)
throw new h("\u6587\u4EF6\u5DF2\u88AB\u79FB\u9664");
let n = this.selectedFileList[i];
return this.renameByIndex(n, t);
}
getDownloadUrl(e) {
var i;
const t = this.rawFileList[e.rawIndex];
return t.file ? (i = t.objectURL) != null ? i : null : this.apiService.getDownloadUrl(t.userFileInfo.id, e.name);
}
anyFile() {
return this.selectedFileList.filter((e) => !e.canceled).length !== 0;
}
getSelectFileAlarmInfo() {
return this.config.upperLimit ? this.selectedFileList.length < this.config.upperLimit ? `\u8FD8\u53EF\u6DFB\u52A0\u4E2A${this.config.upperLimit - this.selectedFileList.length}\u6587\u4EF6` : "\u6587\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650" : "";
}
getSelectCLass() {
return this.limited() ? "item-limited" : "";
}
getAllowedTypes() {
return this.config.allowedTypeList.join(", ");
}
limited() {
return !!this.config.upperLimit && this.selectedFileList.filter((e) => !e.canceled).length >= this.config.upperLimit;
}
totalSize() {
let e = 0;
for (const t of this.selectedFileList)
t.canceled || (e += this.rawFileList[t.rawIndex].size);
return e;
}
append(e) {
this.appendFile(e);
}
async appendById(e) {
return this.appendUploadedFile(e);
}
changeSort(e, t) {
if (e == t)
return;
const i = this.selectedFileSortMap.get(e);
if (e > t)
for (let n = e; n > t; n--)
setInterval(() => {
}, 100), this.selectedFileSortMap.set(n, this.selectedFileSortMap.get(n - 1));
else
for (let n = e; n < t; n++)
this.selectedFileSortMap.set(n, this.selectedFileSortMap.get(n + 1));
this.selectedFileSortMap.set(t, i), this.selectedFileSortMapChangedTrigger();
}
registerLayoutChanged(e) {
this.layoutChanged.push(e);
}
registerConfigChanged(e) {
this.configChanged.push(e);
}
registerSelectedFileListChanged(e) {
this.selectedFileListChanged.push(e);
}
registerSelectedFileSortMapChanged(e) {
this.selectedFileSortMapChanged.push(e);
}
registerUserFileInfoListChanged(e) {
this.userFileInfoListChanged.push(e);
}
registerAlertError(e) {
this.alertError.push(e);
}
setupBeforeCheck(e) {
this.beforeCheck = e;
}
setupAfterCheck(e) {
this.afterCheck = e;
}
setupAfterCheckAll(e) {
this.afterCheckAll = e;
}
setupAfterUpload(e) {
this.afterUpload = e;
}
setupAfterUploadAll(e) {
this.afterUploadAll = e;
}
setupHandlerError(e) {
this.handlerError = e;
}
getSelectedFileCount() {
return this.selectedFileList.filter((e) => !e.canceled).length;
}
getSelectedFileSortMap() {
return this.selectedFileSortMap;
}
getSelectedFileList(e) {
if (!e)
return this.selectedFileList.filter((i) => !i.canceled);
const t = [];
for (let i = 1; i <= this.selectedFileSortMap.size; i++) {
const n = this.selectedFileList[this.selectedFileSortMap.get(i)];
n.canceled || t.push(n);
}
return t;
}
getRawFileList(e) {
return this.getSelectedFileList(e).map((t) => this.rawFileList[t.rawIndex]);
}
getUserFileInfoList(e) {
return this.getRawFileList(e).filter((t) => t.userFileInfo).map((t) => t.userFileInfo);
}
getSelectedFile(e) {
return this.selectedFileList[this.selectedFileSortMap.get(e)];
}
getGradientStyle(e, t, i, n) {
switch (e) {
default:
case "conic":
return `
background: conic-gradient(${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%;
background: -moz-conic-gradient(${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%;
background: -o-conic-gradient(${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%;
background: -webkit-conic-gradient(${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%;`;
case "linear":
return `
background: linear-gradient(to right, ${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%;
background: -moz-linear-gradient(to right, ${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%;
background: -o-linear-gradient(to right, ${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%;
background: -webkit-linear-gradient(to right, ${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%;`;
}
}
getGradientStyleObject(e, t, i, n) {
switch (e) {
default:
case "conic":
return [
{ background: `conic-gradient(${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%` },
{ background: `-moz-conic-gradient(${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%` },
{ background: `-o-conic-gradient(${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%` },
{ background: `-webkit-conic-gradient(${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%` }
];
case "linear":
return [
{ background: `linear-gradient(to right, ${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%` },
{ background: `-moz-linear-gradient(to right, ${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%` },
{ background: `-o-linear-gradient(to right, ${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%` },
{ background: `-webkit-linear-gradient(to right, ${t} ${i}%, transparent ${n}%) repeat scroll 0% 0%` }
];
}
}
}
export {
F as default
};
//# sourceMappingURL=NaiveUpload.js.map