Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the s3 restore check #3115

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions services/api/src/resources/backup/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,36 @@ export const getRestoreLocation: ResolverFn = async (


// before generating the signed url, check the object exists
await s3Client.headObject({
let exists = false
const restoreLoc = await s3Client.headObject({
Bucket: R.prop(2, s3Parts),
Key: R.prop(3, s3Parts)
}, async function(err, data) {
if (err) {
// if there is an error, then delete the restore from the database
await query(
sqlClientPool,
Sql.deleteRestore({
backupId
})
);
return ""
} else {
// otherwise return the signed url
return s3Client.getSignedUrl('getObject', {
Bucket: R.prop(2, s3Parts),
Key: R.prop(3, s3Parts),
Expires: 300 // 5 minutes
});
}
});
try {
await Promise.all([restoreLoc.promise()]).then(data => {
// the file exists
}).catch(err => {
if (err) throw err;
});
exists = true
} catch(err) {
exists = false
}
if (exists) {
return s3Client.getSignedUrl('getObject', {
Bucket: R.prop(2, s3Parts),
Key: R.prop(3, s3Parts),
Expires: 300 // 5 minutes
});
} else {
await query(
sqlClientPool,
Sql.deleteRestore({
backupId
})
);
return ""
}
}

return restoreLocation;
Expand Down