Skip to content

Commit c6f8eab

Browse files
committed
Updated to latest EVEmon version with image support
Added ImagesController to handle requests for images Signed-off-by: Alexis Maiquez Murcia <[email protected]>
1 parent 552e915 commit c6f8eab

File tree

3 files changed

+113
-2
lines changed

3 files changed

+113
-2
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ logs/
1212
Database/apo15-mysql5-v1.sql
1313
Database/mapPrecalculatedSolarSystemJumps.sql
1414
Server/.idea
15-
Server/EVESharp.Orchestrator/appsettings.Development.json
15+
Server/EVESharp.Orchestrator/appsettings.Development.json
16+
Server/EVESharp.API/appsettings.Development.json
17+
Server/EVESharp.API/res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System.Data.Common;
2+
using EVESharp.Database;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace EVESharp.API.Controllers;
6+
7+
[ApiController]
8+
[Route ("/")]
9+
public class ImagesController : ControllerBase
10+
{
11+
private readonly IDatabase DB;
12+
13+
public ImagesController (IDatabase db)
14+
{
15+
DB = db;
16+
}
17+
18+
private string? ResolvePath (int size, int id)
19+
{
20+
while (size > 32)
21+
{
22+
string path = Path.Combine (Directory.GetCurrentDirectory (), $"res/types/{size}", $"{id}.png");
23+
24+
if (System.IO.File.Exists (path) == true)
25+
return path;
26+
27+
size >>= 1;
28+
}
29+
30+
return null;
31+
}
32+
33+
[Route ("images/characters/{size}/{id}")]
34+
[HttpGet]
35+
public IActionResult Characters (int size, int id)
36+
{
37+
// for now just return the file
38+
return PhysicalFile (Path.Combine (Directory.GetCurrentDirectory (), "res", "portrait.jpg"), "image/jpeg");
39+
}
40+
41+
[Route ("images/types/{size}/{id}")]
42+
[HttpGet]
43+
public IActionResult Types (int size, int id)
44+
{
45+
// first check if there's an image with the given size for the given itemID first
46+
// otherwise try to look up the icon in the database
47+
string? path = ResolvePath (size, id);
48+
49+
if (path is not null)
50+
return PhysicalFile (path, "image/png");
51+
52+
// check the database for the icon file
53+
DbDataReader reader = DB.Select (
54+
"SELECT icon FROM invTypes RIGHT JOIN eveGraphics USING (graphicID) WHERE typeID = @typeID;",
55+
new Dictionary <string, object> ()
56+
{
57+
{"@typeID", id}
58+
}
59+
);
60+
61+
if (reader.Read () == true)
62+
{
63+
string icon = reader.GetStringOrNull (0);
64+
65+
if (string.IsNullOrEmpty (icon) == false)
66+
{
67+
path = Path.Combine (Directory.GetCurrentDirectory (), "res/types/icons/", $"icon{icon}.png");
68+
69+
if (System.IO.File.Exists (path) == true)
70+
return PhysicalFile (path, "image/png");
71+
}
72+
}
73+
74+
// last resort, return a placeholder
75+
return PhysicalFile (Path.Combine (Directory.GetCurrentDirectory (), "res/types/placeholder.png"), "image/png");
76+
}
77+
78+
[Route("icons/{size}/{file}.png")]
79+
[HttpGet]
80+
public IActionResult OldIconsTanslate (string size, string file)
81+
{
82+
// trying to find an icon, locate it and return
83+
if (file.StartsWith ("icon") == true)
84+
{
85+
string path = Path.Combine (Directory.GetCurrentDirectory (), "res/types/icons/", $"{file}.png");
86+
87+
if (System.IO.File.Exists (path) == true)
88+
return PhysicalFile (path, "image/png");
89+
90+
return PhysicalFile (Path.Combine (Directory.GetCurrentDirectory (), "res/types/placeholder.png"), "image/png");
91+
}
92+
93+
// normal icon, parse sizes and call the better approach
94+
if (size.Contains ("_") == false)
95+
return BadRequest ();
96+
97+
string [] parts = size.Split ('_');
98+
99+
if (parts.Length == 0)
100+
return BadRequest ();
101+
if (int.TryParse (parts [0], out int sizeInt) == false)
102+
return BadRequest ();
103+
if (int.TryParse (file, out int typeID) == false)
104+
return BadRequest ();
105+
106+
// finally call the other endpoint
107+
return Types (sizeInt, typeID);
108+
}
109+
}

Tools/evemon

Submodule evemon updated 78 files

0 commit comments

Comments
 (0)