refactor: sped up game list loading code, plus many small bug fixes

This commit is contained in:
Michael Green
2023-06-27 23:31:29 +10:00
parent 3f269d802b
commit ee4e5d4037
12 changed files with 315 additions and 210 deletions

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Data;
using gaseous_tools; using gaseous_tools;
using IGDB; using IGDB;
using IGDB.Models; using IGDB.Models;
@@ -25,7 +26,7 @@ namespace gaseous_server.Classes.Metadata
if (Id == 0) if (Id == 0)
{ {
Game returnValue = new Game(); Game returnValue = new Game();
if ((Storage.GetCacheStatus("game", 0) == Storage.CacheStatus.NotPresent) || (forceRefresh == true)) if (Storage.GetCacheStatus("game", 0) == Storage.CacheStatus.NotPresent)
{ {
returnValue = new Game returnValue = new Game
{ {
@@ -55,6 +56,11 @@ namespace gaseous_server.Classes.Metadata
return RetVal.Result; return RetVal.Result;
} }
public static Game GetGame(DataRow dataRow)
{
return Storage.BuildCacheObject<Game>(new Game(), dataRow);
}
private static async Task<Game> _GetGame(SearchUsing searchUsing, object searchValue, bool followSubGames = false, bool forceRefresh = false) private static async Task<Game> _GetGame(SearchUsing searchUsing, object searchValue, bool followSubGames = false, bool forceRefresh = false)
{ {
// check database first // check database first
@@ -229,6 +235,9 @@ namespace gaseous_server.Classes.Metadata
searchBody += "fields id,name,slug,platforms,summary; "; searchBody += "fields id,name,slug,platforms,summary; ";
switch (searchType) switch (searchType)
{ {
case SearchType.searchNoPlatform:
searchBody += "search \"" + SearchString + "\"; ";
break;
case SearchType.search: case SearchType.search:
searchBody += "search \"" + SearchString + "\"; "; searchBody += "search \"" + SearchString + "\"; ";
searchBody += "where platforms = (" + PlatformId + ");"; searchBody += "where platforms = (" + PlatformId + ");";
@@ -252,7 +261,8 @@ namespace gaseous_server.Classes.Metadata
{ {
where = 0, where = 0,
wherefuzzy = 1, wherefuzzy = 1,
search = 2 search = 2,
searchNoPlatform = 3
} }
} }
} }

View File

@@ -26,6 +26,26 @@ namespace gaseous_server.Classes.Metadata
return _GetCacheStatus(Endpoint, "id", Id); return _GetCacheStatus(Endpoint, "id", Id);
} }
public static CacheStatus GetCacheStatus(DataRow Row)
{
if (Row.Table.Columns.Contains("lastUpdated"))
{
DateTime CacheExpiryTime = DateTime.UtcNow.AddHours(-168);
if ((DateTime)Row["lastUpdated"] < CacheExpiryTime)
{
return CacheStatus.Expired;
}
else
{
return CacheStatus.Current;
}
}
else
{
throw new Exception("No lastUpdated column!");
}
}
private static CacheStatus _GetCacheStatus(string Endpoint, string SearchField, object SearchValue) private static CacheStatus _GetCacheStatus(string Endpoint, string SearchField, object SearchValue)
{ {
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
@@ -161,189 +181,194 @@ namespace gaseous_server.Classes.Metadata
else else
{ {
DataRow dataRow = dt.Rows[0]; DataRow dataRow = dt.Rows[0];
foreach (PropertyInfo property in EndpointType.GetType().GetProperties()) return BuildCacheObject<T>(EndpointType, dataRow);
{
if (dataRow.Table.Columns.Contains(property.Name))
{
if (dataRow[property.Name] != DBNull.Value)
{
string objectTypeName = property.PropertyType.Name.ToLower().Split("`")[0];
string subObjectTypeName = "";
object? objectToStore = null;
if (objectTypeName == "nullable")
{
objectTypeName = property.PropertyType.UnderlyingSystemType.ToString().Split("`1")[1].Replace("[System.", "").Replace("]", "").ToLower();
}
try
{
switch (objectTypeName)
{
case "datetimeoffset":
DateTimeOffset? storedDate = (DateTime?)dataRow[property.Name];
property.SetValue(EndpointType, storedDate);
break;
//case "nullable":
// Console.WriteLine("Nullable: " + property.PropertyType.UnderlyingSystemType);
// break;
case "identityorvalue":
subObjectTypeName = property.PropertyType.UnderlyingSystemType.ToString().Split("`1")[1].Replace("[IGDB.Models.", "").Replace("]", "").ToLower();
switch (subObjectTypeName)
{
case "collection":
objectToStore = new IdentityOrValue<Collection>(id: (long)dataRow[property.Name]);
break;
case "cover":
objectToStore = new IdentityOrValue<Cover>(id: (long)dataRow[property.Name]);
break;
case "franchise":
objectToStore = new IdentityOrValue<Franchise>(id: (long)dataRow[property.Name]);
break;
case "game":
objectToStore = new IdentityOrValue<Game>(id: (long)dataRow[property.Name]);
break;
case "platformfamily":
objectToStore = new IdentityOrValue<PlatformFamily>(id: (long)dataRow[property.Name]);
break;
case "platformlogo":
objectToStore = new IdentityOrValue<PlatformLogo>(id: (long)dataRow[property.Name]);
break;
case "platformversioncompany":
objectToStore = new IdentityOrValue<PlatformVersionCompany>(id: (long)dataRow[property.Name]);
break;
}
if (objectToStore != null)
{
property.SetValue(EndpointType, objectToStore);
}
break;
case "identitiesorvalues":
subObjectTypeName = property.PropertyType.UnderlyingSystemType.ToString().Split("`1")[1].Replace("[IGDB.Models.", "").Replace("]", "").ToLower();
long[] fromJsonObject = Newtonsoft.Json.JsonConvert.DeserializeObject<long[]>((string)dataRow[property.Name]);
switch (subObjectTypeName)
{
case "agerating":
objectToStore = new IdentitiesOrValues<AgeRating>(ids: fromJsonObject);
break;
case "alternativename":
objectToStore = new IdentitiesOrValues<AlternativeName>(ids: fromJsonObject);
break;
case "artwork":
objectToStore = new IdentitiesOrValues<Artwork>(ids: fromJsonObject);
break;
case "ageratingcontentdescription":
objectToStore = new IdentitiesOrValues<AgeRatingContentDescription>(ids: fromJsonObject);
break;
case "game":
objectToStore = new IdentitiesOrValues<Game>(ids: fromJsonObject);
break;
case "externalgame":
objectToStore = new IdentitiesOrValues<ExternalGame>(ids: fromJsonObject);
break;
case "franchise":
objectToStore = new IdentitiesOrValues<Franchise>(ids: fromJsonObject);
break;
case "gameengine":
objectToStore = new IdentitiesOrValues<GameEngine>(ids: fromJsonObject);
break;
case "gamemode":
objectToStore = new IdentitiesOrValues<GameMode>(ids: fromJsonObject);
break;
case "gamevideo":
objectToStore = new IdentitiesOrValues<GameVideo>(ids: fromJsonObject);
break;
case "genre":
objectToStore = new IdentitiesOrValues<Genre>(ids: fromJsonObject);
break;
case "involvedcompany":
objectToStore = new IdentitiesOrValues<InvolvedCompany>(ids: fromJsonObject);
break;
case "multiplayermode":
objectToStore = new IdentitiesOrValues<MultiplayerMode>(ids: fromJsonObject);
break;
case "platform":
objectToStore = new IdentitiesOrValues<Platform>(ids: fromJsonObject);
break;
case "platformversion":
objectToStore = new IdentitiesOrValues<PlatformVersion>(ids: fromJsonObject);
break;
case "platformwebsite":
objectToStore = new IdentitiesOrValues<PlatformWebsite>(ids: fromJsonObject);
break;
case "platformversioncompany":
objectToStore = new IdentitiesOrValues<PlatformVersionCompany>(ids: fromJsonObject);
break;
case "platformversionreleasedate":
objectToStore = new IdentitiesOrValues<PlatformVersionReleaseDate>(ids: fromJsonObject);
break;
case "playerperspective":
objectToStore = new IdentitiesOrValues<PlayerPerspective>(ids: fromJsonObject);
break;
case "releasedate":
objectToStore = new IdentitiesOrValues<ReleaseDate>(ids: fromJsonObject);
break;
case "screenshot":
objectToStore = new IdentitiesOrValues<Screenshot>(ids: fromJsonObject);
break;
case "theme":
objectToStore = new IdentitiesOrValues<Theme>(ids: fromJsonObject);
break;
case "website":
objectToStore = new IdentitiesOrValues<Website>(ids: fromJsonObject);
break;
}
if (objectToStore != null)
{
property.SetValue(EndpointType, objectToStore);
}
break;
case "int32[]":
Int32[] fromJsonObject_int32Array = Newtonsoft.Json.JsonConvert.DeserializeObject<Int32[]>((string)dataRow[property.Name]);
if (fromJsonObject_int32Array != null)
{
property.SetValue(EndpointType, fromJsonObject_int32Array);
}
break;
case "[igdb.models.category":
property.SetValue(EndpointType, (Category)dataRow[property.Name]);
break;
case "[igdb.models.gamestatus":
property.SetValue(EndpointType, (GameStatus)dataRow[property.Name]);
break;
case "[igdb.models.ageratingcategory":
property.SetValue(EndpointType, (AgeRatingCategory)dataRow[property.Name]);
break;
case "[igdb.models.ageratingcontentdescriptioncategory":
property.SetValue(EndpointType, (AgeRatingContentDescriptionCategory)dataRow[property.Name]);
break;
case "[igdb.models.ageratingtitle":
property.SetValue(EndpointType, (AgeRatingTitle)dataRow[property.Name]);
break;
case "[igdb.models.externalcategory":
property.SetValue(EndpointType, (ExternalCategory)dataRow[property.Name]);
break;
default:
property.SetValue(EndpointType, dataRow[property.Name]);
break;
}
}
catch (Exception ex)
{
Console.WriteLine("Error occurred in column " + property.Name);
Console.WriteLine(ex.ToString());
}
}
}
}
return EndpointType;
} }
}
public static T BuildCacheObject<T>(T EndpointType, DataRow dataRow)
{
foreach (PropertyInfo property in EndpointType.GetType().GetProperties())
{
if (dataRow.Table.Columns.Contains(property.Name))
{
if (dataRow[property.Name] != DBNull.Value)
{
string objectTypeName = property.PropertyType.Name.ToLower().Split("`")[0];
string subObjectTypeName = "";
object? objectToStore = null;
if (objectTypeName == "nullable")
{
objectTypeName = property.PropertyType.UnderlyingSystemType.ToString().Split("`1")[1].Replace("[System.", "").Replace("]", "").ToLower();
}
try
{
switch (objectTypeName)
{
case "datetimeoffset":
DateTimeOffset? storedDate = (DateTime?)dataRow[property.Name];
property.SetValue(EndpointType, storedDate);
break;
//case "nullable":
// Console.WriteLine("Nullable: " + property.PropertyType.UnderlyingSystemType);
// break;
case "identityorvalue":
subObjectTypeName = property.PropertyType.UnderlyingSystemType.ToString().Split("`1")[1].Replace("[IGDB.Models.", "").Replace("]", "").ToLower();
switch (subObjectTypeName)
{
case "collection":
objectToStore = new IdentityOrValue<Collection>(id: (long)dataRow[property.Name]);
break;
case "cover":
objectToStore = new IdentityOrValue<Cover>(id: (long)dataRow[property.Name]);
break;
case "franchise":
objectToStore = new IdentityOrValue<Franchise>(id: (long)dataRow[property.Name]);
break;
case "game":
objectToStore = new IdentityOrValue<Game>(id: (long)dataRow[property.Name]);
break;
case "platformfamily":
objectToStore = new IdentityOrValue<PlatformFamily>(id: (long)dataRow[property.Name]);
break;
case "platformlogo":
objectToStore = new IdentityOrValue<PlatformLogo>(id: (long)dataRow[property.Name]);
break;
case "platformversioncompany":
objectToStore = new IdentityOrValue<PlatformVersionCompany>(id: (long)dataRow[property.Name]);
break;
}
if (objectToStore != null)
{
property.SetValue(EndpointType, objectToStore);
}
break;
case "identitiesorvalues":
subObjectTypeName = property.PropertyType.UnderlyingSystemType.ToString().Split("`1")[1].Replace("[IGDB.Models.", "").Replace("]", "").ToLower();
long[] fromJsonObject = Newtonsoft.Json.JsonConvert.DeserializeObject<long[]>((string)dataRow[property.Name]);
switch (subObjectTypeName)
{
case "agerating":
objectToStore = new IdentitiesOrValues<AgeRating>(ids: fromJsonObject);
break;
case "alternativename":
objectToStore = new IdentitiesOrValues<AlternativeName>(ids: fromJsonObject);
break;
case "artwork":
objectToStore = new IdentitiesOrValues<Artwork>(ids: fromJsonObject);
break;
case "ageratingcontentdescription":
objectToStore = new IdentitiesOrValues<AgeRatingContentDescription>(ids: fromJsonObject);
break;
case "game":
objectToStore = new IdentitiesOrValues<Game>(ids: fromJsonObject);
break;
case "externalgame":
objectToStore = new IdentitiesOrValues<ExternalGame>(ids: fromJsonObject);
break;
case "franchise":
objectToStore = new IdentitiesOrValues<Franchise>(ids: fromJsonObject);
break;
case "gameengine":
objectToStore = new IdentitiesOrValues<GameEngine>(ids: fromJsonObject);
break;
case "gamemode":
objectToStore = new IdentitiesOrValues<GameMode>(ids: fromJsonObject);
break;
case "gamevideo":
objectToStore = new IdentitiesOrValues<GameVideo>(ids: fromJsonObject);
break;
case "genre":
objectToStore = new IdentitiesOrValues<Genre>(ids: fromJsonObject);
break;
case "involvedcompany":
objectToStore = new IdentitiesOrValues<InvolvedCompany>(ids: fromJsonObject);
break;
case "multiplayermode":
objectToStore = new IdentitiesOrValues<MultiplayerMode>(ids: fromJsonObject);
break;
case "platform":
objectToStore = new IdentitiesOrValues<Platform>(ids: fromJsonObject);
break;
case "platformversion":
objectToStore = new IdentitiesOrValues<PlatformVersion>(ids: fromJsonObject);
break;
case "platformwebsite":
objectToStore = new IdentitiesOrValues<PlatformWebsite>(ids: fromJsonObject);
break;
case "platformversioncompany":
objectToStore = new IdentitiesOrValues<PlatformVersionCompany>(ids: fromJsonObject);
break;
case "platformversionreleasedate":
objectToStore = new IdentitiesOrValues<PlatformVersionReleaseDate>(ids: fromJsonObject);
break;
case "playerperspective":
objectToStore = new IdentitiesOrValues<PlayerPerspective>(ids: fromJsonObject);
break;
case "releasedate":
objectToStore = new IdentitiesOrValues<ReleaseDate>(ids: fromJsonObject);
break;
case "screenshot":
objectToStore = new IdentitiesOrValues<Screenshot>(ids: fromJsonObject);
break;
case "theme":
objectToStore = new IdentitiesOrValues<Theme>(ids: fromJsonObject);
break;
case "website":
objectToStore = new IdentitiesOrValues<Website>(ids: fromJsonObject);
break;
}
if (objectToStore != null)
{
property.SetValue(EndpointType, objectToStore);
}
break;
case "int32[]":
Int32[] fromJsonObject_int32Array = Newtonsoft.Json.JsonConvert.DeserializeObject<Int32[]>((string)dataRow[property.Name]);
if (fromJsonObject_int32Array != null)
{
property.SetValue(EndpointType, fromJsonObject_int32Array);
}
break;
case "[igdb.models.category":
property.SetValue(EndpointType, (Category)dataRow[property.Name]);
break;
case "[igdb.models.gamestatus":
property.SetValue(EndpointType, (GameStatus)dataRow[property.Name]);
break;
case "[igdb.models.ageratingcategory":
property.SetValue(EndpointType, (AgeRatingCategory)dataRow[property.Name]);
break;
case "[igdb.models.ageratingcontentdescriptioncategory":
property.SetValue(EndpointType, (AgeRatingContentDescriptionCategory)dataRow[property.Name]);
break;
case "[igdb.models.ageratingtitle":
property.SetValue(EndpointType, (AgeRatingTitle)dataRow[property.Name]);
break;
case "[igdb.models.externalcategory":
property.SetValue(EndpointType, (ExternalCategory)dataRow[property.Name]);
break;
default:
property.SetValue(EndpointType, dataRow[property.Name]);
break;
}
}
catch (Exception ex)
{
Console.WriteLine("Error occurred in column " + property.Name);
Console.WriteLine(ex.ToString());
}
}
}
}
return EndpointType;
} }
} }
} }

View File

@@ -16,6 +16,7 @@ namespace gaseous_server.Controllers
{ {
[HttpGet] [HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ResponseCache(CacheProfileName = "5Minute")]
public Dictionary<string, object> Filter() public Dictionary<string, object> Filter()
{ {
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);

View File

@@ -111,14 +111,15 @@ namespace gaseous_server.Controllers
} }
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT DISTINCT games_roms.gameid AS ROMGameId, game.ageratings, game.aggregatedrating, game.aggregatedratingcount, game.alternativenames, game.artworks, game.bundles, game.category, game.collection, game.cover, game.dlcs, game.expansions, game.externalgames, game.firstreleasedate, game.`follows`, game.franchise, game.franchises, game.gameengines, game.gamemodes, game.genres, game.hypes, game.involvedcompanies, game.keywords, game.multiplayermodes, game.`name`, game.parentgame, game.platforms, game.playerperspectives, game.rating, game.ratingcount, game.releasedates, game.screenshots, game.similargames, game.slug, game.standaloneexpansions, game.`status`, game.storyline, game.summary, game.tags, game.themes, game.totalrating, game.totalratingcount, game.versionparent, game.versiontitle, game.videos, game.websites FROM gaseous.games_roms LEFT JOIN game ON game.id = games_roms.gameid " + whereClause + " " + havingClause + " " + orderByClause; string sql = "SELECT DISTINCT games_roms.gameid AS ROMGameId, game.id, game.ageratings, game.aggregatedrating, game.aggregatedratingcount, game.alternativenames, game.artworks, game.bundles, game.category, game.collection, game.cover, game.dlcs, game.expansions, game.externalgames, game.firstreleasedate, game.`follows`, game.franchise, game.franchises, game.gameengines, game.gamemodes, game.genres, game.hypes, game.involvedcompanies, game.keywords, game.multiplayermodes, game.`name`, game.parentgame, game.platforms, game.playerperspectives, game.rating, game.ratingcount, game.releasedates, game.screenshots, game.similargames, game.slug, game.standaloneexpansions, game.`status`, game.storyline, game.summary, game.tags, game.themes, game.totalrating, game.totalratingcount, game.versionparent, game.versiontitle, game.videos, game.websites FROM gaseous.games_roms LEFT JOIN game ON game.id = games_roms.gameid " + whereClause + " " + havingClause + " " + orderByClause;
List<IGDB.Models.Game> RetVal = new List<IGDB.Models.Game>(); List<IGDB.Models.Game> RetVal = new List<IGDB.Models.Game>();
DataTable dbResponse = db.ExecuteCMD(sql, whereParams); DataTable dbResponse = db.ExecuteCMD(sql, whereParams);
foreach (DataRow dr in dbResponse.Rows) foreach (DataRow dr in dbResponse.Rows)
{ {
RetVal.Add(Classes.Metadata.Games.GetGame((long)dr["ROMGameId"], false, false)); //RetVal.Add(Classes.Metadata.Games.GetGame((long)dr["ROMGameId"], false, false));
RetVal.Add(Classes.Metadata.Games.GetGame(dr));
} }
return Ok(RetVal); return Ok(RetVal);
@@ -128,6 +129,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}")] [Route("{GameId}")]
[ProducesResponseType(typeof(Game), StatusCodes.Status200OK)] [ProducesResponseType(typeof(Game), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "5Minute")]
public ActionResult Game(long GameId, bool forceRefresh = false) public ActionResult Game(long GameId, bool forceRefresh = false)
{ {
try try
@@ -153,6 +155,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/alternativename")] [Route("{GameId}/alternativename")]
[ProducesResponseType(typeof(List<AlternativeName>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(List<AlternativeName>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameAlternativeNames(long GameId) public ActionResult GameAlternativeNames(long GameId)
{ {
try try
@@ -183,6 +186,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/agerating")] [Route("{GameId}/agerating")]
[ProducesResponseType(typeof(List<AgeRatings.GameAgeRating>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(List<AgeRatings.GameAgeRating>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameAgeClassification(long GameId) public ActionResult GameAgeClassification(long GameId)
{ {
try try
@@ -275,6 +279,7 @@ namespace gaseous_server.Controllers
}; };
Response.Headers.Add("Content-Disposition", cd.ToString()); Response.Headers.Add("Content-Disposition", cd.ToString());
Response.Headers.Add("Cache-Control", "public, max-age=604800");
return File(filedata, contentType); return File(filedata, contentType);
} }
@@ -291,6 +296,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/artwork")] [Route("{GameId}/artwork")]
[ProducesResponseType(typeof(List<Artwork>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(List<Artwork>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameArtwork(long GameId) public ActionResult GameArtwork(long GameId)
{ {
try try
@@ -319,6 +325,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/artwork/{ArtworkId}")] [Route("{GameId}/artwork/{ArtworkId}")]
[ProducesResponseType(typeof(Artwork), StatusCodes.Status200OK)] [ProducesResponseType(typeof(Artwork), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameArtwork(long GameId, long ArtworkId) public ActionResult GameArtwork(long GameId, long ArtworkId)
{ {
try try
@@ -377,6 +384,7 @@ namespace gaseous_server.Controllers
}; };
Response.Headers.Add("Content-Disposition", cd.ToString()); Response.Headers.Add("Content-Disposition", cd.ToString());
Response.Headers.Add("Cache-Control", "public, max-age=604800");
return File(filedata, contentType); return File(filedata, contentType);
} }
@@ -405,6 +413,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/cover")] [Route("{GameId}/cover")]
[ProducesResponseType(typeof(Cover), StatusCodes.Status200OK)] [ProducesResponseType(typeof(Cover), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameCover(long GameId) public ActionResult GameCover(long GameId)
{ {
try try
@@ -457,6 +466,7 @@ namespace gaseous_server.Controllers
}; };
Response.Headers.Add("Content-Disposition", cd.ToString()); Response.Headers.Add("Content-Disposition", cd.ToString());
Response.Headers.Add("Cache-Control", "public, max-age=604800");
return File(filedata, contentType); return File(filedata, contentType);
} }
@@ -475,6 +485,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/roms")] [Route("{GameId}/roms")]
[ProducesResponseType(typeof(List<Classes.Roms.GameRomItem>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(List<Classes.Roms.GameRomItem>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "5Minute")]
public ActionResult GameRom(long GameId) public ActionResult GameRom(long GameId)
{ {
try try
@@ -494,7 +505,8 @@ namespace gaseous_server.Controllers
[HttpGet] [HttpGet]
[Route("{GameId}/roms/{RomId}")] [Route("{GameId}/roms/{RomId}")]
[ProducesResponseType(typeof(Classes.Roms.GameRomItem), StatusCodes.Status200OK)] [ProducesResponseType(typeof(Classes.Roms.GameRomItem), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "5Minute")]
public ActionResult GameRom(long GameId, long RomId) public ActionResult GameRom(long GameId, long RomId)
{ {
try try
@@ -602,6 +614,7 @@ namespace gaseous_server.Controllers
}; };
Response.Headers.Add("Content-Disposition", cd.ToString()); Response.Headers.Add("Content-Disposition", cd.ToString());
Response.Headers.Add("Cache-Control", "public, max-age=604800");
return File(filedata, contentType); return File(filedata, contentType);
} }
@@ -620,6 +633,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/screenshots")] [Route("{GameId}/screenshots")]
[ProducesResponseType(typeof(List<Screenshot>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(List<Screenshot>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameScreenshot(long GameId) public ActionResult GameScreenshot(long GameId)
{ {
try try
@@ -648,6 +662,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/screenshots/{ScreenshotId}")] [Route("{GameId}/screenshots/{ScreenshotId}")]
[ProducesResponseType(typeof(Screenshot), StatusCodes.Status200OK)] [ProducesResponseType(typeof(Screenshot), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameScreenshot(long GameId, long ScreenshotId) public ActionResult GameScreenshot(long GameId, long ScreenshotId)
{ {
try try
@@ -702,6 +717,7 @@ namespace gaseous_server.Controllers
}; };
Response.Headers.Add("Content-Disposition", cd.ToString()); Response.Headers.Add("Content-Disposition", cd.ToString());
Response.Headers.Add("Cache-Control", "public, max-age=604800");
return File(filedata, contentType); return File(filedata, contentType);
} }
@@ -720,6 +736,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/videos")] [Route("{GameId}/videos")]
[ProducesResponseType(typeof(List<GameVideo>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(List<GameVideo>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameVideo(long GameId) public ActionResult GameVideo(long GameId)
{ {
try try

View File

@@ -1,6 +1,7 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using gaseous_server; using gaseous_server;
using gaseous_tools; using gaseous_tools;
using Microsoft.AspNetCore.Mvc;
Logging.Log(Logging.LogType.Information, "Startup", "Starting Gaseous Server"); Logging.Log(Logging.LogType.Information, "Startup", "Starting Gaseous Server");
@@ -32,6 +33,27 @@ builder.Services.AddControllers().AddJsonOptions(x =>
// suppress nulls // suppress nulls
x.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; x.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
}); });
builder.Services.AddResponseCaching();
builder.Services.AddControllers(options =>
{
options.CacheProfiles.Add("Default30",
new CacheProfile()
{
Duration = 30
});
options.CacheProfiles.Add("5Minute",
new CacheProfile()
{
Duration = 300,
Location = ResponseCacheLocation.Any
});
options.CacheProfiles.Add("7Days",
new CacheProfile()
{
Duration = 604800,
Location = ResponseCacheLocation.Any
});
});
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
@@ -49,6 +71,8 @@ if (app.Environment.IsDevelopment())
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseResponseCaching();
app.UseAuthorization(); app.UseAuthorization();
app.UseDefaultFiles(); app.UseDefaultFiles();

View File

@@ -103,6 +103,7 @@
<Folder Include="Assets\Ratings\USK\" /> <Folder Include="Assets\Ratings\USK\" />
<Folder Include="Assets\Ratings\GRAC\" /> <Folder Include="Assets\Ratings\GRAC\" />
<Folder Include="Assets\Ratings\CLASS_IND\" /> <Folder Include="Assets\Ratings\CLASS_IND\" />
<Folder Include="wwwroot\fonts\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\gaseous-tools\gaseous-tools.csproj"> <ProjectReference Include="..\gaseous-tools\gaseous-tools.csproj">
@@ -123,6 +124,7 @@
<Content Remove="wwwroot\images\" /> <Content Remove="wwwroot\images\" />
<Content Remove="wwwroot\styles\" /> <Content Remove="wwwroot\styles\" />
<Content Remove="wwwroot\pages\" /> <Content Remove="wwwroot\pages\" />
<Content Remove="wwwroot\fonts\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Support\PlatformMap.json" Condition="'$(ExcludeConfigFilesFromBuildOutput)'!='true'"> <EmbeddedResource Include="Support\PlatformMap.json" Condition="'$(ExcludeConfigFilesFromBuildOutput)'!='true'">

View File

@@ -0,0 +1 @@
<svg width="159" height="110" xmlns="http://www.w3.org/2000/svg"><path d="m154 17.5c-1.82-6.73-7.07-12-13.8-13.8-9.04-3.49-96.6-5.2-122 0.1-6.73 1.82-12 7.07-13.8 13.8-4.08 17.9-4.39 56.6 0.1 74.9 1.82 6.73 7.07 12 13.8 13.8 17.9 4.12 103 4.7 122 0 6.73-1.82 12-7.07 13.8-13.8 4.35-19.5 4.66-55.8-0.1-75z" fill="#f00"/><path d="m105 55-40.8-23.4v46.8z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 374 B

View File

@@ -11,14 +11,14 @@
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"> <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest"> <link rel="manifest" href="/site.webmanifest">
<title>Gaseous</title> <title>Gaseous Games</title>
</head> </head>
<body> <body>
<div id="banner_icon"> <div id="banner_icon">
<img src="/images/logo.png" alt="Gaseous" id="banner_icon_image" /> <img src="/images/logo.png" alt="Gaseous" id="banner_icon_image" />
</div> </div>
<div id="banner_header"> <div id="banner_header">
<div id="banner_header_label"></div> <div id="banner_header_label">Gaseous Games</div>
</div> </div>
<div id="content"> <div id="content">

View File

@@ -139,17 +139,19 @@
if (result.videos) { if (result.videos) {
imageIndex = result.videos.ids.length; imageIndex = result.videos.ids.length;
} }
for (var i = 0; i < result.screenshots.ids.length; i++) { if (result.screenshots) {
var screenshotItem = document.createElement('div'); for (var i = 0; i < result.screenshots.ids.length; i++) {
screenshotItem.id = 'gamescreenshots_gallery_' + imageIndex; var screenshotItem = document.createElement('div');
screenshotItem.setAttribute('name', 'gamescreenshots_gallery_item'); screenshotItem.id = 'gamescreenshots_gallery_' + imageIndex;
screenshotItem.setAttribute('style', 'background-image: url("/api/v1/Games/' + gameId + '/screenshots/' + result.screenshots.ids[i] + '/image"); background-position: center; background-repeat: no-repeat; background-size: contain;)'); screenshotItem.setAttribute('name', 'gamescreenshots_gallery_item');
screenshotItem.setAttribute('imageid', imageIndex); screenshotItem.setAttribute('style', 'background-image: url("/api/v1/Games/' + gameId + '/screenshots/' + result.screenshots.ids[i] + '/image"); background-position: center; background-repeat: no-repeat; background-size: contain;)');
screenshotItem.setAttribute('imagetype', 0); screenshotItem.setAttribute('imageid', imageIndex);
screenshotItem.className = 'gamescreenshosts_gallery_item'; screenshotItem.setAttribute('imagetype', 0);
screenshotItem.setAttribute('onclick', 'selectScreenshot(' + imageIndex + ');'); screenshotItem.className = 'gamescreenshots_gallery_item';
gameScreenshots_Gallery.appendChild(screenshotItem); screenshotItem.setAttribute('onclick', 'selectScreenshot(' + imageIndex + ');');
imageIndex += 1; gameScreenshots_Gallery.appendChild(screenshotItem);
imageIndex += 1;
}
} }
// load videos // load videos
@@ -164,8 +166,14 @@
vScreenshotItem.setAttribute('imageid', i); vScreenshotItem.setAttribute('imageid', i);
vScreenshotItem.setAttribute('imagetype', 1); vScreenshotItem.setAttribute('imagetype', 1);
vScreenshotItem.setAttribute('imageref', result[i].videoId); vScreenshotItem.setAttribute('imageref', result[i].videoId);
vScreenshotItem.className = 'gamescreenshosts_gallery_item'; vScreenshotItem.className = 'gamescreenshots_gallery_item';
vScreenshotItem.setAttribute('onclick', 'selectScreenshot(' + i + ');'); vScreenshotItem.setAttribute('onclick', 'selectScreenshot(' + i + ');');
var youtubeIcon = document.createElement('img');
youtubeIcon.src = '/images/YouTube.svg';
youtubeIcon.className = 'gamescreenshosts_gallery_item_youtube';
vScreenshotItem.appendChild(youtubeIcon);
gameScreenshots_vGallery.insertBefore(vScreenshotItem, gameScreenshots_vGallery.firstChild); gameScreenshots_vGallery.insertBefore(vScreenshotItem, gameScreenshots_vGallery.firstChild);
} }
@@ -206,7 +214,7 @@
var newTable = document.createElement('table'); var newTable = document.createElement('table');
newTable.className = 'romtable'; newTable.className = 'romtable';
newTable.setAttribute('cellspacing', 0); newTable.setAttribute('cellspacing', 0);
newTable.appendChild(createTableRow(true, ['Name', 'Size', 'Media', ''])); newTable.appendChild(createTableRow(true, ['Name', 'Size', 'Media', '', '']));
var lastPlatform = ''; var lastPlatform = '';
for (var i = 0; i < result.length; i++) { for (var i = 0; i < result.length; i++) {
@@ -224,7 +232,8 @@
'<a href="/api/v1/Games/' + gameId + '/roms/' + result[i].id + '/file" class="romlink">' + result[i].name + '</a>', '<a href="/api/v1/Games/' + gameId + '/roms/' + result[i].id + '/file" class="romlink">' + result[i].name + '</a>',
formatBytes(result[i].size, 2), formatBytes(result[i].size, 2),
result[i].romTypeMedia, result[i].romTypeMedia,
result[i].mediaLabel result[i].mediaLabel,
'<a href="#" class="romlink">...</a>'
]; ];
newTable.appendChild(createTableRow(false, newRow, 'romrow', 'romcell')); newTable.appendChild(createTableRow(false, newRow, 'romrow', 'romcell'));
} }

View File

@@ -8,6 +8,11 @@
font-size: 13px; font-size: 13px;
} }
@font-face {
font-family: Commodore64;
src: url('/fonts/Commodore Pixelized v1.2.ttf');
}
h3 { h3 {
border-bottom-style: solid; border-bottom-style: solid;
/*border-bottom-color: #916b01;*/ /*border-bottom-color: #916b01;*/
@@ -48,11 +53,13 @@ h3 {
} }
#banner_header_label { #banner_header_label {
font-family: Commodore64;
display: inline; display: inline;
padding: 10px; padding: 10px;
font-size: 18pt; font-size: 16pt;
font-weight: 700; vertical-align: top;
color: #edeffa; /*color: #edeffa;*/
color: #7c70da;
} }
#content { #content {
@@ -193,7 +200,7 @@ input[id='filter_panel_search'] {
right: 0; right: 0;
margin: auto; margin: auto;
width: 90%; width: 90%;
min-width: 800px; min-width: 911px;
max-width: 1122px; max-width: 1122px;
padding-top: 1px; padding-top: 1px;
@@ -270,7 +277,7 @@ iframe {
white-space: nowrap; white-space: nowrap;
} }
.gamescreenshosts_gallery_item { .gamescreenshots_gallery_item {
display: inline-block; display: inline-block;
height: 50px; height: 50px;
width: 70px; width: 70px;
@@ -282,6 +289,14 @@ iframe {
cursor: pointer; cursor: pointer;
} }
.gamescreenshosts_gallery_item_youtube {
max-height: 20px;
max-width: 20px;
float: right;
margin-top: 30px;
margin-right: 5px;
}
.gamescreenshots_arrows { .gamescreenshots_arrows {
margin-top: 140px; margin-top: 140px;
height: 50px; height: 50px;
@@ -290,7 +305,6 @@ iframe {
background-color: #383838; background-color: #383838;
color: black; color: black;
text-align: center; text-align: center;
user-select: none; /* standard syntax */ user-select: none; /* standard syntax */
-webkit-user-select: none; /* webkit (safari, chrome) browsers */ -webkit-user-select: none; /* webkit (safari, chrome) browsers */
-moz-user-select: none; /* mozilla browsers */ -moz-user-select: none; /* mozilla browsers */

View File

@@ -302,7 +302,9 @@ CREATE TABLE `games_roms` (
`path` longtext, `path` longtext,
`metadatasource` int DEFAULT NULL, `metadatasource` int DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`) UNIQUE KEY `id_UNIQUE` (`id`),
INDEX `gameid` (`gameid` ASC) VISIBLE,
INDEX `id_gameid` (`gameid` ASC, `id` ASC) VISIBLE
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;