0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-31 00:03:21 +00:00

Add retryconfig and forward user ip

This commit is contained in:
Trevor Buckner
2024-09-30 08:31:39 -04:00
parent 40925253bd
commit e9c45b216c
2 changed files with 18 additions and 6 deletions

View File

@@ -25,6 +25,15 @@ if(!config.get('service_account')){
const defaultAuth = serviceAuth || config.get('google_api_key');
const retryConfig = {
retry: 3, // Number of retry attempts
retryDelay: 100, // Initial delay in milliseconds
retryDelayMultiplier: 2, // Multiplier for exponential backoff
maxRetryDelay: 32000, // Maximum delay in milliseconds
httpMethodsToRetry: ['PATCH'], // Only retry PATCH requests
statusCodesToRetry: [[429, 429]], // Only retry on 429 status code
};
const GoogleActions = {
authCheck : (account, res, updateTokens=true)=>{
@@ -147,9 +156,8 @@ const GoogleActions = {
return brews;
},
updateGoogleBrew : async (brew, auth = defaultAuth)=>{
updateGoogleBrew : async (brew, auth = defaultAuth, userIp)=>{
const drive = googleDrive.drive({ version: 'v3', auth: auth });
console.log(auth == defaultAuth ? 'UPDATE w SERVICEACC' : 'UPDATE w USERACC')
await drive.files.update({
@@ -170,7 +178,11 @@ const GoogleActions = {
media : {
mimeType : 'text/plain',
body : brew.text
}
},
headers: {
'X-Forwarded-For': userIp, // Set the X-Forwarded-For header
},
retryConfig
})
.catch((err)=>{
console.log('Error saving to google');