1515using Refresh . Interfaces . APIv3 . Extensions ;
1616using Refresh . Core . RateLimits . Playlists ;
1717using Refresh . Core . Configuration ;
18+ using Refresh . Database . Models ;
1819
1920namespace Refresh . Interfaces . APIv3 . Endpoints ;
2021
@@ -59,6 +60,20 @@ public ApiResponse<ApiGamePlaylistResponse> CreatePlaylist(RequestContext contex
5960 {
6061 if ( user . IsWriteBlocked ( config ) )
6162 return ApiAuthenticationError . ReadOnlyError ;
63+
64+ EntityUploadRateLimitProperties uploadLimit = user . GetRolePermissionsForUser ( config ) . PlaylistUploadRateLimit ;
65+ if ( uploadLimit . Enabled )
66+ {
67+ TimeSpan ? rateLimitExpiresIn = dataContext . Database . GetRemainingTimeIfUploadRateLimitReached ( user , GameDatabaseEntity . Playlist , uploadLimit . UploadQuota ) ;
68+ if ( rateLimitExpiresIn != null )
69+ {
70+ return new ApiValidationError
71+ (
72+ $ "You have created too many playlists recently! Your limit is { uploadLimit . UploadQuota } playlists per { uploadLimit . TimeSpanHours } hours. "+
73+ $ "Try again in { rateLimitExpiresIn . Value . Hours } hours and { rateLimitExpiresIn . Value . Minutes } minutes."
74+ ) ;
75+ }
76+ }
6277
6378 ApiError ? error = this . ValidatePlaylist ( body , dataContext ) ;
6479 if ( error != null ) return error ;
@@ -85,6 +100,10 @@ public ApiResponse<ApiGamePlaylistResponse> CreatePlaylist(RequestContext contex
85100 }
86101
87102 GamePlaylist playlist = dataContext . Database . CreatePlaylist ( user , body , false ) ;
103+ if ( uploadLimit . Enabled )
104+ {
105+ dataContext . Database . IncrementUploadRateLimitForEntity ( user , GameDatabaseEntity . Playlist , uploadLimit . TimeSpanHours ) ;
106+ }
88107 dataContext . Database . AddPlaylistToPlaylist ( playlist , parent ) ;
89108
90109 return ApiGamePlaylistResponse . FromOld ( playlist , dataContext ) ;
0 commit comments