mirror of
https://github.com/lawrencehook/remove-youtube-suggestions.git
synced 2026-07-25 06:54:31 +00:00
Harden license cache: 10s TTL and skip incomplete subscription.created
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -55,6 +55,11 @@ router.post('/stripe', async (req, res) => {
|
||||
try {
|
||||
const email = await getCustomerEmail(subscription.customer);
|
||||
if (email) {
|
||||
// Skip non-active created events to avoid overwriting premium with incomplete status
|
||||
if (!premium && event.type === 'customer.subscription.created') {
|
||||
console.log(`[webhook] Subscription created: ${email} -> ${subscription.status} (skipped cache update)`);
|
||||
break;
|
||||
}
|
||||
storage.setSubscriptionStatus(email, premium, subscription.customer);
|
||||
console.log(`[webhook] Subscription ${action}: ${email} -> ${premium ? 'premium' : 'free'}`);
|
||||
|
||||
|
||||
@@ -78,7 +78,10 @@ function setSubscriptionStatus(email, premium, customerId) {
|
||||
|
||||
function getSubscriptionStatus(email) {
|
||||
const data = readSubscriptionFile();
|
||||
return data[email.toLowerCase()] || null;
|
||||
const entry = data[email.toLowerCase()];
|
||||
if (!entry) return null;
|
||||
if (Date.now() - entry.updatedAt > 10000) return null;
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user