Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more patreon logging #393

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions server/patreon.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ const router = Router();

const membersQuery = () => {
const membersQueryParams = {
include: ["currently_entitled_tiers", "user"].join(","),
include: ["currently_entitled_tiers", "user", "currently_entitled_tiers.campaign"].join(","),
"fields[member]": [
"full_name",
"is_follower",
"lifetime_support_cents",
"currently_entitled_amount_cents",
"patron_status",
].join(","),
"fields[tier]": ["amount_cents", "published", "title", "url"].join(","),
"fields[tier]": ["amount_cents", "title", "description"].join(","),
"fields[campaign]": ["vanity"].join(","),
};

const membersQuery = new URL("https://www.patreon.com/api/oauth2/v2/campaigns/10343002/members");
Expand Down Expand Up @@ -58,7 +59,7 @@ const getPatreonPatronsData = async () => {
}

const tiers = data.included
.filter(i => i.type === "tier" && i.attributes.published)
.filter(i => i.type === "tier")
.reduce((acc, tier) => {
acc[tier.id] = tier;
return acc;
Expand Down Expand Up @@ -87,9 +88,12 @@ const getPatreonPatronsData = async () => {
};

let patronCache = {};
let tierCache = {};

const updatePatrons = async () => {
patronCache = await getPatreonPatronsData();
const data = await getPatreonPatronsData();
patronCache = data.tierMembers;
tierCache = data.tiers;
};

updatePatrons();
Expand Down Expand Up @@ -132,29 +136,34 @@ const getComputeAmountForTier = tierId => {
amount = nonHamisAmount;
break;
}
case "20133846": {
// Free
amount = +nonHamisAmount;
break;
}
case "9702578": {
// Hämis
amount = hamisAmount;
amount = +hamisAmount;
break;
}
case "9702590": {
// Hämis Hämis
amount = hamis2Amount;
amount = +hamis2Amount;
break;
}
case "9702596": {
// Hämis Hämis Hämis
amount = hamis3Amount;
amount = +hamis3Amount;
break;
}
case "9704115": {
// Hämis Hämis Hämis Hämis
amount = hamis4Amount;
amount = +hamis4Amount;
break;
}
default: {
amount = +nonHamisAmount;
console.error("Unknown tier", tierId);
console.error("Unknown tier", tierId, JSON.stringify(tierCache));
break;
}
}
Expand All @@ -169,7 +178,6 @@ const getComputeAmountForPledgeAmount = pledgeAmount => {
case 400: {
// Hämis
amount = hamisAmount;

break;
}
case 800: {
Expand All @@ -189,7 +197,7 @@ const getComputeAmountForPledgeAmount = pledgeAmount => {
}
default: {
amount = (1000 * 60 * 60 * 10 * 400) / pledgeAmount;
console.error("Unknown pledgeAmount", pledgeAmount);
console.error("Unknown pledgeAmount", pledgeAmount, JSON.stringify(tierCache));
if (isNaN(amount)) {
amount = hamis4Amount;
}
Expand Down
Loading