Skip to content

Commit

Permalink
download edge case bug
Browse files Browse the repository at this point in the history
  • Loading branch information
asgray committed Nov 29, 2023
1 parent 901af4f commit cd4177b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions services/FamiliesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,30 @@ const readFamilies = ({...args} = {}, { format, sort, name, name_prefix, name_ac
rows = await family.familySubqueries(rows, format);
let formatted = await format_rules.mapper(total_count, rows, format, copyright=null, download)

// If large request write data to working file and rename to finished file
if (total_count > config.CACHE_CUTOFF && download && fs.existsSync(working_file)) {
if (download) {
// compress response body
let compressed = zlib.gzipSync(formatted.body);

// base64 encode body
let b64 = Buffer.from(compressed).toString('base64')
formatted.body = b64

// write object to string
let str = JSON.stringify(formatted)

//write and rename file
fs.writeFileSync(working_file, str)
fs.renameSync(working_file, cache_file)
// If large request write data to working file and rename to finished file
if (total_count > config.CACHE_CUTOFF && fs.existsSync(working_file)) {
//write and rename file
fs.writeFileSync(working_file, str)
fs.renameSync(working_file, cache_file)
// otherwise, remove placeholder working file
} else if (fs.existsSync(working_file)){
fs.unlinkSync(working_file)
}

// otherwise, remove placeholder working file
} else if (download && fs.existsSync(working_file) ){
fs.unlinkSync(working_file)
resolve(Service.successResponse(str, 200));
}

resolve(Service.successResponse(formatted, 200));

} catch (e) {
Expand Down

0 comments on commit cd4177b

Please sign in to comment.