Added proxy for favicone api
This commit is contained in:
parent
ba31eeda04
commit
e1412eef52
|
@ -1,7 +1,8 @@
|
|||
@using Wave.Data
|
||||
@using System.Net
|
||||
|
||||
<a href="@Link.UrlString" rel="me" target="_blank" title="@Link.Url.Host" @attributes="AdditionalAttributes">
|
||||
<img src="@("https://favicone.com/" + Link.Url.Host + "?s=32")" alt="" width="32" height="32" class="w-5 h-5" />
|
||||
<img src="@("/api/proxy/favicon/" + WebUtility.UrlEncode(Link.Url.Host))" alt="" width="32" height="32" class="w-5 h-5" />
|
||||
@(Link.Url.Host.LastIndexOf('.') > -1 ? Link.Url.Host[..Link.Url.Host.LastIndexOf('.')] : Link.Url.Host)
|
||||
</a>
|
||||
|
||||
|
|
31
Wave/Controllers/ApiProxy.cs
Normal file
31
Wave/Controllers/ApiProxy.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Wave.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("/api/proxy")]
|
||||
public class ApiProxy(HttpClient client) : ControllerBase {
|
||||
private HttpClient Client { get; } = client;
|
||||
|
||||
[Route("favicon/{host}")]
|
||||
[Produces("image/x-icon")]
|
||||
[ResponseCache(Duration = 60*60*24*30, Location = ResponseCacheLocation.Any)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task GetFavicon(string host, [FromQuery] int size = 32) {
|
||||
var response = await DoProxy("https://favicone.com/" + host + "?s=" + size);
|
||||
|
||||
if (!response.IsSuccessStatusCode) {
|
||||
Response.StatusCode = StatusCodes.Status404NotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] data = await response.Content.ReadAsByteArrayAsync();
|
||||
await Response.BodyWriter.WriteAsync(data);
|
||||
}
|
||||
|
||||
|
||||
private async Task<HttpResponseMessage> DoProxy(string url) {
|
||||
return await Client.SendAsync(new HttpRequestMessage(HttpMethod.Get, url));
|
||||
}
|
||||
}
|
|
@ -101,6 +101,7 @@
|
|||
options.ResourcesPath = "Resources";
|
||||
});
|
||||
builder.Services.AddScoped<ImageService>();
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
builder.Services.Configure<Customization>(builder.Configuration.GetSection(nameof(Customization)));
|
||||
builder.Services.AddCascadingValue("TitlePrefix",
|
||||
|
|
Loading…
Reference in a new issue