mirror of
https://github.com/bitwarden/server
synced 2026-01-02 00:23:40 +00:00
new icon fetching service. remove besticon dep.
This commit is contained in:
70
src/Icons/Models/IconResult.cs
Normal file
70
src/Icons/Models/IconResult.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
namespace Bit.Icons.Models
|
||||
{
|
||||
public class IconResult
|
||||
{
|
||||
public IconResult(string href, HtmlNode node)
|
||||
{
|
||||
Path = href;
|
||||
var sizesAttr = node.Attributes["sizes"];
|
||||
if(!string.IsNullOrWhiteSpace(sizesAttr?.Value))
|
||||
{
|
||||
var sizeParts = sizesAttr.Value.Split('x');
|
||||
if(sizeParts.Length == 2 && int.TryParse(sizeParts[0].Trim(), out var width) &&
|
||||
int.TryParse(sizeParts[1].Trim(), out var height))
|
||||
{
|
||||
DefinedWidth = width;
|
||||
DefinedHeight = height;
|
||||
|
||||
if(width == height)
|
||||
{
|
||||
if(width == 32)
|
||||
{
|
||||
Priority = 1;
|
||||
}
|
||||
else if(width == 64)
|
||||
{
|
||||
Priority = 2;
|
||||
}
|
||||
else if(width >= 24 && width <= 128)
|
||||
{
|
||||
Priority = 3;
|
||||
}
|
||||
else if(width == 16)
|
||||
{
|
||||
Priority = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
Priority = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(Priority == 0)
|
||||
{
|
||||
Priority = 200;
|
||||
}
|
||||
}
|
||||
|
||||
public IconResult(Uri uri, byte[] bytes, string format)
|
||||
{
|
||||
Path = uri.ToString();
|
||||
Icon = new Icon
|
||||
{
|
||||
Image = bytes,
|
||||
Format = format
|
||||
};
|
||||
Priority = 10;
|
||||
}
|
||||
|
||||
public string Path { get; set; }
|
||||
public int? DefinedWidth { get; set; }
|
||||
public int? DefinedHeight { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
public int Priority { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user