1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 09:42:54 +08:00
This commit is contained in:
Salman Alshamrani 2024-12-03 17:38:41 +09:00 committed by GitHub
commit 8d19337ac2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 89 additions and 4 deletions

View File

@ -0,0 +1,47 @@
// 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 NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Game.Graphics.Containers.Markdown;
namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneImageProxying : OsuTestScene
{
[Resolved]
private GameHost host { get; set; } = null!;
[Test]
public void TestExternalImageLink()
{
AddStep("load image", () => Child = new OsuMarkdownContainer
{
RelativeSizeAxes = Axes.Both,
Text = "![](https://github.com/ppy/osu-wiki/blob/master/wiki/Announcement_messages/img/notification.png?raw=true)",
});
}
[Test]
public void TestLocalImageLink()
{
AddStep("load image", () => Child = new OsuMarkdownContainer
{
RelativeSizeAxes = Axes.Both,
Text = "![](https://osu.ppy.sh/help/wiki/shared/news/banners/monthly-beatmapping-contest.png)",
});
}
[Test]
public void TestInvalidImageLink()
{
AddStep("load image", () => Child = new OsuMarkdownContainer
{
RelativeSizeAxes = Axes.Both,
Text = "![](https://this-site-does-not-exist.com/img.png)",
});
}
}
}

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>

View File

@ -17,5 +17,8 @@ namespace osu.Game.Graphics.Containers.Markdown
{
TooltipText = linkInline.Title;
}
protected override ImageContainer CreateImageContainer(string url)
=> base.CreateImageContainer($@"https://osu.ppy.sh/media-url?url={url}");
}
}

View File

@ -0,0 +1,31 @@
// 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;
using osu.Framework.Logging;
namespace osu.Game.Online
{
public class OsuOnlineStore : OnlineStore
{
private readonly string apiEndpointUrl;
public OsuOnlineStore(string apiEndpointUrl)
{
this.apiEndpointUrl = apiEndpointUrl;
}
protected override string GetLookupUrl(string url)
{
// add leading dot to avoid matching hosts named "<anything>ppy.sh"
if (!Uri.TryCreate(url, UriKind.Absolute, out Uri? uri) || !uri.Host.EndsWith(@".ppy.sh", StringComparison.OrdinalIgnoreCase))
{
Logger.Log($@"Blocking resource lookup from external website: {url}", LoggingTarget.Network, LogLevel.Important);
return string.Empty;
}
return url;
}
}
}

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;
@ -824,6 +825,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)

View File

@ -277,7 +277,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);