1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +08:00

Add website root URL and update most links to use it

For what it's worth, I intentionally didn't include news / changelog /
supporter, because these should never change.
This commit is contained in:
Dean Herbert 2020-12-24 18:11:40 +09:00
parent eb795a2127
commit 323da82477
15 changed files with 57 additions and 24 deletions

View File

@ -28,7 +28,9 @@ namespace osu.Game.Online.API
private readonly Queue<APIRequest> queue = new Queue<APIRequest>();
public string Endpoint { get; }
public string APIEndpointUrl { get; }
public string WebsiteRootUrl { get; }
/// <summary>
/// The username/email provided by the user when initiating a login.
@ -57,9 +59,10 @@ namespace osu.Game.Online.API
{
this.config = config;
Endpoint = endpointConfiguration.APIEndpoint;
APIEndpointUrl = endpointConfiguration.APIEndpointUrl;
WebsiteRootUrl = endpointConfiguration.WebsiteRootUrl;
authentication = new OAuth(endpointConfiguration.APIClientID, endpointConfiguration.APIClientSecret, Endpoint);
authentication = new OAuth(endpointConfiguration.APIClientID, endpointConfiguration.APIClientSecret, APIEndpointUrl);
log = Logger.GetLogger(LoggingTarget.Network);
ProvidedUsername = config.Get<string>(OsuSetting.Username);
@ -245,7 +248,7 @@ namespace osu.Game.Online.API
var req = new RegistrationRequest
{
Url = $@"{Endpoint}/users",
Url = $@"{APIEndpointUrl}/users",
Method = HttpMethod.Post,
Username = username,
Email = email,

View File

@ -57,7 +57,7 @@ namespace osu.Game.Online.API
protected virtual WebRequest CreateWebRequest() => new OsuWebRequest(Uri);
protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}";
protected virtual string Uri => $@"{API.APIEndpointUrl}/api/v2/{Target}";
protected APIAccess API;
protected WebRequest WebRequest;

View File

@ -28,7 +28,9 @@ namespace osu.Game.Online.API
public string ProvidedUsername => LocalUser.Value.Username;
public string Endpoint => "http://localhost";
public string APIEndpointUrl => "http://localhost";
public string WebsiteRootUrl => "http://localhost";
/// <summary>
/// Provide handling logic for an arbitrary API request.

View File

@ -46,7 +46,12 @@ namespace osu.Game.Online.API
/// <summary>
/// The URL endpoint for this API. Does not include a trailing slash.
/// </summary>
string Endpoint { get; }
string APIEndpointUrl { get; }
/// <summary>
/// The root URL of of the website, excluding the trailing slash.
/// </summary>
public string WebsiteRootUrl { get; }
/// <summary>
/// The current connection state of the API.

View File

@ -46,7 +46,7 @@ namespace osu.Game.Online.Chat
break;
}
var beatmapString = beatmap.OnlineBeatmapID.HasValue ? $"[https://osu.ppy.sh/b/{beatmap.OnlineBeatmapID} {beatmap}]" : beatmap.ToString();
var beatmapString = beatmap.OnlineBeatmapID.HasValue ? $"[{api.WebsiteRootUrl}/b/{beatmap.OnlineBeatmapID} {beatmap}]" : beatmap.ToString();
channelManager.PostMessage($"is {verb} {beatmapString}", true);
Expire();

View File

@ -7,11 +7,11 @@ namespace osu.Game.Online
{
public DevelopmentEndpointConfiguration()
{
APIEndpoint = @"https://dev.ppy.sh";
WebsiteRootUrl = APIEndpointUrl = @"https://dev.ppy.sh";
APIClientSecret = @"3LP2mhUrV89xxzD1YKNndXHEhWWCRLPNKioZ9ymT";
APIClientID = "5";
SpectatorEndpoint = $"{APIEndpoint}/spectator";
MultiplayerEndpoint = $"{APIEndpoint}/multiplayer";
SpectatorEndpointUrl = $"{APIEndpointUrl}/spectator";
MultiplayerEndpointUrl = $"{APIEndpointUrl}/multiplayer";
}
}
}

View File

@ -8,10 +8,15 @@ namespace osu.Game.Online
/// </summary>
public class EndpointConfiguration
{
/// <summary>
/// The base URL for the website.
/// </summary>
public string WebsiteRootUrl { get; set; }
/// <summary>
/// The endpoint for the main (osu-web) API.
/// </summary>
public string APIEndpoint { get; set; }
public string APIEndpointUrl { get; set; }
/// <summary>
/// The OAuth client secret.
@ -23,8 +28,14 @@ namespace osu.Game.Online
/// </summary>
public string APIClientID { get; set; }
public string SpectatorEndpoint { get; set; }
/// <summary>
/// The endpoint for the SignalR spectator server.
/// </summary>
public string SpectatorEndpointUrl { get; set; }
public string MultiplayerEndpoint { get; set; }
/// <summary>
/// The endpoint for the SignalR multiplayer server.
/// </summary>
public string MultiplayerEndpointUrl { get; set; }
}
}

View File

@ -7,11 +7,11 @@ namespace osu.Game.Online
{
public ProductionEndpointConfiguration()
{
APIEndpoint = @"https://osu.ppy.sh";
WebsiteRootUrl = APIEndpointUrl = @"https://osu.ppy.sh";
APIClientSecret = @"FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk";
APIClientID = "5";
SpectatorEndpoint = "https://spectator.ppy.sh/spectator";
MultiplayerEndpoint = "https://spectator.ppy.sh/multiplayer";
SpectatorEndpointUrl = "https://spectator.ppy.sh/spectator";
MultiplayerEndpointUrl = "https://spectator.ppy.sh/multiplayer";
}
}
}

View File

@ -33,7 +33,7 @@ namespace osu.Game.Online.RealtimeMultiplayer
public RealtimeMultiplayerClient(EndpointConfiguration endpoints)
{
endpoint = endpoints.MultiplayerEndpoint;
endpoint = endpoints.MultiplayerEndpointUrl;
}
[BackgroundDependencyLoader]

View File

@ -85,7 +85,7 @@ namespace osu.Game.Online.Spectator
public SpectatorStreamingClient(EndpointConfiguration endpoints)
{
endpoint = endpoints.SpectatorEndpoint;
endpoint = endpoints.SpectatorEndpointUrl;
}
[BackgroundDependencyLoader]

View File

@ -294,7 +294,7 @@ namespace osu.Game
public void OpenUrlExternally(string url) => waitForReady(() => externalLinkOpener, _ =>
{
if (url.StartsWith('/'))
url = $"{API.Endpoint}{url}";
url = $"{API.APIEndpointUrl}{url}";
externalLinkOpener.OpenUrlExternally(url);
});

View File

@ -15,6 +15,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Online.API;
using osu.Game.Overlays.BeatmapListing.Panels;
using osu.Game.Overlays.BeatmapSet.Buttons;
using osu.Game.Rulesets;
@ -40,6 +41,9 @@ namespace osu.Game.Overlays.BeatmapSet
public bool DownloadButtonsVisible => downloadButtonsContainer.Any();
[Resolved]
private IAPIProvider api { get; set; }
public BeatmapRulesetSelector RulesetSelector => beatmapSetHeader.RulesetSelector;
public readonly BeatmapPicker Picker;
@ -213,7 +217,7 @@ namespace osu.Game.Overlays.BeatmapSet
Picker.Beatmap.ValueChanged += b =>
{
Details.Beatmap = b.NewValue;
externalLink.Link = $@"https://osu.ppy.sh/beatmapsets/{BeatmapSet.Value?.OnlineBeatmapSetID}#{b.NewValue?.Ruleset.ShortName}/{b.NewValue?.OnlineBeatmapID}";
externalLink.Link = $@"{api.WebsiteRootUrl}/beatmapsets/{BeatmapSet.Value?.OnlineBeatmapSetID}#{b.NewValue?.Ruleset.ShortName}/{b.NewValue?.OnlineBeatmapID}";
};
}

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Users;
using osuTK;
using osuTK.Graphics;
@ -27,6 +28,9 @@ namespace osu.Game.Overlays.Profile.Header
private Color4 iconColour;
[Resolved]
private IAPIProvider api { get; set; }
public BottomHeaderContainer()
{
AutoSizeAxes = Axes.Y;
@ -109,7 +113,7 @@ namespace osu.Game.Overlays.Profile.Header
}
topLinkContainer.AddText("Contributed ");
topLinkContainer.AddLink($@"{user.PostCount:#,##0} forum posts", $"https://osu.ppy.sh/users/{user.Id}/posts", creationParameters: embolden);
topLinkContainer.AddLink($@"{user.PostCount:#,##0} forum posts", $"{api.WebsiteRootUrl}/users/{user.Id}/posts", creationParameters: embolden);
string websiteWithoutProtocol = user.Website;

View File

@ -10,6 +10,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Overlays.Profile.Header.Components;
using osu.Game.Users;
using osu.Game.Users.Drawables;
@ -23,6 +24,9 @@ namespace osu.Game.Overlays.Profile.Header
public readonly Bindable<User> User = new Bindable<User>();
[Resolved]
private IAPIProvider api { get; set; }
private SupporterIcon supporterTag;
private UpdateableAvatar avatar;
private OsuSpriteText usernameText;
@ -166,7 +170,7 @@ namespace osu.Game.Overlays.Profile.Header
{
avatar.User = user;
usernameText.Text = user?.Username ?? string.Empty;
openUserExternally.Link = $@"https://osu.ppy.sh/users/{user?.Id ?? 0}";
openUserExternally.Link = $@"{api.WebsiteRootUrl}/users/{user?.Id ?? 0}";
userFlag.Country = user?.Country;
userCountryText.Text = user?.Country?.FullName ?? "Alien";
supporterTag.SupportLevel = user?.SupportLevel ?? 0;

View File

@ -216,7 +216,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
private void addBeatmapsetLink()
=> content.AddLink(activity.Beatmapset?.Title, LinkAction.OpenBeatmapSet, getLinkArgument(activity.Beatmapset?.Url), creationParameters: t => t.Font = getLinkFont());
private string getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.Endpoint}{url}").Argument;
private string getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.APIEndpointUrl}{url}").Argument;
private FontUsage getLinkFont(FontWeight fontWeight = FontWeight.Regular)
=> OsuFont.GetFont(size: font_size, weight: fontWeight, italics: true);