diff --git a/gaseous-server/Classes/Metadata/Games.cs b/gaseous-server/Classes/Metadata/Games.cs index 016eed1..f83a351 100644 --- a/gaseous-server/Classes/Metadata/Games.cs +++ b/gaseous-server/Classes/Metadata/Games.cs @@ -1,4 +1,5 @@ using System; +using System.Data; using gaseous_tools; using IGDB; using IGDB.Models; @@ -25,7 +26,7 @@ namespace gaseous_server.Classes.Metadata if (Id == 0) { 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 { @@ -55,6 +56,11 @@ namespace gaseous_server.Classes.Metadata return RetVal.Result; } + public static Game GetGame(DataRow dataRow) + { + return Storage.BuildCacheObject(new Game(), dataRow); + } + private static async Task _GetGame(SearchUsing searchUsing, object searchValue, bool followSubGames = false, bool forceRefresh = false) { // check database first @@ -229,6 +235,9 @@ namespace gaseous_server.Classes.Metadata searchBody += "fields id,name,slug,platforms,summary; "; switch (searchType) { + case SearchType.searchNoPlatform: + searchBody += "search \"" + SearchString + "\"; "; + break; case SearchType.search: searchBody += "search \"" + SearchString + "\"; "; searchBody += "where platforms = (" + PlatformId + ");"; @@ -252,7 +261,8 @@ namespace gaseous_server.Classes.Metadata { where = 0, wherefuzzy = 1, - search = 2 + search = 2, + searchNoPlatform = 3 } } } \ No newline at end of file diff --git a/gaseous-server/Classes/Metadata/Storage.cs b/gaseous-server/Classes/Metadata/Storage.cs index 8d543cc..d2fb9be 100644 --- a/gaseous-server/Classes/Metadata/Storage.cs +++ b/gaseous-server/Classes/Metadata/Storage.cs @@ -26,6 +26,26 @@ namespace gaseous_server.Classes.Metadata 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) { Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); @@ -161,189 +181,194 @@ namespace gaseous_server.Classes.Metadata else { DataRow dataRow = dt.Rows[0]; - 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(id: (long)dataRow[property.Name]); - break; - case "cover": - objectToStore = new IdentityOrValue(id: (long)dataRow[property.Name]); - break; - case "franchise": - objectToStore = new IdentityOrValue(id: (long)dataRow[property.Name]); - break; - case "game": - objectToStore = new IdentityOrValue(id: (long)dataRow[property.Name]); - break; - case "platformfamily": - objectToStore = new IdentityOrValue(id: (long)dataRow[property.Name]); - break; - case "platformlogo": - objectToStore = new IdentityOrValue(id: (long)dataRow[property.Name]); - break; - case "platformversioncompany": - objectToStore = new IdentityOrValue(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((string)dataRow[property.Name]); - - switch (subObjectTypeName) - { - case "agerating": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "alternativename": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "artwork": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "ageratingcontentdescription": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "game": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "externalgame": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "franchise": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "gameengine": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "gamemode": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "gamevideo": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "genre": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "involvedcompany": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "multiplayermode": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "platform": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "platformversion": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "platformwebsite": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "platformversioncompany": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "platformversionreleasedate": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "playerperspective": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "releasedate": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "screenshot": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "theme": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - case "website": - objectToStore = new IdentitiesOrValues(ids: fromJsonObject); - break; - } - - if (objectToStore != null) - { - property.SetValue(EndpointType, objectToStore); - } - - break; - case "int32[]": - Int32[] fromJsonObject_int32Array = Newtonsoft.Json.JsonConvert.DeserializeObject((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; + return BuildCacheObject(EndpointType, dataRow); } + } + + public static T BuildCacheObject(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(id: (long)dataRow[property.Name]); + break; + case "cover": + objectToStore = new IdentityOrValue(id: (long)dataRow[property.Name]); + break; + case "franchise": + objectToStore = new IdentityOrValue(id: (long)dataRow[property.Name]); + break; + case "game": + objectToStore = new IdentityOrValue(id: (long)dataRow[property.Name]); + break; + case "platformfamily": + objectToStore = new IdentityOrValue(id: (long)dataRow[property.Name]); + break; + case "platformlogo": + objectToStore = new IdentityOrValue(id: (long)dataRow[property.Name]); + break; + case "platformversioncompany": + objectToStore = new IdentityOrValue(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((string)dataRow[property.Name]); + + switch (subObjectTypeName) + { + case "agerating": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "alternativename": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "artwork": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "ageratingcontentdescription": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "game": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "externalgame": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "franchise": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "gameengine": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "gamemode": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "gamevideo": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "genre": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "involvedcompany": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "multiplayermode": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "platform": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "platformversion": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "platformwebsite": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "platformversioncompany": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "platformversionreleasedate": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "playerperspective": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "releasedate": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "screenshot": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "theme": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + case "website": + objectToStore = new IdentitiesOrValues(ids: fromJsonObject); + break; + } + + if (objectToStore != null) + { + property.SetValue(EndpointType, objectToStore); + } + + break; + case "int32[]": + Int32[] fromJsonObject_int32Array = Newtonsoft.Json.JsonConvert.DeserializeObject((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; } } } diff --git a/gaseous-server/Controllers/FilterController.cs b/gaseous-server/Controllers/FilterController.cs index 8247192..865510a 100644 --- a/gaseous-server/Controllers/FilterController.cs +++ b/gaseous-server/Controllers/FilterController.cs @@ -16,6 +16,7 @@ namespace gaseous_server.Controllers { [HttpGet] [ProducesResponseType(StatusCodes.Status200OK)] + [ResponseCache(CacheProfileName = "5Minute")] public Dictionary Filter() { Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); diff --git a/gaseous-server/Controllers/GamesController.cs b/gaseous-server/Controllers/GamesController.cs index 0fd0ac9..47cfbad 100644 --- a/gaseous-server/Controllers/GamesController.cs +++ b/gaseous-server/Controllers/GamesController.cs @@ -111,14 +111,15 @@ namespace gaseous_server.Controllers } 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 RetVal = new List(); DataTable dbResponse = db.ExecuteCMD(sql, whereParams); 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); @@ -128,6 +129,7 @@ namespace gaseous_server.Controllers [Route("{GameId}")] [ProducesResponseType(typeof(Game), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "5Minute")] public ActionResult Game(long GameId, bool forceRefresh = false) { try @@ -153,6 +155,7 @@ namespace gaseous_server.Controllers [Route("{GameId}/alternativename")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "7Days")] public ActionResult GameAlternativeNames(long GameId) { try @@ -183,6 +186,7 @@ namespace gaseous_server.Controllers [Route("{GameId}/agerating")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "7Days")] public ActionResult GameAgeClassification(long GameId) { try @@ -275,6 +279,7 @@ namespace gaseous_server.Controllers }; Response.Headers.Add("Content-Disposition", cd.ToString()); + Response.Headers.Add("Cache-Control", "public, max-age=604800"); return File(filedata, contentType); } @@ -291,6 +296,7 @@ namespace gaseous_server.Controllers [Route("{GameId}/artwork")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "7Days")] public ActionResult GameArtwork(long GameId) { try @@ -319,6 +325,7 @@ namespace gaseous_server.Controllers [Route("{GameId}/artwork/{ArtworkId}")] [ProducesResponseType(typeof(Artwork), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "7Days")] public ActionResult GameArtwork(long GameId, long ArtworkId) { try @@ -377,6 +384,7 @@ namespace gaseous_server.Controllers }; Response.Headers.Add("Content-Disposition", cd.ToString()); + Response.Headers.Add("Cache-Control", "public, max-age=604800"); return File(filedata, contentType); } @@ -405,6 +413,7 @@ namespace gaseous_server.Controllers [Route("{GameId}/cover")] [ProducesResponseType(typeof(Cover), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "7Days")] public ActionResult GameCover(long GameId) { try @@ -457,6 +466,7 @@ namespace gaseous_server.Controllers }; Response.Headers.Add("Content-Disposition", cd.ToString()); + Response.Headers.Add("Cache-Control", "public, max-age=604800"); return File(filedata, contentType); } @@ -475,6 +485,7 @@ namespace gaseous_server.Controllers [Route("{GameId}/roms")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "5Minute")] public ActionResult GameRom(long GameId) { try @@ -494,7 +505,8 @@ namespace gaseous_server.Controllers [HttpGet] [Route("{GameId}/roms/{RomId}")] [ProducesResponseType(typeof(Classes.Roms.GameRomItem), StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "5Minute")] public ActionResult GameRom(long GameId, long RomId) { try @@ -602,6 +614,7 @@ namespace gaseous_server.Controllers }; Response.Headers.Add("Content-Disposition", cd.ToString()); + Response.Headers.Add("Cache-Control", "public, max-age=604800"); return File(filedata, contentType); } @@ -620,6 +633,7 @@ namespace gaseous_server.Controllers [Route("{GameId}/screenshots")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "7Days")] public ActionResult GameScreenshot(long GameId) { try @@ -648,6 +662,7 @@ namespace gaseous_server.Controllers [Route("{GameId}/screenshots/{ScreenshotId}")] [ProducesResponseType(typeof(Screenshot), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "7Days")] public ActionResult GameScreenshot(long GameId, long ScreenshotId) { try @@ -702,6 +717,7 @@ namespace gaseous_server.Controllers }; Response.Headers.Add("Content-Disposition", cd.ToString()); + Response.Headers.Add("Cache-Control", "public, max-age=604800"); return File(filedata, contentType); } @@ -720,6 +736,7 @@ namespace gaseous_server.Controllers [Route("{GameId}/videos")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "7Days")] public ActionResult GameVideo(long GameId) { try diff --git a/gaseous-server/Program.cs b/gaseous-server/Program.cs index 49342f4..7ae0da9 100644 --- a/gaseous-server/Program.cs +++ b/gaseous-server/Program.cs @@ -1,6 +1,7 @@ using System.Text.Json.Serialization; using gaseous_server; using gaseous_tools; +using Microsoft.AspNetCore.Mvc; Logging.Log(Logging.LogType.Information, "Startup", "Starting Gaseous Server"); @@ -32,6 +33,27 @@ builder.Services.AddControllers().AddJsonOptions(x => // suppress nulls 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 builder.Services.AddEndpointsApiExplorer(); @@ -49,6 +71,8 @@ if (app.Environment.IsDevelopment()) app.UseHttpsRedirection(); +app.UseResponseCaching(); + app.UseAuthorization(); app.UseDefaultFiles(); diff --git a/gaseous-server/gaseous-server.csproj b/gaseous-server/gaseous-server.csproj index aa3be2e..ac0ffa6 100644 --- a/gaseous-server/gaseous-server.csproj +++ b/gaseous-server/gaseous-server.csproj @@ -103,6 +103,7 @@ + @@ -123,6 +124,7 @@ + diff --git a/gaseous-server/wwwroot/fonts/Commodore Pixelized v1.2.ttf b/gaseous-server/wwwroot/fonts/Commodore Pixelized v1.2.ttf new file mode 100644 index 0000000..6bf582a Binary files /dev/null and b/gaseous-server/wwwroot/fonts/Commodore Pixelized v1.2.ttf differ diff --git a/gaseous-server/wwwroot/images/YouTube.svg b/gaseous-server/wwwroot/images/YouTube.svg new file mode 100644 index 0000000..a2be57b --- /dev/null +++ b/gaseous-server/wwwroot/images/YouTube.svg @@ -0,0 +1 @@ + diff --git a/gaseous-server/wwwroot/index.html b/gaseous-server/wwwroot/index.html index b1b9d2f..29c8c95 100644 --- a/gaseous-server/wwwroot/index.html +++ b/gaseous-server/wwwroot/index.html @@ -11,14 +11,14 @@ - Gaseous + Gaseous Games
diff --git a/gaseous-server/wwwroot/pages/game.html b/gaseous-server/wwwroot/pages/game.html index 9bbe21c..962cdf3 100644 --- a/gaseous-server/wwwroot/pages/game.html +++ b/gaseous-server/wwwroot/pages/game.html @@ -139,17 +139,19 @@ if (result.videos) { imageIndex = result.videos.ids.length; } - for (var i = 0; i < result.screenshots.ids.length; i++) { - var screenshotItem = document.createElement('div'); - screenshotItem.id = 'gamescreenshots_gallery_' + imageIndex; - screenshotItem.setAttribute('name', 'gamescreenshots_gallery_item'); - 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('imageid', imageIndex); - screenshotItem.setAttribute('imagetype', 0); - screenshotItem.className = 'gamescreenshosts_gallery_item'; - screenshotItem.setAttribute('onclick', 'selectScreenshot(' + imageIndex + ');'); - gameScreenshots_Gallery.appendChild(screenshotItem); - imageIndex += 1; + if (result.screenshots) { + for (var i = 0; i < result.screenshots.ids.length; i++) { + var screenshotItem = document.createElement('div'); + screenshotItem.id = 'gamescreenshots_gallery_' + imageIndex; + screenshotItem.setAttribute('name', 'gamescreenshots_gallery_item'); + 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('imageid', imageIndex); + screenshotItem.setAttribute('imagetype', 0); + screenshotItem.className = 'gamescreenshots_gallery_item'; + screenshotItem.setAttribute('onclick', 'selectScreenshot(' + imageIndex + ');'); + gameScreenshots_Gallery.appendChild(screenshotItem); + imageIndex += 1; + } } // load videos @@ -164,8 +166,14 @@ vScreenshotItem.setAttribute('imageid', i); vScreenshotItem.setAttribute('imagetype', 1); vScreenshotItem.setAttribute('imageref', result[i].videoId); - vScreenshotItem.className = 'gamescreenshosts_gallery_item'; + vScreenshotItem.className = 'gamescreenshots_gallery_item'; 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); } @@ -206,7 +214,7 @@ var newTable = document.createElement('table'); newTable.className = 'romtable'; newTable.setAttribute('cellspacing', 0); - newTable.appendChild(createTableRow(true, ['Name', 'Size', 'Media', ''])); + newTable.appendChild(createTableRow(true, ['Name', 'Size', 'Media', '', ''])); var lastPlatform = ''; for (var i = 0; i < result.length; i++) { @@ -224,7 +232,8 @@ '' + result[i].name + '', formatBytes(result[i].size, 2), result[i].romTypeMedia, - result[i].mediaLabel + result[i].mediaLabel, + '...' ]; newTable.appendChild(createTableRow(false, newRow, 'romrow', 'romcell')); } diff --git a/gaseous-server/wwwroot/styles/style.css b/gaseous-server/wwwroot/styles/style.css index 6927b06..1305b25 100644 --- a/gaseous-server/wwwroot/styles/style.css +++ b/gaseous-server/wwwroot/styles/style.css @@ -8,6 +8,11 @@ font-size: 13px; } +@font-face { + font-family: Commodore64; + src: url('/fonts/Commodore Pixelized v1.2.ttf'); +} + h3 { border-bottom-style: solid; /*border-bottom-color: #916b01;*/ @@ -48,11 +53,13 @@ h3 { } #banner_header_label { + font-family: Commodore64; display: inline; padding: 10px; - font-size: 18pt; - font-weight: 700; - color: #edeffa; + font-size: 16pt; + vertical-align: top; + /*color: #edeffa;*/ + color: #7c70da; } #content { @@ -193,7 +200,7 @@ input[id='filter_panel_search'] { right: 0; margin: auto; width: 90%; - min-width: 800px; + min-width: 911px; max-width: 1122px; padding-top: 1px; @@ -270,7 +277,7 @@ iframe { white-space: nowrap; } -.gamescreenshosts_gallery_item { +.gamescreenshots_gallery_item { display: inline-block; height: 50px; width: 70px; @@ -282,6 +289,14 @@ iframe { cursor: pointer; } +.gamescreenshosts_gallery_item_youtube { + max-height: 20px; + max-width: 20px; + float: right; + margin-top: 30px; + margin-right: 5px; +} + .gamescreenshots_arrows { margin-top: 140px; height: 50px; @@ -290,7 +305,6 @@ iframe { background-color: #383838; color: black; text-align: center; - user-select: none; /* standard syntax */ -webkit-user-select: none; /* webkit (safari, chrome) browsers */ -moz-user-select: none; /* mozilla browsers */ diff --git a/gaseous-tools/Database/MySQL/gaseous-1000.sql b/gaseous-tools/Database/MySQL/gaseous-1000.sql index 3e0143a..b44033b 100644 --- a/gaseous-tools/Database/MySQL/gaseous-1000.sql +++ b/gaseous-tools/Database/MySQL/gaseous-1000.sql @@ -302,7 +302,9 @@ CREATE TABLE `games_roms` ( `path` longtext, `metadatasource` int DEFAULT NULL, 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; /*!40101 SET character_set_client = @saved_cs_client */;