Compare commits

..

2 Commits

Author SHA1 Message Date
8bcb0094b2 feat: treat quota limit of 0 as unlimited
All checks were successful
CI / build (push) Successful in 41s
Pre-check now skips periods where limit is 0, allowing users to have
unlimited quota by setting daily_limit_mb/weekly_limit_mb/monthly_limit_mb
to 0 in the database.
2026-06-25 22:09:36 +03:30
f39e4e6fb0 fix: quota pre-check used max format size, blocked before format selection
Changed pre-check to only reject when used >= limit (already exhausted),
not when the max format size alone would exceed the limit. The actual
quota is applied at 50% progress using the selected format's size.
2026-06-25 22:08:05 +03:30

View File

@@ -113,19 +113,17 @@ func (h *Handler) handleURLInput(ctx context.Context, chatID int64, text string,
return return
} }
// Reject if user has already exhausted quota (limit of 0 = unlimited).
q, err := h.Repo.GetOrCreateQuotas(userID) q, err := h.Repo.GetOrCreateQuotas(userID)
if err == nil { if err == nil {
q = h.resetQuotasIfNeeded(q) q = h.resetQuotasIfNeeded(q)
estimatedMB := info.EstimatedSize / (1024 * 1024) if (q.DailyLimitMB > 0 && q.DailyUsedMB >= q.DailyLimitMB) ||
if estimatedMB > 0 { (q.WeeklyLimitMB > 0 && q.WeeklyUsedMB >= q.WeeklyLimitMB) ||
if q.DailyUsedMB+estimatedMB > q.DailyLimitMB || (q.MonthlyLimitMB > 0 && q.MonthlyUsedMB >= q.MonthlyLimitMB) {
q.WeeklyUsedMB+estimatedMB > q.WeeklyLimitMB || h.sendText(ctx, chatID, fmt.Sprintf(
q.MonthlyUsedMB+estimatedMB > q.MonthlyLimitMB { "Quota exceeded. Daily: %d/%d MB, Weekly: %d/%d MB, Monthly: %d/%d MB.",
h.sendText(ctx, chatID, fmt.Sprintf( q.DailyUsedMB, q.DailyLimitMB, q.WeeklyUsedMB, q.WeeklyLimitMB, q.MonthlyUsedMB, q.MonthlyLimitMB))
"Quota exceeded. Daily: %d/%d MB, Weekly: %d/%d MB, Monthly: %d/%d MB.", return
q.DailyUsedMB, q.DailyLimitMB, q.WeeklyUsedMB, q.WeeklyLimitMB, q.MonthlyUsedMB, q.MonthlyLimitMB))
return
}
} }
} }