feat: add resource quotas, PayPal subscriptions and paid disk allowances
Calculate and enforce configurable resource consumption, expose balances in PostIt and document the rule in CGU. Add confirmed monthly PayPal credits and disk quotas of twice the free default for Discovery and five times for Premium, with payment reconciliation, migrations and regression tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
0728d2a3f7
commit
650e5f5e30
69 changed files with 19111 additions and 203 deletions
21
src/Yavsc.Server/Settings/ResourceUsageOptions.cs
Normal file
21
src/Yavsc.Server/Settings/ResourceUsageOptions.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#nullable enable
|
||||
namespace Yavsc.Settings;
|
||||
|
||||
public sealed class ResourceUsageOptions
|
||||
{
|
||||
public const string SectionName = "ResourceUsage";
|
||||
|
||||
public decimal ApiCallWeight { get; set; } = 0.2m;
|
||||
public decimal CpuSecondWeight { get; set; } = 0.1m;
|
||||
public decimal BandwidthMbWeight { get; set; } = 0.05m;
|
||||
public decimal StorageMbWeight { get; set; } = 0.5m;
|
||||
public decimal DefaultLimit { get; set; } = 1000m;
|
||||
public Dictionary<string, decimal> UserLimits { get; set; } = new();
|
||||
|
||||
public decimal GetLimit(string userId)
|
||||
=> UserLimits.TryGetValue(userId, out var limit) ? limit : DefaultLimit;
|
||||
|
||||
public decimal Calculate(decimal apiCalls, decimal cpuSeconds, decimal bandwidthMb, decimal storageMb)
|
||||
=> apiCalls * ApiCallWeight + cpuSeconds * CpuSecondWeight
|
||||
+ bandwidthMb * BandwidthMbWeight + storageMb * StorageMbWeight;
|
||||
}
|
||||
Loading…
Reference in a new issue