diff --git a/DeckPersonalisationApi/Controllers/SubmissionController.cs b/DeckPersonalisationApi/Controllers/SubmissionController.cs index 22a59a1..4df9195 100644 --- a/DeckPersonalisationApi/Controllers/SubmissionController.cs +++ b/DeckPersonalisationApi/Controllers/SubmissionController.cs @@ -20,14 +20,16 @@ public class SubmissionController : Controller private UserService _user; private BlobService _blob; private AppConfiguration _config; + private ThemeService _themes; - public SubmissionController(JwtService jwt, SubmissionService submission, UserService user, BlobService blob, AppConfiguration config) + public SubmissionController(JwtService jwt, SubmissionService submission, UserService user, BlobService blob, AppConfiguration config, ThemeService themes) { _jwt = jwt; _submission = submission; _user = user; _blob = blob; _config = config; + _themes = themes; } [HttpPost("css_git")] @@ -202,6 +204,9 @@ private void ValidateMeta(User user, SubmissionMeta meta, ThemeType type) if (meta.PrivateSubmission && DiscordBot.Instance.PermissionStateOfUser(user.Id) == "None") throw new BadRequestException("Can only create private themes on premium account"); + + if (_themes.GetThemeCountOfUser(user) >= _config.MaxThemeCount) + throw new BadRequestException("Theme limit reached"); } private void CheckIfUserIsAllowedToMakeSubmission(User user) diff --git a/DeckPersonalisationApi/Services/AppConfiguration.cs b/DeckPersonalisationApi/Services/AppConfiguration.cs index 6ef6a3b..74a6126 100644 --- a/DeckPersonalisationApi/Services/AppConfiguration.cs +++ b/DeckPersonalisationApi/Services/AppConfiguration.cs @@ -46,6 +46,7 @@ public class AppConfiguration public long MaxEmailLength { get; private set; } public long MaxDescriptionLength { get; private set; } public long MaxCssOnlySubmissionSize { get; private set; } + public long MaxThemeCount { get; private set; } public long MaxErrorStoreCharacters { get; private set; } public long DiscordServerId { get; private set; } public long DiscordPremiumTier1Role { get; private set; } @@ -134,6 +135,7 @@ private void SetValues() MaxEmailLength = GetInt("Config:MaxEmailLength"); MaxCssOnlySubmissionSize = GetInt("Config:MaxCssOnlySubmissionSize"); MaxErrorStoreCharacters = GetInt("Config:MaxErrorStoreCharacters"); + MaxThemeCount = GetInt("Config:MaxThemeCountPerUser"); DiscordServerId = GetInt("Config:DiscordServerId"); DiscordPremiumTier1Role = GetInt("Config:PremiumTier1Role"); diff --git a/DeckPersonalisationApi/Services/ThemeService.cs b/DeckPersonalisationApi/Services/ThemeService.cs index f3eb233..bff1b5f 100644 --- a/DeckPersonalisationApi/Services/ThemeService.cs +++ b/DeckPersonalisationApi/Services/ThemeService.cs @@ -222,6 +222,9 @@ public IEnumerable GetThemesByIds(List ids, bool strict = true public bool ThemeNameExists(string name, ThemeType type) => _ctx.CssThemes.Any(x => x.Name == name && x.Visibility == PostVisibility.Public && x.Type == type); + public int GetThemeCountOfUser(User user) + => _ctx.CssThemes.Count(x => x.Author.Id == user.Id && x.Visibility != PostVisibility.Deleted); + public List GetThemesLegacy(ThemeType type, PostVisibility visibility) => _ctx.CssThemes .Include(x => x.Images) diff --git a/DeckPersonalisationApi/appsettings.example.json b/DeckPersonalisationApi/appsettings.example.json index ca83799..e9d8398 100644 --- a/DeckPersonalisationApi/appsettings.example.json +++ b/DeckPersonalisationApi/appsettings.example.json @@ -50,6 +50,7 @@ "MaxDescriptionLength": "1000", "MaxCssOnlySubmissionSize": "2000", "MaxErrorStoreCharacters": "4096", + "MaxThemeCountPerUser": "100", "DiscordServerId": "1051660079033745478", "PremiumTier1Role": "1077305620346175498", "PremiumTier2Role": "1077306197939585036",