1
0
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:
Kyle Spearrin
2018-05-22 12:49:34 -04:00
parent 60bb4d466c
commit 0e4ffc7d7f
11 changed files with 357 additions and 115 deletions

View 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; }
}
}