v1.6.0/release

-user clean up webhook
-ig promo asset
This commit is contained in:
2020-08-09 14:36:08 -04:00
parent 2ccce0278b
commit 71219aa7b4
4 changed files with 358 additions and 566 deletions
+60
View File
@@ -0,0 +1,60 @@
const admin = require("firebase-admin");
const secret = require("../FirebaseSecret.json");
const FIREBASE_OPTIONS = {
credential: admin.credential.cert(secret),
databaseURL: "https://watch-party-crx.firebaseio.com",
};
admin.initializeApp(FIREBASE_OPTIONS);
const timeDiff = (ds1, ds2) => {
const d1 = new Date(ds1);
const d2 = new Date(ds2);
var diff = (d2.getTime() - d1.getTime()) / 1000;
diff /= 60 * 60;
return Math.abs(Math.round(diff));
};
const cleanUser = async (pT, sT) => {
var usersToDelete = [];
await admin
.auth()
.listUsers(1000, pT)
.then((listUsersResult) => {
listUsersResult.users.forEach((userRecord) => {
if (timeDiff(userRecord.metadata.lastSignInTime, sT) >= 24 * 7) {
usersToDelete.push(userRecord.uid);
}
});
if (listUsersResult.pageToken) {
usersToDelete.push(...listAllUsers(listUsersResult.pageToken, sT));
}
return;
})
.catch((error) => {
console.log("Error listing users:", error);
});
return usersToDelete;
};
module.exports = async (req, res) => {
console.info(`[START]\tWEBHOOKS/User Clean Up`);
res.status(200).send({ message: "User Clean Up Started" });
const startedTime = new Date();
const usersToDelete = await cleanUser(undefined, startedTime);
console.info(
`[PROGRESS]\tWEBHOOKS/User Clean Up\t# OF USERS ${usersToDelete.length}`
);
admin
.auth()
.deleteUsers(usersToDelete)
.catch((err) =>
console.error(
`[ERROR]\tWEBHOOKS/User Clean Up\t# OF USERS ${usersToDelete.length},\tERROR:${err}`
)
);
console.info(
`[DONE]\tWEBHOOKS/User Clean Up\t# OF USERS ${usersToDelete.length}`
);
};