mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-24 08:17:57 -04:00
Update favicon display in client to handle SVG (#622)
This commit is contained in:
@@ -56,5 +56,5 @@ The following websites have been known to cause issues in the past (but should b
|
||||
| --- | --- |
|
||||
| https://www.paprika-shopping.nl/nieuwsbrief/newsletter-register-landing.html | Popup CSS style conflicts |
|
||||
| https://bloshing.com/inschrijven-nieuwsbrief | Popup CSS style conflicts |
|
||||
| https://gamefaqs.gamespot.com/user | Popup buttons not working |
|
||||
| https://news.ycombinator.com/login?goto=news | Popup logo not showing due to SVG format after identity creation |
|
||||
| https://gamefaqs.gamespot.com/user | Popup buttons not working |
|
||||
| https://news.ycombinator.com/login?goto=news | Popup and client favicon not showing due to SVG format |
|
||||
|
||||
@@ -26,6 +26,9 @@ else
|
||||
[Parameter]
|
||||
public bool Padding { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The data URL of the favicon.
|
||||
/// </summary>
|
||||
private string? _faviconDataUrl;
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -33,8 +36,46 @@ else
|
||||
{
|
||||
if (FaviconBytes is not null)
|
||||
{
|
||||
string mimeType = DetectMimeType(FaviconBytes);
|
||||
string base64String = Convert.ToBase64String(FaviconBytes);
|
||||
_faviconDataUrl = $"data:image/x-icon;base64,{base64String}";
|
||||
_faviconDataUrl = $"data:{mimeType};base64,{base64String}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detect the mime type of the favicon.
|
||||
/// </summary>
|
||||
/// <param name="bytes">The bytes of the favicon.</param>
|
||||
/// <returns>The mime type of the favicon.</returns>
|
||||
private string DetectMimeType(byte[] bytes)
|
||||
{
|
||||
// Check for SVG.
|
||||
if (bytes.Length >= 5)
|
||||
{
|
||||
string header = System.Text.Encoding.ASCII.GetString(bytes.Take(5).ToArray()).ToLower();
|
||||
if (header.Contains("<?xml") || header.Contains("<svg"))
|
||||
{
|
||||
return "image/svg+xml";
|
||||
}
|
||||
}
|
||||
|
||||
// Check for ICO.
|
||||
if (bytes.Length >= 4 &&
|
||||
bytes[0] == 0x00 && bytes[1] == 0x00 &&
|
||||
bytes[2] == 0x01 && bytes[3] == 0x00)
|
||||
{
|
||||
return "image/x-icon";
|
||||
}
|
||||
|
||||
// Check for PNG.
|
||||
if (bytes.Length >= 4 &&
|
||||
bytes[0] == 0x89 && bytes[1] == 0x50 &&
|
||||
bytes[2] == 0x4E && bytes[3] == 0x47)
|
||||
{
|
||||
return "image/png";
|
||||
}
|
||||
|
||||
// Default to x-icon if unknown.
|
||||
return "image/x-icon";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user