Skip to content

Commit

Permalink
fix: pro download
Browse files Browse the repository at this point in the history
  • Loading branch information
AldemirLucas committed Aug 20, 2024
1 parent e6d03e0 commit 0dba9f2
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions next/pages/api/tables/downloadTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ async function downloadTable(url, datasetID, tableId, token, res) {

const prefixUrl = "https://storage.googleapis.com/"

try {
let fileUrl = ""
let fileUrl = ""

if(payloadToken?.pro_subscription_status === "active") {
fileUrl = `${prefixUrl}${urlDownloadClosed}${datasetID}/${tableId}/${tableId}_bdpro.csv.gz`
}else if(url === "free") {
fileUrl =`${prefixUrl}${urlDownloadOpen}${datasetID}/${tableId}/${tableId}.csv.gz`
}
if(payloadToken?.pro_subscription_status === "active") {
fileUrl = `${prefixUrl}${urlDownloadClosed}${datasetID}/${tableId}/${tableId}_bdpro.csv.gz`
}else if(url === "free") {
fileUrl =`${prefixUrl}${urlDownloadOpen}${datasetID}/${tableId}/${tableId}.csv.gz`
}

try {
const response = await axios({
url: fileUrl,
method: 'GET',
Expand All @@ -47,8 +47,21 @@ async function downloadTable(url, datasetID, tableId, token, res) {

response.data.pipe(res)
} catch (error) {
console.error(error)
res.status(500).json({ message: 'Error downloading the file' })
try {
const response = await axios({
url: `${prefixUrl}${urlDownloadOpen}${datasetID}/${tableId}/${tableId}.csv.gz`,
method: 'GET',
responseType: 'stream'
})

res.setHeader('Content-Disposition', `attachment; filename=${datasetID}_${tableId}.csv.gz`)
res.setHeader('Content-Type', 'application/gzip')

response.data.pipe(res)
} catch (error) {
console.error(error)
res.status(500).json({ message: 'Error downloading the file' })
}
}
}

Expand Down

0 comments on commit 0dba9f2

Please sign in to comment.