-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31804 from bdach/bss/api-setup
Add API request & response structures for beatmap submission
- Loading branch information
Showing
37 changed files
with
310 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ public void TestOnlineMenuBannerTrusted() | |
new APIMenuImage | ||
{ | ||
Image = @"https://assets.ppy.sh/main-menu/[email protected]", | ||
Url = $@"{API.WebsiteRootUrl}/home/news/2023-12-21-project-loved-december-2023", | ||
Url = $@"{API.Endpoints.WebsiteUrl}/home/news/2023-12-21-project-loved-december-2023", | ||
} | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Diagnostics; | ||
using osu.Framework.IO.Network; | ||
|
||
namespace osu.Game.Online.API.Requests | ||
{ | ||
public abstract class APIUploadRequest : APIRequest | ||
{ | ||
protected override WebRequest CreateWebRequest() | ||
{ | ||
var request = base.CreateWebRequest(); | ||
request.UploadProgress += onUploadProgress; | ||
return request; | ||
} | ||
|
||
private void onUploadProgress(long current, long total) | ||
{ | ||
Debug.Assert(API != null); | ||
API.Schedule(() => Progressed?.Invoke(current, total)); | ||
} | ||
|
||
public event APIProgressHandler? Progressed; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
osu.Game/Online/API/Requests/PatchBeatmapPackageRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using osu.Framework.IO.Network; | ||
|
||
namespace osu.Game.Online.API.Requests | ||
{ | ||
public class PatchBeatmapPackageRequest : APIUploadRequest | ||
{ | ||
protected override string Uri | ||
{ | ||
get | ||
{ | ||
// can be removed once the service has been successfully deployed to production | ||
if (API!.Endpoints.BeatmapSubmissionServiceUrl == null) | ||
throw new NotSupportedException("Beatmap submission not supported in this configuration!"); | ||
|
||
return $@"{API!.Endpoints.BeatmapSubmissionServiceUrl!}/beatmapsets/{BeatmapSetID}"; | ||
} | ||
} | ||
|
||
protected override string Target => throw new NotSupportedException(); | ||
|
||
public uint BeatmapSetID { get; } | ||
|
||
// ReSharper disable once CollectionNeverUpdated.Global | ||
public Dictionary<string, byte[]> FilesChanged { get; } = new Dictionary<string, byte[]>(); | ||
|
||
// ReSharper disable once CollectionNeverUpdated.Global | ||
public HashSet<string> FilesDeleted { get; } = new HashSet<string>(); | ||
|
||
public PatchBeatmapPackageRequest(uint beatmapSetId) | ||
{ | ||
BeatmapSetID = beatmapSetId; | ||
} | ||
|
||
protected override WebRequest CreateWebRequest() | ||
{ | ||
var request = base.CreateWebRequest(); | ||
request.Method = HttpMethod.Patch; | ||
|
||
foreach ((string filename, byte[] content) in FilesChanged) | ||
request.AddFile(@"filesChanged", content, filename); | ||
|
||
foreach (string filename in FilesDeleted) | ||
request.AddParameter(@"filesDeleted", filename, RequestParameterType.Form); | ||
|
||
request.Timeout = 60_000; | ||
return request; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using osu.Framework.IO.Network; | ||
using osu.Framework.Localisation; | ||
using osu.Game.Localisation; | ||
using osu.Game.Online.API.Requests.Responses; | ||
|
||
namespace osu.Game.Online.API.Requests | ||
{ | ||
public class PutBeatmapSetRequest : APIRequest<PutBeatmapSetResponse> | ||
{ | ||
protected override string Uri | ||
{ | ||
get | ||
{ | ||
// can be removed once the service has been successfully deployed to production | ||
if (API!.Endpoints.BeatmapSubmissionServiceUrl == null) | ||
throw new NotSupportedException("Beatmap submission not supported in this configuration!"); | ||
|
||
return $@"{API!.Endpoints.BeatmapSubmissionServiceUrl}/beatmapsets"; | ||
} | ||
} | ||
|
||
protected override string Target => throw new NotSupportedException(); | ||
|
||
[JsonProperty("beatmapset_id")] | ||
public uint? BeatmapSetID { get; init; } | ||
|
||
[JsonProperty("beatmaps_to_create")] | ||
public uint BeatmapsToCreate { get; init; } | ||
|
||
[JsonProperty("beatmaps_to_keep")] | ||
public uint[] BeatmapsToKeep { get; init; } = []; | ||
|
||
[JsonProperty("target")] | ||
public BeatmapSubmissionTarget SubmissionTarget { get; init; } | ||
|
||
private PutBeatmapSetRequest() | ||
{ | ||
} | ||
|
||
public static PutBeatmapSetRequest CreateNew(uint beatmapCount, BeatmapSubmissionTarget target) => new PutBeatmapSetRequest | ||
{ | ||
BeatmapsToCreate = beatmapCount, | ||
SubmissionTarget = target, | ||
}; | ||
|
||
public static PutBeatmapSetRequest UpdateExisting(uint beatmapSetId, IEnumerable<uint> beatmapsToKeep, uint beatmapsToCreate, BeatmapSubmissionTarget target) => new PutBeatmapSetRequest | ||
{ | ||
BeatmapSetID = beatmapSetId, | ||
BeatmapsToKeep = beatmapsToKeep.ToArray(), | ||
BeatmapsToCreate = beatmapsToCreate, | ||
SubmissionTarget = target, | ||
}; | ||
|
||
protected override WebRequest CreateWebRequest() | ||
{ | ||
var req = base.CreateWebRequest(); | ||
req.Method = HttpMethod.Put; | ||
req.ContentType = @"application/json"; | ||
req.AddRaw(JsonConvert.SerializeObject(this)); | ||
return req; | ||
} | ||
} | ||
|
||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum BeatmapSubmissionTarget | ||
{ | ||
[LocalisableDescription(typeof(BeatmapSubmissionStrings), nameof(BeatmapSubmissionStrings.BeatmapSubmissionTargetWIP))] | ||
WIP, | ||
|
||
[LocalisableDescription(typeof(BeatmapSubmissionStrings), nameof(BeatmapSubmissionStrings.BeatmapSubmissionTargetPending))] | ||
Pending, | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
osu.Game/Online/API/Requests/ReplaceBeatmapPackageRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Net.Http; | ||
using osu.Framework.IO.Network; | ||
|
||
namespace osu.Game.Online.API.Requests | ||
{ | ||
public class ReplaceBeatmapPackageRequest : APIUploadRequest | ||
{ | ||
protected override string Uri | ||
{ | ||
get | ||
{ | ||
// can be removed once the service has been successfully deployed to production | ||
if (API!.Endpoints.BeatmapSubmissionServiceUrl == null) | ||
throw new NotSupportedException("Beatmap submission not supported in this configuration!"); | ||
|
||
return $@"{API!.Endpoints.BeatmapSubmissionServiceUrl}/beatmapsets/{BeatmapSetID}"; | ||
} | ||
} | ||
|
||
protected override string Target => throw new NotSupportedException(); | ||
|
||
public uint BeatmapSetID { get; } | ||
|
||
private readonly byte[] oszPackage; | ||
|
||
public ReplaceBeatmapPackageRequest(uint beatmapSetID, byte[] oszPackage) | ||
{ | ||
this.oszPackage = oszPackage; | ||
BeatmapSetID = beatmapSetID; | ||
} | ||
|
||
protected override WebRequest CreateWebRequest() | ||
{ | ||
var request = base.CreateWebRequest(); | ||
request.AddFile(@"beatmapArchive", oszPackage); | ||
request.Method = HttpMethod.Put; | ||
request.Timeout = 60_000; | ||
return request; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
osu.Game/Online/API/Requests/Responses/PutBeatmapSetResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace osu.Game.Online.API.Requests.Responses | ||
{ | ||
public class PutBeatmapSetResponse | ||
{ | ||
[JsonProperty("beatmapset_id")] | ||
public uint BeatmapSetId { get; set; } | ||
|
||
[JsonProperty("beatmap_ids")] | ||
public ICollection<uint> BeatmapIds { get; set; } = Array.Empty<uint>(); | ||
|
||
[JsonProperty("files")] | ||
public ICollection<BeatmapSetFile> Files { get; set; } = Array.Empty<BeatmapSetFile>(); | ||
} | ||
|
||
public struct BeatmapSetFile | ||
{ | ||
[JsonProperty("filename")] | ||
public string Filename { get; set; } | ||
|
||
[JsonProperty("sha2_hash")] | ||
public string SHA2Hash { get; set; } | ||
} | ||
} |
Oops, something went wrong.