mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 13:25:18 +00:00
fix: export tx more logs
This commit is contained in:
@@ -38,6 +38,9 @@ export async function GET(request: Request) {
|
||||
// Process transactions in chunks to avoid memory issues
|
||||
for (let i = 0; i < transactions.length; i += TRANSACTIONS_CHUNK_SIZE) {
|
||||
const chunk = transactions.slice(i, i + TRANSACTIONS_CHUNK_SIZE)
|
||||
console.log(
|
||||
`Processing transactions ${i + 1}-${Math.min(i + TRANSACTIONS_CHUNK_SIZE, transactions.length)} of ${transactions.length}`
|
||||
)
|
||||
|
||||
for (const transaction of chunk) {
|
||||
const row: Record<string, unknown> = {}
|
||||
@@ -90,8 +93,22 @@ export async function GET(request: Request) {
|
||||
throw new Error("Failed to create zip folder")
|
||||
}
|
||||
|
||||
let totalFilesProcessed = 0
|
||||
let totalFilesToProcess = 0
|
||||
|
||||
// First count total files to process
|
||||
for (const transaction of transactions) {
|
||||
const transactionFiles = await getFilesByTransactionId(transaction.id, user.id)
|
||||
totalFilesToProcess += transactionFiles.length
|
||||
}
|
||||
|
||||
console.log(`Starting to process ${totalFilesToProcess} files in total`)
|
||||
|
||||
for (let i = 0; i < transactions.length; i += FILES_CHUNK_SIZE) {
|
||||
const chunk = transactions.slice(i, i + FILES_CHUNK_SIZE)
|
||||
console.log(
|
||||
`Processing files for transactions ${i + 1}-${Math.min(i + FILES_CHUNK_SIZE, transactions.length)} of ${transactions.length}`
|
||||
)
|
||||
|
||||
for (const transaction of chunk) {
|
||||
const transactionFiles = await getFilesByTransactionId(transaction.id, user.id)
|
||||
@@ -108,6 +125,9 @@ export async function GET(request: Request) {
|
||||
for (const file of transactionFiles) {
|
||||
const fullFilePath = fullPathForFile(user, file)
|
||||
if (await fileExists(fullFilePath)) {
|
||||
console.log(
|
||||
`Processing file ${++totalFilesProcessed}/${totalFilesToProcess}: ${file.filename} for transaction ${transaction.id}`
|
||||
)
|
||||
const fileData = await fs.readFile(fullFilePath)
|
||||
const fileExtension = path.extname(fullFilePath)
|
||||
transactionFolder.file(
|
||||
@@ -116,11 +136,15 @@ export async function GET(request: Request) {
|
||||
}${fileExtension}`,
|
||||
fileData
|
||||
)
|
||||
} else {
|
||||
console.log(`Skipping missing file: ${file.filename} for transaction ${transaction.id}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Finished processing all ${totalFilesProcessed} files`)
|
||||
|
||||
// Generate zip with progress tracking
|
||||
const zipContent = await zip.generateAsync({
|
||||
type: "uint8array",
|
||||
|
||||
Reference in New Issue
Block a user