Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Fix: Download Legacy Report v2 (#2835)
Browse files Browse the repository at this point in the history
* Fix: Download Legacy Report v2

* Fix: Download Legacy Report v2

* Fix: Download Legacy Report v2

* Fix: Download Legacy Report v2
  • Loading branch information
Ricargame authored Oct 18, 2024
1 parent bfdef1c commit eb6afbc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/api/ADempiere/file-management/resource-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function requestDeleteResources({

export function requestShareResources({
fileName,
seconds
seconds = 3600
}) {
return request({
url: `/resources/download-url/${fileName}`,
Expand Down
28 changes: 17 additions & 11 deletions src/store/modules/ADempiere/reportManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ import { showMessage, showNotification } from '@/utils/ADempiere/notification.js
import {
containerManager
} from '@/utils/ADempiere/dictionary/report.js'
import {
requestShareResources
} from '@/api/ADempiere/file-management/resource-reference.ts'

const initState = {
printFormatsList: {},
Expand Down Expand Up @@ -963,33 +966,36 @@ const reportManager = {
isDownload
}) {
return new Promise(resolve => {
const { url, file_name, mime_type } = reportOutput
const { url, file_name, mime_type, table_name, id } = reportOutput
requestPresignedUrl({
clientId: rootGetters['user/getRole'].uuid,
containerType: 'resource',
fileName: reportOutput.file_name,
tableName: reportOutput.table_name,
fileName: file_name,
tableName: table_name,
containerId: containerUuid,
recordId: reportOutput.id
recordId: id
})
.then(response => {
fetch(url)
.then(responseBlob => responseBlob.blob())
.then(blob => {
const file = new File([blob], file_name, { type: mime_type })
const fileUrl = URL.createObjectURL(file)
fetch(response.url, {
method: 'PUT',
body: file
})
if (!isEmptyValue(response.file_name)) {
if (isDownload) {
const fileLink = document.createElement('a')
fileLink.href = fileUrl
fileLink.download = reportName
document.body.appendChild(fileLink)
fileLink.click()
document.body.removeChild(fileLink)
requestShareResources({
fileName: response.file_name
})
.then(data => {
const file = document.createElement('a')
file.href = data
file.download = `${reportName}`
file.target = '_blank'
file.click()
})
}
resolve(response.file_name)
}
Expand Down

0 comments on commit eb6afbc

Please sign in to comment.