mirror of
https://github.com/ppy/osu.git
synced 2026-05-29 23:01:12 +08:00
Add API request & response structures for beatmap submission
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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!.EndpointConfiguration.BeatmapSubmissionServiceUrl == null)
|
||||
throw new NotSupportedException("Beatmap submission not supported in this configuration!");
|
||||
|
||||
return $@"{API!.EndpointConfiguration.BeatmapSubmissionServiceUrl!}/beatmapsets/{BeatmapSetID}";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string Target => throw new NotSupportedException();
|
||||
|
||||
public uint BeatmapSetID { get; }
|
||||
public Dictionary<string, byte[]> FilesChanged { get; } = new Dictionary<string, byte[]>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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!.EndpointConfiguration.BeatmapSubmissionServiceUrl == null)
|
||||
throw new NotSupportedException("Beatmap submission not supported in this configuration!");
|
||||
|
||||
return $@"{API!.EndpointConfiguration.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,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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!.EndpointConfiguration.BeatmapSubmissionServiceUrl == null)
|
||||
throw new NotSupportedException("Beatmap submission not supported in this configuration!");
|
||||
|
||||
return $@"{API!.EndpointConfiguration.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user