Skip to content

Commit 3c72a79

Browse files
authored
Expose more information over /instance (#1071)
Allows instance owners to optionally set a URL leading to a status page for their instance (in bonsai's case, https://status.lbpbonsai.com) in their `integrations.json` config, and adds this URL to the `/instance` API endpoint's response , aswell as some other attributes, like role-specific perms (read-only etc), and whether the instance's presence server is enabled.
2 parents cc54039 + 8e9f4a0 commit 3c72a79

5 files changed

Lines changed: 49 additions & 1 deletion

File tree

Refresh.Core/Configuration/IntegrationConfig.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Refresh.Core.Configuration;
77
/// </summary>
88
public class IntegrationConfig : Config
99
{
10-
public override int CurrentConfigVersion => 8;
10+
public override int CurrentConfigVersion => 9;
1111
public override int Version { get; set; }
1212
protected override void Migrate(int oldVer, dynamic oldConfig)
1313
{
@@ -69,6 +69,7 @@ protected override void Migrate(int oldVer, dynamic oldConfig)
6969
#endregion
7070

7171
public string? GrafanaDashboardUrl { get; set; }
72+
public string? ServerStatusUrl { get; set; }
7273

7374
/// <summary>
7475
/// A link to a .SVG or .PNG containing the logo to use for branding.

Refresh.Interfaces.APIv3/Endpoints/DataTypes/Response/ApiInstanceResponse.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ public class ApiInstanceResponse : IApiResponse
4747

4848
public required bool MaintenanceModeEnabled { get; set; }
4949
public required string? GrafanaDashboardUrl { get; set; }
50+
public required string? ServerStatusUrl { get; set; }
5051

5152
public required string WebsiteLogoUrl { get; set; }
5253
public required string? WebsiteDefaultTheme { get; set; }
5354

5455
public required ApiContactInfoResponse ContactInfo { get; set; }
5556

5657
public required ApiContestResponse? ActiveContest { get; set; }
58+
59+
public required ApiRolePermissionsResponse NormalUserPermissions { get; set; }
60+
public required ApiRolePermissionsResponse TrustedUserPermissions { get; set; }
61+
62+
public required bool IsPresenceServerEnabled { get; set; }
63+
// TODO: similar attribute for CWLib integration
5764
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Refresh.Core.Configuration;
2+
3+
namespace Refresh.Interfaces.APIv3.Endpoints.DataTypes.Response;
4+
5+
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
6+
public class ApiRolePermissionsResponse : IApiResponse
7+
{
8+
public required ConfigAssetFlags BlockedAssetFlags { get; set; }
9+
public required bool ReadOnlyMode { get; set; }
10+
public required ApiTimedLevelLimitResponse? TimedLevelUploadLimits { get; set; }
11+
public required int UserFilesizeQuota { get; set; }
12+
13+
public static ApiRolePermissionsResponse FromOld(RolePermissions old)
14+
{
15+
return new()
16+
{
17+
BlockedAssetFlags = old.BlockedAssetFlags,
18+
ReadOnlyMode = old.ReadOnlyMode,
19+
TimedLevelUploadLimits = old.TimedLevelUploadLimits.Enabled ? new ApiTimedLevelLimitResponse()
20+
{
21+
TimeSpanHours = old.TimedLevelUploadLimits.TimeSpanHours,
22+
LevelQuota = old.TimedLevelUploadLimits.LevelQuota,
23+
} : null,
24+
UserFilesizeQuota = old.UserFilesizeQuota,
25+
};
26+
}
27+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Refresh.Interfaces.APIv3.Endpoints.DataTypes.Response;
2+
3+
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
4+
public class ApiTimedLevelLimitResponse : IApiResponse
5+
{
6+
public required int TimeSpanHours { get; set; }
7+
public required int LevelQuota { get; set; }
8+
}

Refresh.Interfaces.APIv3/Endpoints/InstanceApiEndpoints.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public ApiResponse<ApiInstanceResponse> GetInstanceInformation(RequestContext co
7272
GrafanaDashboardUrl = integrationConfig.GrafanaDashboardUrl,
7373
WebsiteLogoUrl = integrationConfig.WebsiteLogoUrl,
7474
WebsiteDefaultTheme = integrationConfig.WebsiteDefaultTheme,
75+
IsPresenceServerEnabled = integrationConfig.PresenceEnabled,
76+
ServerStatusUrl = integrationConfig.ServerStatusUrl,
77+
78+
NormalUserPermissions = ApiRolePermissionsResponse.FromOld(gameConfig.NormalUserPermissions),
79+
TrustedUserPermissions = ApiRolePermissionsResponse.FromOld(gameConfig.TrustedUserPermissions),
7580

7681
ContactInfo = new ApiContactInfoResponse
7782
{

0 commit comments

Comments
 (0)