tav-ui
Version:
39 lines (36 loc) • 1.37 kB
JavaScript
import { useMessage } from '../../../../hooks/web/useMessage2.mjs';
import '../../../../locales/index2.mjs';
import { tavI18n } from '../../../../locales/transfer2.mjs';
const { createMessage } = useMessage();
async function fileSingleDownload(options) {
const { file, api, fileName, isWaterMarker = false } = options;
if (!file || !file.id) {
createMessage.warning(tavI18n("Tav.file.download.1"));
return;
}
const { data, success } = await api({ id: file.id });
if (success === true && data) {
const aEl = window.document.createElement("a");
aEl.setAttribute("download", fileName || (isWaterMarker ? decodeURIComponent(data.split("/").at(-1)) : file.fullName));
aEl.setAttribute("href", data);
aEl.setAttribute("target", "_blank");
aEl.click();
setTimeout(() => {
aEl.remove();
}, 5e3);
}
}
async function fileMultipleDownload(options) {
const { files, api, fileName } = options;
if (Array.isArray(files) && files.length === 0) {
createMessage.warning(tavI18n("Tav.file.download.1"));
return;
}
const ids = files.map((file) => file.id);
const { success, data } = await api({ fileName: fileName || tavI18n("Tav.file.download.2"), ids });
if (success === true && data) {
window.open(data);
}
}
export { fileMultipleDownload, fileSingleDownload };
//# sourceMappingURL=download2.mjs.map