Skip to content

Commit

Permalink
Tweak button frozen logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Heathcorp committed Apr 22, 2024
1 parent 6ef9207 commit 001fadf
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ export const helloWorld = https.onRequest((request, response) => {


// extreme cases where we need to shut off the button but still show a count
const getIsFrozen = async () => {
const getButtonConfig = async () => {
const db = getDatabase();
const ref = db.ref("thebutton/frozen");
const frozen = (await ref.once("value")).val();
return !!frozen;
const ref = db.ref("thebutton/config");
const config = (await ref.once("value")).val();
return config;
};

export const buttonCount = https.onCall(async (data, context) => {
const db = getDatabase();


try {
const frozen = await getIsFrozen();
const {frozen} = await getButtonConfig();

const ref = db.ref("thebutton/main_count");
const count = (await ref.once("value")).val();
Expand All @@ -56,10 +56,12 @@ export const buttonCount = https.onCall(async (data, context) => {
}
});

const MAX_PRESSES_PER_REQUEST = 150;

export const buttonPressed = https.onCall(
async (data: { count?: number; turnstileToken: string }, context) => {

const frozen = await getIsFrozen();
const {frozen, } = await getButtonConfig();
if (frozen) {
return { success: false, frozen };
}
Expand All @@ -68,7 +70,7 @@ export const buttonPressed = https.onCall(

if (
data.count !== undefined &&
(typeof data.count !== "number" || data.count <= 0 || data.count > 500)
(typeof data.count !== "number" || data.count <= 0 || data.count > MAX_PRESSES_PER_REQUEST)
) {
return {
success: false,
Expand Down

0 comments on commit 001fadf

Please sign in to comment.