mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 16:08:38 +00:00
Implement basic RPC configuration API endpoint (#864)
* Implement basic RPC information endpoint with test data * Implement configuration options for RPC * Rename RpcConfiguration to RpcResponse * Rider insists on modifying dataSources.xml * Implement documentation and fix code quality/gitignore issues * Use SerializableAttribute instead of UsedImplicitlyAttribute * Add warning regarding nullable assets * Prevent precision issues with application ID * Check asset properties for null/whitespace and return null
This commit is contained in:
parent
7939211308
commit
e072201ec7
7 changed files with 123 additions and 20 deletions
18
ProjectLighthouse.Servers.API/Controllers/RpcController.cs
Normal file
18
ProjectLighthouse.Servers.API/Controllers/RpcController.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Servers.API.Responses;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.API.Controllers;
|
||||
|
||||
public class RpcController : ApiEndpointController
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns basic information that Discord RPC clients can use for self-configuration.
|
||||
/// </summary>
|
||||
/// <returns>RpcResponse</returns>
|
||||
/// <response code="200">The RPC configuration.</response>
|
||||
[HttpGet("rpc")]
|
||||
[ProducesResponseType(typeof(RpcResponse), StatusCodes.Status200OK)]
|
||||
public IActionResult GetRpcConfiguration() =>
|
||||
this.Ok(RpcResponse.CreateFromConfiguration(ServerConfiguration.Instance.RichPresenceConfiguration));
|
||||
}
|
33
ProjectLighthouse.Servers.API/Responses/RpcResponse.cs
Normal file
33
ProjectLighthouse.Servers.API/Responses/RpcResponse.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
#nullable disable
|
||||
|
||||
using LBPUnion.ProjectLighthouse.Configuration.ConfigurationCategories;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.API.Responses;
|
||||
|
||||
public class RpcResponse
|
||||
{
|
||||
public string ApplicationId { get; set; }
|
||||
public string PartyIdPrefix { get; set; }
|
||||
public UsernameType UsernameType { get; set; }
|
||||
public RpcAssets Assets { get; set; }
|
||||
|
||||
public static RpcResponse CreateFromConfiguration(RichPresenceConfiguration configuration) =>
|
||||
new()
|
||||
{
|
||||
ApplicationId = configuration.ApplicationId,
|
||||
PartyIdPrefix = configuration.PartyIdPrefix,
|
||||
UsernameType = configuration.UsernameType,
|
||||
Assets = new RpcAssets
|
||||
{
|
||||
PodAsset = AssetConvertNull(configuration.Assets.PodAsset),
|
||||
MoonAsset = AssetConvertNull(configuration.Assets.MoonAsset),
|
||||
RemoteMoonAsset = AssetConvertNull(configuration.Assets.RemoteMoonAsset),
|
||||
DeveloperAsset = AssetConvertNull(configuration.Assets.DeveloperAsset),
|
||||
DeveloperAdventureAsset = AssetConvertNull(configuration.Assets.DeveloperAdventureAsset),
|
||||
DlcAsset = AssetConvertNull(configuration.Assets.DlcAsset),
|
||||
FallbackAsset = AssetConvertNull(configuration.Assets.FallbackAsset),
|
||||
},
|
||||
};
|
||||
|
||||
private static string AssetConvertNull(string asset) => string.IsNullOrWhiteSpace(asset) ? null : asset;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue