diff --git a/src/pages/Report.jsx b/src/pages/Report.jsx index c97151e..f3b30c0 100644 --- a/src/pages/Report.jsx +++ b/src/pages/Report.jsx @@ -37,11 +37,6 @@ const imgPaths = { '.las': '/images/las.png' } -const contentTypes = { - '.pdf': 'application/pdf', - '.las': 'application/octet-stream' -} - // Экспорт рендера export default function Report(props) { @@ -85,8 +80,8 @@ export default function Report(props) {
{ progressData.operation }
- getReportFile(event, progressData.reportName)} - download> + {getReportFile(event, progressData.reportName)}} + download={progressData.reportName}> { progressData.reportName } @@ -94,17 +89,31 @@ export default function Report(props) { } const getReportFile = async (event, reportFileName) => { - try { - const element = event.target - let bytesArray = await ReportService.getReport(wellId, reportFileName) - const contentType = contentTypes[reportFileName.slice(-4)] - let reportUrl = URL.createObjectURL(new File(bytesArray, {type: contentType})) - element.href = reportUrl - } catch (error) { - notify(`Не удалось скачать отчет по скважине (${wellId}) c - ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по - ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') - console.log(error) + const element = event.target + + if(!element.href.length) { + try { + await fetch(`/api/report/${wellId}/${reportFileName}`, { + headers: { + Authorization: 'Bearer ' + localStorage['token'] + } + }) + .then(async (response) => { + const blob = await response.blob(); + + let reader = new FileReader(); + reader.readAsDataURL(blob); + reader.onload = function (e) { + element.href = e.target.result + element.click() + }; + }); + } catch (error) { + notify(`Не удалось скачать отчет по скважине (${wellId}) c + ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по + ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') + console.log(error) + } } }