diff --git a/server/googleActions.js b/server/googleActions.js index b042a00e6..4cba4d8ca 100644 --- a/server/googleActions.js +++ b/server/googleActions.js @@ -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'); diff --git a/server/homebrew.api.js b/server/homebrew.api.js index e1fa0e089..9546e8266 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -373,7 +373,7 @@ const api = { if(!brew.googleId) return; } else if(brew.googleId) { // If the google id exists and no other actions are being performed, update the google brew - const updated = await api.updateGoogleBrew(req.account, api.excludeGoogleProps(brew), res); + const updated = await api.updateGoogleBrew(req.account, api.excludeGoogleProps(brew), res, req); if(!updated) return; } @@ -418,12 +418,12 @@ const api = { res.status(200).send(saved); }, - updateGoogleBrew : async (account, brew, res)=>{ + updateGoogleBrew : async (account, brew, res, req)=>{ let oAuth2Client; if(account.googleId) oAuth2Client = GoogleActions.authCheck(account, res); - return await GoogleActions.updateGoogleBrew(brew, oAuth2Client); + return await GoogleActions.updateGoogleBrew(brew, oAuth2Client, req.ip); }, deleteGoogleBrew : async (account, id, editId, res)=>{