UNPKG

tav-ui

Version:
44 lines (39 loc) 1.53 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var useMessage = require('../../../../hooks/web/useMessage2.js'); require('../../../../locales/index2.js'); var transfer = require('../../../../locales/transfer2.js'); const { createMessage } = useMessage.useMessage(); async function fileSingleDownload(options) { const { file, api, fileName, isWaterMarker = false } = options; if (!file || !file.id) { createMessage.warning(transfer.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(transfer.tavI18n("Tav.file.download.1")); return; } const ids = files.map((file) => file.id); const { success, data } = await api({ fileName: fileName || transfer.tavI18n("Tav.file.download.2"), ids }); if (success === true && data) { window.open(data); } } exports.fileMultipleDownload = fileMultipleDownload; exports.fileSingleDownload = fileSingleDownload; //# sourceMappingURL=download2.js.map