From 53a46778c3afe3d3111a88863d596b645013c08b Mon Sep 17 00:00:00 2001 From: Toaster Date: Thu, 12 Mar 2026 23:57:37 +0100 Subject: [PATCH] block api asset upload if filesize quota is reached --- Refresh.Interfaces.APIv3/Endpoints/ResourceApiEndpoints.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Refresh.Interfaces.APIv3/Endpoints/ResourceApiEndpoints.cs b/Refresh.Interfaces.APIv3/Endpoints/ResourceApiEndpoints.cs index 782c8cdc..4d95653c 100644 --- a/Refresh.Interfaces.APIv3/Endpoints/ResourceApiEndpoints.cs +++ b/Refresh.Interfaces.APIv3/Endpoints/ResourceApiEndpoints.cs @@ -194,6 +194,12 @@ IntegrationConfig integration return new ApiValidationError($"The asset must be under 2MB. Your file was {body.Length:N0} bytes."); } + if (body.Length + user.FilesizeQuotaUsage > config.UserFilesizeQuota) + { + context.Logger.LogWarning(BunkumCategory.UserContent, "User {0} has hit the filesize quota ({1} bytes), rejecting.", user.Username, config.UserFilesizeQuota); + return new ApiValidationError($"You have exceeded your filesize quota."); + } + GameAsset? gameAsset = importer.ReadAndVerifyAsset(hash, body, TokenPlatform.Website, database); if (gameAsset == null) return ApiValidationError.CannotReadAssetError; @@ -213,6 +219,7 @@ IntegrationConfig integration database.AddAssetToDatabase(gameAsset); dataContext.Cache.CacheAsset(gameAsset.AssetHash, gameAsset); + database.IncrementUserFilesizeQuota(user, body.Length); return new ApiResponse(ApiGameAssetResponse.FromOld(gameAsset, dataContext)!, Created); }