|
4 | 4 | using Bunkum.Core.RateLimit; |
5 | 5 | using Bunkum.Protocols.Http; |
6 | 6 | using Refresh.Common.Constants; |
7 | | -using Refresh.Core.Services; |
8 | 7 | using Refresh.Core.Types.Data; |
9 | | -using Refresh.Database; |
10 | | -using Refresh.Database.Models.Assets; |
11 | | -using Refresh.Database.Models.Authentication; |
12 | 8 | using Refresh.Database.Models.Levels; |
13 | 9 | using Refresh.Database.Models.Playlists; |
14 | 10 | using Refresh.Database.Models.Users; |
15 | 11 | using Refresh.Interfaces.APIv3.Endpoints.ApiTypes; |
16 | 12 | using Refresh.Interfaces.APIv3.Endpoints.ApiTypes.Errors; |
17 | 13 | using Refresh.Interfaces.APIv3.Endpoints.DataTypes.Request; |
18 | 14 | using Refresh.Interfaces.APIv3.Endpoints.DataTypes.Response.Playlists; |
| 15 | +using Refresh.Interfaces.APIv3.Extensions; |
19 | 16 | using static Refresh.Core.RateLimits.PlaylistEndpointLimits; |
20 | 17 |
|
21 | 18 | namespace Refresh.Interfaces.APIv3.Endpoints; |
22 | 19 |
|
23 | 20 | public class PlaylistApiEndpoints : EndpointGroup |
24 | 21 | { |
25 | | - private ApiError? ValidatePlaylist(ApiPlaylistCreationRequest body, GuidCheckerService guidChecker, GameDatabaseContext database) |
| 22 | + private ApiError? ValidatePlaylist(ApiPlaylistCreationRequest body, DataContext dataContext) |
26 | 23 | { |
27 | | - if (body.Icon != null) |
28 | | - { |
29 | | - if (body.Icon.IsBlankHash()) |
30 | | - body.Icon = "0"; |
31 | | - |
32 | | - else if (body.Icon!.StartsWith('g') && body.Icon.Length > 1) |
33 | | - { |
34 | | - bool isGuid = long.TryParse(body.Icon[1..], out long guid); |
35 | | - if (!isGuid || (isGuid && !guidChecker.IsTextureGuid(TokenGame.LittleBigPlanet1, guid))) |
36 | | - return ApiValidationError.InvalidTextureGuidError; |
37 | | - } |
38 | | - else |
39 | | - { |
40 | | - GameAsset? icon = database.GetAssetFromHash(body.Icon); |
41 | | - |
42 | | - if (icon == null) |
43 | | - return ApiValidationError.IconMissingError; |
44 | | - |
45 | | - if (icon.AssetType is not GameAssetType.Jpeg and not GameAssetType.Png) |
46 | | - return ApiValidationError.IconMustBeImageError; |
47 | | - } |
48 | | - } |
| 24 | + (body.Icon, ApiError? iconError) = body.Icon.ValidateIcon(dataContext); |
| 25 | + if (iconError != null) return iconError; |
49 | 26 |
|
50 | 27 | // Trim name and description |
51 | 28 | if (body.Name != null && body.Name.Length > UgcLimits.TitleLimit) |
@@ -78,7 +55,7 @@ public class PlaylistApiEndpoints : EndpointGroup |
78 | 55 | public ApiResponse<ApiGamePlaylistResponse> CreatePlaylist(RequestContext context, DataContext dataContext, |
79 | 56 | GameUser user, ApiPlaylistCreationRequest body) |
80 | 57 | { |
81 | | - ApiError? error = this.ValidatePlaylist(body, dataContext.GuidChecker, dataContext.Database); |
| 58 | + ApiError? error = this.ValidatePlaylist(body, dataContext); |
82 | 59 | if (error != null) return error; |
83 | 60 |
|
84 | 61 | string? parentIdStr = context.QueryString.Get("parentId"); |
@@ -125,7 +102,7 @@ public ApiResponse<ApiGamePlaylistResponse> UpdatePlaylist(RequestContext contex |
125 | 102 | if (user.UserId != playlist.PublisherId) |
126 | 103 | return ApiValidationError.NoPlaylistEditPermissionError; |
127 | 104 |
|
128 | | - ApiError? error = this.ValidatePlaylist(body, dataContext.GuidChecker, dataContext.Database); |
| 105 | + ApiError? error = this.ValidatePlaylist(body, dataContext); |
129 | 106 | if (error != null) return error; |
130 | 107 |
|
131 | 108 | playlist = dataContext.Database.UpdatePlaylist(playlist, body); |
|
0 commit comments