closes #3 and fixes PR for #6

This commit is contained in:
msramalho
2024-02-06 15:13:35 +00:00
parent 8e106c49f8
commit 7c4e301d4d
3 changed files with 28 additions and 27 deletions

View File

@@ -14,6 +14,9 @@ const logger = require("firebase-functions/logger");
const { initializeApp } = require("firebase-admin/app");
const { getFirestore } = require("firebase-admin/firestore");
const { defineSecret } = require('firebase-functions/params');
const API_TOKEN = defineSecret('API_SERVICE_PASSWORD');
initializeApp();
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -34,7 +37,7 @@ String.prototype.hashCode = function () {
}
exports.processSheetScheduler = onSchedule(
"* * * * *",
{ secrets: [API_TOKEN], schedule: "* * * * *" },
async (event) => {
// get all documents from firestore sheets collection
const db = getFirestore();
@@ -52,20 +55,16 @@ exports.processSheetScheduler = onSchedule(
// send POST request with sheetID to trigger sheet processing
const url = "https://auto-archiver-api.bellingcat.com/sheet_service";
const data = {
sheet_id: doc.data().sheetId,
author_id: doc.data().email ?? doc.data().uid,
tags: ["setup-tool"]
const data = {
sheet_id: doc.data().sheetId,
author_id: doc.data().email ?? doc.data().uid,
tags: ["setup-tool"]
};
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization:
"Bearer " +
Buffer.from(
"password"
).toString("base64"),
Authorization: `Bearer ${API_TOKEN.value()}`,
},
body: JSON.stringify(data),
};