🐛 Fix wrong counting usage
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -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<long> GetTotalBillableUsage()
|
||||
public async Task<long> 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)
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user