From 83059374e9774021a65cf96113371bca5c117c6b Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 29 Jul 2025 14:43:40 +0800 Subject: [PATCH] :bug: Fix wrong counting usage --- DysonNetwork.Drive/Billing/QuotaService.cs | 2 +- DysonNetwork.Drive/Billing/UsageService.cs | 5 +++-- DysonNetwork.Drive/Storage/TusService.cs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/DysonNetwork.Drive/Billing/QuotaService.cs b/DysonNetwork.Drive/Billing/QuotaService.cs index aa91132..a59f294 100644 --- a/DysonNetwork.Drive/Billing/QuotaService.cs +++ b/DysonNetwork.Drive/Billing/QuotaService.cs @@ -17,7 +17,7 @@ public class QuotaService( { // The billable unit is MiB var billableUnit = (long)Math.Ceiling(newFileSize / 1024.0 / 1024.0 * costMultiplier); - var totalBillableUsage = await usage.GetTotalBillableUsage(); + var totalBillableUsage = await usage.GetTotalBillableUsage(accountId); var quota = await GetQuota(accountId); return (totalBillableUsage + billableUnit <= quota, billableUnit, quota); } diff --git a/DysonNetwork.Drive/Billing/UsageService.cs b/DysonNetwork.Drive/Billing/UsageService.cs index 917c484..ca99273 100644 --- a/DysonNetwork.Drive/Billing/UsageService.cs +++ b/DysonNetwork.Drive/Billing/UsageService.cs @@ -60,7 +60,7 @@ public class UsageService(AppDatabase db) PoolUsages = poolUsages, TotalUsageBytes = totalUsage, TotalFileCount = totalFileCount, - UsedQuota = await GetTotalBillableUsage() + UsedQuota = await GetTotalBillableUsage(accountId) }; } @@ -98,10 +98,11 @@ public class UsageService(AppDatabase db) }; } - public async Task GetTotalBillableUsage() + public async Task GetTotalBillableUsage(Guid accountId) { var now = SystemClock.Instance.GetCurrentInstant(); var files = await db.Files + .Where(f => f.AccountId == accountId) .Where(f => f.PoolId.HasValue) .Where(f => !f.IsMarkedRecycle) .Include(f => f.Pool) diff --git a/DysonNetwork.Drive/Storage/TusService.cs b/DysonNetwork.Drive/Storage/TusService.cs index 60f17a9..a6a0cb4 100644 --- a/DysonNetwork.Drive/Storage/TusService.cs +++ b/DysonNetwork.Drive/Storage/TusService.cs @@ -262,7 +262,7 @@ public abstract class TusService { eventContext.FailRequest( HttpStatusCode.Forbidden, - $"File size {billableUnit} MiB is exceed than the user's quota {quota} MiB" + $"File size {billableUnit} MiB is exceeded the user's quota {quota} MiB" ); rejected = true; }