1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:52:56 +08:00

change image url replace implementation

This commit is contained in:
Gagah Pangeran Rosfatiputra 2021-05-26 15:10:09 +07:00
parent 71f77eb902
commit 9c31b8856d
No known key found for this signature in database
GPG Key ID: 25F6F17FD29031E2

View File

@ -2,37 +2,28 @@
// See the LICENCE file in the repository root for full licence text.
using Markdig.Syntax.Inlines;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Containers.Markdown;
using osu.Framework.Graphics.Cursor;
using osu.Game.Online.API;
namespace osu.Game.Overlays.Wiki.Markdown
{
public class WikiMarkdownImage : MarkdownImage, IHasTooltip
{
private readonly string url;
public string TooltipText { get; }
public WikiMarkdownImage(LinkInline linkInline)
: base(linkInline.Url)
{
url = linkInline.Url;
TooltipText = linkInline.Title;
}
[BackgroundDependencyLoader]
private void load(IAPIProvider api)
protected override ImageContainer CreateImageContainer(string url)
{
// The idea is replace "{api.WebsiteRootUrl}/wiki/{path-to-image}" to "{api.WebsiteRootUrl}/wiki/images/{path-to-image}"
// The idea is replace "https://website.url/wiki/{path-to-image}" to "https://website.url/wiki/images/{path-to-image}"
// "/wiki/images/*" is route to fetch wiki image from osu!web server (see: https://github.com/ppy/osu-web/blob/4205eb66a4da86bdee7835045e4bf28c35456e04/routes/web.php#L289)
// Currently all image in dev server (https://dev.ppy.sh/wiki/image/*) is 404
// So for now just replace "{api.WebsiteRootUrl}/wiki/*" to "https://osu.ppy.sh/wiki/images/*" for simplicity
var imageUrl = url.Replace($"{api.WebsiteRootUrl}/wiki", "https://osu.ppy.sh/wiki/images");
url = url.Replace("/wiki/", "/wiki/images/");
InternalChild = new DelayedLoadWrapper(CreateImageContainer(imageUrl));
return base.CreateImageContainer(url);
}
}
}