feat: added platforms to the API
This commit is contained in:
@@ -24,7 +24,22 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
{
|
{
|
||||||
if (Id == 0)
|
if (Id == 0)
|
||||||
{
|
{
|
||||||
return null;
|
Game returnValue = new Game();
|
||||||
|
if ((Storage.GetCacheStatus("game", 0) == Storage.CacheStatus.NotPresent) || (forceRefresh == true))
|
||||||
|
{
|
||||||
|
returnValue = new Game
|
||||||
|
{
|
||||||
|
Id = 0,
|
||||||
|
Name = "Unknown"
|
||||||
|
};
|
||||||
|
Storage.NewCacheValue(returnValue);
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Storage.GetCacheValue<Game>(returnValue, "id", 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -26,7 +26,22 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
{
|
{
|
||||||
if (Id == 0)
|
if (Id == 0)
|
||||||
{
|
{
|
||||||
return null;
|
Platform returnValue = new Platform();
|
||||||
|
if (Storage.GetCacheStatus("platform", 0) == Storage.CacheStatus.NotPresent)
|
||||||
|
{
|
||||||
|
returnValue = new Platform
|
||||||
|
{
|
||||||
|
Id = 0,
|
||||||
|
Name = "Unknown"
|
||||||
|
};
|
||||||
|
Storage.NewCacheValue(returnValue);
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Storage.GetCacheValue<Platform>(returnValue, "id", 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
137
gaseous-server/Controllers/PlatformsController.cs
Normal file
137
gaseous-server/Controllers/PlatformsController.cs
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using gaseous_server.Classes.Metadata;
|
||||||
|
using gaseous_tools;
|
||||||
|
using IGDB.Models;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.CodeAnalysis.Scripting;
|
||||||
|
|
||||||
|
namespace gaseous_server.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/v1/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class PlatformsController : Controller
|
||||||
|
{
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(typeof(List<Platform>), StatusCodes.Status200OK)]
|
||||||
|
public ActionResult Platform()
|
||||||
|
{
|
||||||
|
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
|
|
||||||
|
string sql = "SELECT * FROM gaseous.platform WHERE id IN (SELECT DISTINCT platformid FROM games_roms) ORDER BY `name` ASC;";
|
||||||
|
|
||||||
|
List<Platform> RetVal = new List<Platform>();
|
||||||
|
|
||||||
|
DataTable dbResponse = db.ExecuteCMD(sql);
|
||||||
|
foreach (DataRow dr in dbResponse.Rows)
|
||||||
|
{
|
||||||
|
RetVal.Add(Classes.Metadata.Platforms.GetPlatform((long)dr["id"]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(RetVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{PlatformId}")]
|
||||||
|
[ProducesResponseType(typeof(Platform), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public ActionResult Platform(long PlatformId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IGDB.Models.Platform platformObject = Classes.Metadata.Platforms.GetPlatform(PlatformId);
|
||||||
|
|
||||||
|
if (platformObject != null)
|
||||||
|
{
|
||||||
|
return Ok(platformObject);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{PlatformId}/platformlogo")]
|
||||||
|
[ProducesResponseType(typeof(PlatformLogo), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public ActionResult PlatformLogo(long PlatformId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IGDB.Models.Platform platformObject = Classes.Metadata.Platforms.GetPlatform(PlatformId);
|
||||||
|
if (platformObject != null)
|
||||||
|
{
|
||||||
|
IGDB.Models.PlatformLogo logoObject = PlatformLogos.GetPlatformLogo(platformObject.PlatformLogo.Id, Config.LibraryConfiguration.LibraryMetadataDirectory_Platform(platformObject));
|
||||||
|
if (logoObject != null)
|
||||||
|
{
|
||||||
|
return Ok(logoObject);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{PlatformId}/platformlogo/image")]
|
||||||
|
[ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public ActionResult PlatformLogoImage(long PlatformId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IGDB.Models.Platform platformObject = Classes.Metadata.Platforms.GetPlatform(PlatformId);
|
||||||
|
|
||||||
|
string logoFilePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Platform(platformObject), "Logo_Medium.png");
|
||||||
|
if (System.IO.File.Exists(logoFilePath))
|
||||||
|
{
|
||||||
|
string filename = "Logo.png";
|
||||||
|
string filepath = logoFilePath;
|
||||||
|
byte[] filedata = System.IO.File.ReadAllBytes(filepath);
|
||||||
|
string contentType = "image/png";
|
||||||
|
|
||||||
|
var cd = new System.Net.Mime.ContentDisposition
|
||||||
|
{
|
||||||
|
FileName = filename,
|
||||||
|
Inline = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
Response.Headers.Add("Content-Disposition", cd.ToString());
|
||||||
|
|
||||||
|
return File(filedata, contentType);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -59,6 +59,10 @@ app.MapControllers();
|
|||||||
// setup library directories
|
// setup library directories
|
||||||
Config.LibraryConfiguration.InitLibrary();
|
Config.LibraryConfiguration.InitLibrary();
|
||||||
|
|
||||||
|
// insert unknown platform and game if not present
|
||||||
|
gaseous_server.Classes.Metadata.Games.GetGame(0, false, true);
|
||||||
|
gaseous_server.Classes.Metadata.Platforms.GetPlatform(0);
|
||||||
|
|
||||||
// organise library
|
// organise library
|
||||||
//gaseous_server.Classes.ImportGame.OrganiseLibrary();
|
//gaseous_server.Classes.ImportGame.OrganiseLibrary();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user