Skip to content

Commit fe8bc3b

Browse files
authored
block api asset upload if filesize quota is reached (#1051)
2 parents 3d0201a + 53a4677 commit fe8bc3b

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Refresh.Interfaces.APIv3/Endpoints/ResourceApiEndpoints.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ IntegrationConfig integration
194194
return new ApiValidationError($"The asset must be under 2MB. Your file was {body.Length:N0} bytes.");
195195
}
196196

197+
if (body.Length + user.FilesizeQuotaUsage > config.UserFilesizeQuota)
198+
{
199+
context.Logger.LogWarning(BunkumCategory.UserContent, "User {0} has hit the filesize quota ({1} bytes), rejecting.", user.Username, config.UserFilesizeQuota);
200+
return new ApiValidationError($"You have exceeded your filesize quota.");
201+
}
202+
197203
GameAsset? gameAsset = importer.ReadAndVerifyAsset(hash, body, TokenPlatform.Website, database);
198204
if (gameAsset == null)
199205
return ApiValidationError.CannotReadAssetError;
@@ -213,6 +219,7 @@ IntegrationConfig integration
213219

214220
database.AddAssetToDatabase(gameAsset);
215221
dataContext.Cache.CacheAsset(gameAsset.AssetHash, gameAsset);
222+
database.IncrementUserFilesizeQuota(user, body.Length);
216223

217224
return new ApiResponse<ApiGameAssetResponse>(ApiGameAssetResponse.FromOld(gameAsset, dataContext)!, Created);
218225
}

0 commit comments

Comments
 (0)