1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-08 03:43:39 +08:00

Add OsuOnlineStore for proxying external media lookups

This commit is contained in:
Salman Alshamrani
2024-11-24 21:46:33 -05:00
Unverified
parent c34827a4ed
commit 2417d4de83
4 changed files with 37 additions and 4 deletions
+4 -3
View File
@@ -6,9 +6,10 @@ using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.Online;
using osu.Game.Online.API;
namespace osu.Game.Audio
{
@@ -28,9 +29,9 @@ namespace osu.Game.Audio
}
[BackgroundDependencyLoader]
private void load(AudioManager audioManager)
private void load(AudioManager audioManager, IAPIProvider api)
{
trackStore = audioManager.GetTrackStore(new OnlineStore());
trackStore = audioManager.GetTrackStore(new OsuOnlineStore(api.APIEndpointUrl));
}
/// <summary>
+29
View File
@@ -0,0 +1,29 @@
// 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 osu.Framework.IO.Stores;
namespace osu.Game.Online
{
/// <summary>
/// An <see cref="OnlineStore"/> which proxies external media lookups through osu-web.
/// </summary>
public class OsuOnlineStore : OnlineStore
{
private readonly string apiEndpointUrl;
public OsuOnlineStore(string apiEndpointUrl)
{
this.apiEndpointUrl = apiEndpointUrl;
}
protected override string GetLookupUrl(string url)
{
if (Uri.TryCreate(url, UriKind.Absolute, out Uri? uri) && uri.Host.EndsWith(@".ppy.sh", StringComparison.OrdinalIgnoreCase))
return url;
return $@"{apiEndpointUrl}/beatmapsets/discussions/media-url?url={url}";
}
}
}
+3
View File
@@ -29,6 +29,7 @@ using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.IO.Stores;
using osu.Framework.Localisation;
using osu.Framework.Logging;
using osu.Framework.Platform;
@@ -819,6 +820,8 @@ namespace osu.Game
protected override Container CreateScalingContainer() => new ScalingContainer(ScalingMode.Everything);
protected override OnlineStore CreateOnlineStore() => new OsuOnlineStore(CreateEndpoints().APIEndpointUrl);
#region Beatmap progression
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> beatmap)
+1 -1
View File
@@ -279,7 +279,7 @@ namespace osu.Game
dependencies.CacheAs(Storage);
var largeStore = new LargeTextureStore(Host.Renderer, Host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(Resources, @"Textures")));
largeStore.AddTextureSource(Host.CreateTextureLoaderStore(new OnlineStore()));
largeStore.AddTextureSource(Host.CreateTextureLoaderStore(CreateOnlineStore()));
dependencies.Cache(largeStore);
dependencies.CacheAs(LocalConfig);