From 3101db4d2481588676c7ccd3cd2c1c57d4ecbad5 Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:40:46 +0000 Subject: [PATCH] adds feature that removes 404 spreadsheets --- functions/index.js | 13 ++++++++++++- src/store/index.js | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/functions/index.js b/functions/index.js index 01e8150..1e75404 100644 --- a/functions/index.js +++ b/functions/index.js @@ -51,7 +51,18 @@ exports.processSheetScheduler = onSchedule( console.log(`skipping document: ${doc.id} as its hash%60 (${hashToSixty}) does not match the cron minute (${eventDate.getMinutes()})`); return; } - logger.log(`processing document ${doc.id}, its hash % 60 (${hashToSixty}) matches the cron minute (${eventDate.getMinutes()})`); + logger.log(`processing document ${doc.id}, its hash % 60 (${hashToSixty}) matches the cron minute (${eventDate.getMinutes()})`); + + // try to access the spreadsheet and delete the document if it's not found, users will delete/change auth on sheets and we don't want to keep processing them + try { + s3 = await gapi.client.sheets.spreadsheets.get({spreadsheetId: doc.id,}); + } catch (e) { + logger.log(e); + if (e.status == 404) { + await doc.ref.delete(); + logger.log(`document ${doc.id} not found, deleted`); + } + } // send POST request with sheetID to trigger sheet processing const url = "https://auto-archiver-api.bellingcat.com/sheet_service"; diff --git a/src/store/index.js b/src/store/index.js index 339059e..94226b0 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -342,7 +342,7 @@ export default new Vuex.Store({ ); const response = await getDocs(q); - if(response.docs.length > 0) { + if (response.docs.length > 0) { throw "Sheet already enabled"; }