Collections needs to honour the logged in users age rating permissionFixes #273
Known issue: #275
This commit is contained in:
@@ -7,33 +7,26 @@ using System.Security.Cryptography;
|
|||||||
using Authentication;
|
using Authentication;
|
||||||
using gaseous_server.Classes.Metadata;
|
using gaseous_server.Classes.Metadata;
|
||||||
using gaseous_server.Controllers;
|
using gaseous_server.Controllers;
|
||||||
|
using gaseous_server.Controllers.v1_1;
|
||||||
using gaseous_server.Models;
|
using gaseous_server.Models;
|
||||||
using IGDB.Models;
|
using IGDB.Models;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SharpCompress.Common;
|
using SharpCompress.Common;
|
||||||
|
using static gaseous_server.Classes.Metadata.Games;
|
||||||
|
|
||||||
namespace gaseous_server.Classes
|
namespace gaseous_server.Classes
|
||||||
{
|
{
|
||||||
public class Collections
|
public class Collections
|
||||||
{
|
{
|
||||||
private readonly UserManager<ApplicationUser> _userManager;
|
public static List<CollectionItem> GetCollections(string userid) {
|
||||||
private readonly SignInManager<ApplicationUser> _signInManager;
|
|
||||||
|
|
||||||
public Collections(
|
|
||||||
UserManager<ApplicationUser> userManager,
|
|
||||||
SignInManager<ApplicationUser> signInManager)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_signInManager = signInManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<CollectionItem> GetCollections() {
|
|
||||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
string sql = "SELECT * FROM RomCollections ORDER BY `Name`";
|
string sql = "SELECT * FROM RomCollections WHERE OwnedBy=@ownedby ORDER BY `Name`";
|
||||||
|
Dictionary<string, object> dbDict = new Dictionary<string, object>{
|
||||||
DataTable data = db.ExecuteCMD(sql);
|
{ "ownedby", userid }
|
||||||
|
};
|
||||||
|
DataTable data = db.ExecuteCMD(sql, dbDict);
|
||||||
|
|
||||||
List<CollectionItem> collectionItems = new List<CollectionItem>();
|
List<CollectionItem> collectionItems = new List<CollectionItem>();
|
||||||
|
|
||||||
@@ -44,11 +37,24 @@ namespace gaseous_server.Classes
|
|||||||
return collectionItems;
|
return collectionItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CollectionItem GetCollection(long Id) {
|
public static CollectionItem GetCollection(long Id, string userid) {
|
||||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
string sql = "SELECT * FROM RomCollections WHERE Id = @id ORDER BY `Name`";
|
string sql;
|
||||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
if (userid == "")
|
||||||
dbDict.Add("id", Id);
|
{
|
||||||
|
// reserved for internal operations
|
||||||
|
sql = "SELECT * FROM RomCollections WHERE Id = @id ORDER BY `Name`";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// instigated by a user
|
||||||
|
sql = "SELECT * FROM RomCollections WHERE Id = @id AND OwnedBy = @ownedby ORDER BY `Name`";
|
||||||
|
}
|
||||||
|
Dictionary<string, object> dbDict = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "id", Id },
|
||||||
|
{ "ownedby", userid }
|
||||||
|
};
|
||||||
DataTable romDT = db.ExecuteCMD(sql, dbDict);
|
DataTable romDT = db.ExecuteCMD(sql, dbDict);
|
||||||
|
|
||||||
if (romDT.Rows.Count > 0)
|
if (romDT.Rows.Count > 0)
|
||||||
@@ -64,60 +70,66 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CollectionItem NewCollection(CollectionItem item)
|
public static CollectionItem NewCollection(CollectionItem item, string userid)
|
||||||
{
|
{
|
||||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
string sql = "INSERT INTO RomCollections (`Name`, Description, Platforms, Genres, Players, PlayerPerspectives, Themes, MinimumRating, MaximumRating, MaximumRomsPerPlatform, MaximumBytesPerPlatform, MaximumCollectionSizeInBytes, FolderStructure, IncludeBIOSFiles, ArchiveType, AlwaysInclude, BuiltStatus) VALUES (@name, @description, @platforms, @genres, @players, @playerperspectives, @themes, @minimumrating, @maximumrating, @maximumromsperplatform, @maximumbytesperplatform, @maximumcollectionsizeinbytes, @folderstructure, @includebiosfiles, @archivetype, @alwaysinclude, @builtstatus); SELECT CAST(LAST_INSERT_ID() AS SIGNED);";
|
string sql = "INSERT INTO RomCollections (`Name`, Description, Platforms, Genres, Players, PlayerPerspectives, Themes, MinimumRating, MaximumRating, MaximumRomsPerPlatform, MaximumBytesPerPlatform, MaximumCollectionSizeInBytes, FolderStructure, IncludeBIOSFiles, ArchiveType, AlwaysInclude, BuiltStatus, OwnedBy) VALUES (@name, @description, @platforms, @genres, @players, @playerperspectives, @themes, @minimumrating, @maximumrating, @maximumromsperplatform, @maximumbytesperplatform, @maximumcollectionsizeinbytes, @folderstructure, @includebiosfiles, @archivetype, @alwaysinclude, @builtstatus, @ownedby); SELECT CAST(LAST_INSERT_ID() AS SIGNED);";
|
||||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
Dictionary<string, object> dbDict = new Dictionary<string, object>
|
||||||
dbDict.Add("name", item.Name);
|
{
|
||||||
dbDict.Add("description", item.Description);
|
{ "name", item.Name },
|
||||||
dbDict.Add("platforms", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Platforms, new List<long>())));
|
{ "description", item.Description },
|
||||||
dbDict.Add("genres", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Genres, new List<long>())));
|
{ "platforms", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Platforms, new List<long>())) },
|
||||||
dbDict.Add("players", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Players, new List<long>())));
|
{ "genres", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Genres, new List<long>())) },
|
||||||
dbDict.Add("playerperspectives", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.PlayerPerspectives, new List<long>())));
|
{ "players", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Players, new List<long>())) },
|
||||||
dbDict.Add("themes", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Themes, new List<long>())));
|
{ "playerperspectives", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.PlayerPerspectives, new List<long>())) },
|
||||||
dbDict.Add("minimumrating", Common.ReturnValueIfNull(item.MinimumRating, -1));
|
{ "themes", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Themes, new List<long>())) },
|
||||||
dbDict.Add("maximumrating", Common.ReturnValueIfNull(item.MaximumRating, -1));
|
{ "minimumrating", Common.ReturnValueIfNull(item.MinimumRating, -1) },
|
||||||
dbDict.Add("maximumromsperplatform", Common.ReturnValueIfNull(item.MaximumRomsPerPlatform, -1));
|
{ "maximumrating", Common.ReturnValueIfNull(item.MaximumRating, -1) },
|
||||||
dbDict.Add("maximumbytesperplatform", Common.ReturnValueIfNull(item.MaximumBytesPerPlatform, -1));
|
{ "maximumromsperplatform", Common.ReturnValueIfNull(item.MaximumRomsPerPlatform, -1) },
|
||||||
dbDict.Add("maximumcollectionsizeinbytes", Common.ReturnValueIfNull(item.MaximumCollectionSizeInBytes, -1));
|
{ "maximumbytesperplatform", Common.ReturnValueIfNull(item.MaximumBytesPerPlatform, -1) },
|
||||||
dbDict.Add("folderstructure", Common.ReturnValueIfNull(item.FolderStructure, CollectionItem.FolderStructures.Gaseous));
|
{ "maximumcollectionsizeinbytes", Common.ReturnValueIfNull(item.MaximumCollectionSizeInBytes, -1) },
|
||||||
dbDict.Add("includebiosfiles", Common.ReturnValueIfNull(item.IncludeBIOSFiles, 0));
|
{ "folderstructure", Common.ReturnValueIfNull(item.FolderStructure, CollectionItem.FolderStructures.Gaseous) },
|
||||||
dbDict.Add("archivetype", Common.ReturnValueIfNull(item.ArchiveType, CollectionItem.ArchiveTypes.Zip));
|
{ "includebiosfiles", Common.ReturnValueIfNull(item.IncludeBIOSFiles, 0) },
|
||||||
dbDict.Add("alwaysinclude", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.AlwaysInclude, new List<CollectionItem.AlwaysIncludeItem>())));
|
{ "archivetype", Common.ReturnValueIfNull(item.ArchiveType, CollectionItem.ArchiveTypes.Zip) },
|
||||||
dbDict.Add("builtstatus", CollectionItem.CollectionBuildStatus.WaitingForBuild);
|
{ "alwaysinclude", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.AlwaysInclude, new List<CollectionItem.AlwaysIncludeItem>())) },
|
||||||
|
{ "builtstatus", CollectionItem.CollectionBuildStatus.WaitingForBuild },
|
||||||
|
{ "ownedby", userid }
|
||||||
|
};
|
||||||
DataTable romDT = db.ExecuteCMD(sql, dbDict);
|
DataTable romDT = db.ExecuteCMD(sql, dbDict);
|
||||||
long CollectionId = (long)romDT.Rows[0][0];
|
long CollectionId = (long)romDT.Rows[0][0];
|
||||||
|
|
||||||
CollectionItem collectionItem = GetCollection(CollectionId);
|
CollectionItem collectionItem = GetCollection(CollectionId, userid);
|
||||||
|
|
||||||
StartCollectionItemBuild(CollectionId);
|
StartCollectionItemBuild(CollectionId, userid);
|
||||||
|
|
||||||
return collectionItem;
|
return collectionItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CollectionItem EditCollection(long Id, CollectionItem item, bool ForceRebuild = true)
|
public static CollectionItem EditCollection(long Id, CollectionItem item, string userid, bool ForceRebuild = true)
|
||||||
{
|
{
|
||||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
string sql = "UPDATE RomCollections SET `Name`=@name, Description=@description, Platforms=@platforms, Genres=@genres, Players=@players, PlayerPerspectives=@playerperspectives, Themes=@themes, MinimumRating=@minimumrating, MaximumRating=@maximumrating, MaximumRomsPerPlatform=@maximumromsperplatform, MaximumBytesPerPlatform=@maximumbytesperplatform, MaximumCollectionSizeInBytes=@maximumcollectionsizeinbytes, FolderStructure=@folderstructure, IncludeBIOSFiles=@includebiosfiles, ArchiveType=@archivetype, AlwaysInclude=@alwaysinclude, BuiltStatus=@builtstatus WHERE Id=@id";
|
string sql = "UPDATE RomCollections SET `Name`=@name, Description=@description, Platforms=@platforms, Genres=@genres, Players=@players, PlayerPerspectives=@playerperspectives, Themes=@themes, MinimumRating=@minimumrating, MaximumRating=@maximumrating, MaximumRomsPerPlatform=@maximumromsperplatform, MaximumBytesPerPlatform=@maximumbytesperplatform, MaximumCollectionSizeInBytes=@maximumcollectionsizeinbytes, FolderStructure=@folderstructure, IncludeBIOSFiles=@includebiosfiles, ArchiveType=@archivetype, AlwaysInclude=@alwaysinclude, BuiltStatus=@builtstatus WHERE Id=@id AND OwnedBy=@ownedby";
|
||||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
Dictionary<string, object> dbDict = new Dictionary<string, object>
|
||||||
dbDict.Add("id", Id);
|
{
|
||||||
dbDict.Add("name", item.Name);
|
{ "id", Id },
|
||||||
dbDict.Add("description", item.Description);
|
{ "name", item.Name },
|
||||||
dbDict.Add("platforms", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Platforms, new List<long>())));
|
{ "description", item.Description },
|
||||||
dbDict.Add("genres", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Genres, new List<long>())));
|
{ "platforms", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Platforms, new List<long>())) },
|
||||||
dbDict.Add("players", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Players, new List<long>())));
|
{ "genres", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Genres, new List<long>())) },
|
||||||
dbDict.Add("playerperspectives", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.PlayerPerspectives, new List<long>())));
|
{ "players", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Players, new List<long>())) },
|
||||||
dbDict.Add("themes", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Themes, new List<long>())));
|
{ "playerperspectives", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.PlayerPerspectives, new List<long>())) },
|
||||||
dbDict.Add("minimumrating", Common.ReturnValueIfNull(item.MinimumRating, -1));
|
{ "themes", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.Themes, new List<long>())) },
|
||||||
dbDict.Add("maximumrating", Common.ReturnValueIfNull(item.MaximumRating, -1));
|
{ "minimumrating", Common.ReturnValueIfNull(item.MinimumRating, -1) },
|
||||||
dbDict.Add("maximumromsperplatform", Common.ReturnValueIfNull(item.MaximumRomsPerPlatform, -1));
|
{ "maximumrating", Common.ReturnValueIfNull(item.MaximumRating, -1) },
|
||||||
dbDict.Add("maximumbytesperplatform", Common.ReturnValueIfNull(item.MaximumBytesPerPlatform, -1));
|
{ "maximumromsperplatform", Common.ReturnValueIfNull(item.MaximumRomsPerPlatform, -1) },
|
||||||
dbDict.Add("maximumcollectionsizeinbytes", Common.ReturnValueIfNull(item.MaximumCollectionSizeInBytes, -1));
|
{ "maximumbytesperplatform", Common.ReturnValueIfNull(item.MaximumBytesPerPlatform, -1) },
|
||||||
dbDict.Add("folderstructure", Common.ReturnValueIfNull(item.FolderStructure, CollectionItem.FolderStructures.Gaseous));
|
{ "maximumcollectionsizeinbytes", Common.ReturnValueIfNull(item.MaximumCollectionSizeInBytes, -1) },
|
||||||
dbDict.Add("includebiosfiles", Common.ReturnValueIfNull(item.IncludeBIOSFiles, 0));
|
{ "folderstructure", Common.ReturnValueIfNull(item.FolderStructure, CollectionItem.FolderStructures.Gaseous) },
|
||||||
dbDict.Add("alwaysinclude", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.AlwaysInclude, new List<CollectionItem.AlwaysIncludeItem>())));
|
{ "includebiosfiles", Common.ReturnValueIfNull(item.IncludeBIOSFiles, 0) },
|
||||||
dbDict.Add("archivetype", Common.ReturnValueIfNull(item.ArchiveType, CollectionItem.ArchiveTypes.Zip));
|
{ "alwaysinclude", Newtonsoft.Json.JsonConvert.SerializeObject(Common.ReturnValueIfNull(item.AlwaysInclude, new List<CollectionItem.AlwaysIncludeItem>())) },
|
||||||
|
{ "archivetype", Common.ReturnValueIfNull(item.ArchiveType, CollectionItem.ArchiveTypes.Zip) },
|
||||||
|
{ "ownedby", userid }
|
||||||
|
};
|
||||||
|
|
||||||
string CollectionZipFile = Path.Combine(Config.LibraryConfiguration.LibraryCollectionsDirectory, Id + item.ArchiveExtension);
|
string CollectionZipFile = Path.Combine(Config.LibraryConfiguration.LibraryCollectionsDirectory, Id + item.ArchiveExtension);
|
||||||
if (ForceRebuild == true)
|
if (ForceRebuild == true)
|
||||||
@@ -142,22 +154,25 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
db.ExecuteCMD(sql, dbDict);
|
db.ExecuteCMD(sql, dbDict);
|
||||||
|
|
||||||
CollectionItem collectionItem = GetCollection(Id);
|
CollectionItem collectionItem = GetCollection(Id, userid);
|
||||||
|
|
||||||
if (collectionItem.BuildStatus == CollectionItem.CollectionBuildStatus.WaitingForBuild)
|
if (collectionItem.BuildStatus == CollectionItem.CollectionBuildStatus.WaitingForBuild)
|
||||||
{
|
{
|
||||||
StartCollectionItemBuild(Id);
|
StartCollectionItemBuild(Id, userid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return collectionItem;
|
return collectionItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DeleteCollection(long Id)
|
public static void DeleteCollection(long Id, string userid)
|
||||||
{
|
{
|
||||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
string sql = "DELETE FROM RomCollections WHERE Id=@id";
|
string sql = "DELETE FROM RomCollections WHERE Id=@id AND OwnedBy=@ownedby";
|
||||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
Dictionary<string, object> dbDict = new Dictionary<string, object>
|
||||||
dbDict.Add("id", Id);
|
{
|
||||||
|
{ "id", Id },
|
||||||
|
{ "ownedby", userid }
|
||||||
|
};
|
||||||
db.ExecuteCMD(sql, dbDict);
|
db.ExecuteCMD(sql, dbDict);
|
||||||
|
|
||||||
string CollectionZipFile = Path.Combine(Config.LibraryConfiguration.LibraryCollectionsDirectory, Id + ".zip");
|
string CollectionZipFile = Path.Combine(Config.LibraryConfiguration.LibraryCollectionsDirectory, Id + ".zip");
|
||||||
@@ -167,9 +182,10 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StartCollectionItemBuild(long Id)
|
public static void StartCollectionItemBuild(long Id, string userid)
|
||||||
{
|
{
|
||||||
CollectionItem collectionItem = GetCollection(Id);
|
// send blank user id to getcollection as this is not a user initiated process
|
||||||
|
CollectionItem collectionItem = GetCollection(Id, userid);
|
||||||
|
|
||||||
if (collectionItem.BuildStatus != CollectionItem.CollectionBuildStatus.Building)
|
if (collectionItem.BuildStatus != CollectionItem.CollectionBuildStatus.Building)
|
||||||
{
|
{
|
||||||
@@ -183,13 +199,40 @@ namespace gaseous_server.Classes
|
|||||||
|
|
||||||
// start background task
|
// start background task
|
||||||
ProcessQueue.QueueItem queueItem = new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.CollectionCompiler, 1, false, true);
|
ProcessQueue.QueueItem queueItem = new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.CollectionCompiler, 1, false, true);
|
||||||
queueItem.Options = Id;
|
queueItem.Options = new Dictionary<string, object>{
|
||||||
|
{ "Id", Id },
|
||||||
|
{ "UserId", userid }
|
||||||
|
};
|
||||||
queueItem.ForceExecute();
|
queueItem.ForceExecute();
|
||||||
ProcessQueue.QueueItems.Add(queueItem);
|
ProcessQueue.QueueItems.Add(queueItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CollectionContents GetCollectionContent(CollectionItem collectionItem) {
|
public static CollectionContents GetCollectionContent(CollectionItem collectionItem, string userid) {
|
||||||
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
|
|
||||||
|
// get age ratings for specified user
|
||||||
|
List<AgeGroups.AgeRestrictionGroupings> UserAgeGroupings = new List<AgeGroups.AgeRestrictionGroupings>();
|
||||||
|
bool UserAgeGroupIncludeUnrated = true;
|
||||||
|
if (userid != "")
|
||||||
|
{
|
||||||
|
Authentication.UserTable<Authentication.ApplicationUser> userTable = new UserTable<ApplicationUser>(db);
|
||||||
|
var user = userTable.GetUserById(userid);
|
||||||
|
|
||||||
|
if (user.SecurityProfile.AgeRestrictionPolicy.IncludeUnrated == false)
|
||||||
|
{
|
||||||
|
UserAgeGroupIncludeUnrated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (AgeGroups.AgeRestrictionGroupings ageGrouping in Enum.GetValues(typeof(AgeGroups.AgeRestrictionGroupings)))
|
||||||
|
{
|
||||||
|
if (ageGrouping <= user.SecurityProfile.AgeRestrictionPolicy.MaximumAgeRestriction && ageGrouping != AgeGroups.AgeRestrictionGroupings.Unclassified)
|
||||||
|
{
|
||||||
|
UserAgeGroupings.Add(ageGrouping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<CollectionContents.CollectionPlatformItem> collectionPlatformItems = new List<CollectionContents.CollectionPlatformItem>();
|
List<CollectionContents.CollectionPlatformItem> collectionPlatformItems = new List<CollectionContents.CollectionPlatformItem>();
|
||||||
|
|
||||||
// get platforms
|
// get platforms
|
||||||
@@ -230,6 +273,10 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// age ratings
|
||||||
|
AgeGroups.AgeRestrictionGroupings AgeGrouping = AgeGroups.AgeRestrictionGroupings.Unclassified;
|
||||||
|
bool ContainsUnclassifiedAgeGroup = false;
|
||||||
|
|
||||||
// build collection
|
// build collection
|
||||||
List<CollectionContents.CollectionPlatformItem> platformItems = new List<CollectionContents.CollectionPlatformItem>();
|
List<CollectionContents.CollectionPlatformItem> platformItems = new List<CollectionContents.CollectionPlatformItem>();
|
||||||
|
|
||||||
@@ -247,18 +294,29 @@ namespace gaseous_server.Classes
|
|||||||
isDynamic = true;
|
isDynamic = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Game> games = new List<Game>();
|
Controllers.v1_1.GamesController.GameReturnPackage games = new Controllers.v1_1.GamesController.GameReturnPackage();
|
||||||
if (isDynamic == true)
|
if (isDynamic == true)
|
||||||
{
|
{
|
||||||
games = GamesController.GetGames("",
|
Controllers.v1_1.GamesController.GameSearchModel searchModel = new Controllers.v1_1.GamesController.GameSearchModel{
|
||||||
platform.Id.ToString(),
|
Name = "",
|
||||||
string.Join(",", collectionItem.Genres),
|
Platform = new List<string>{
|
||||||
string.Join(",", collectionItem.Players),
|
platform.Id.ToString()
|
||||||
string.Join(",", collectionItem.PlayerPerspectives),
|
},
|
||||||
string.Join(",", collectionItem.Themes),
|
Genre = collectionItem.Genres.ConvertAll(s => s.ToString()),
|
||||||
collectionItem.MinimumRating,
|
GameMode = collectionItem.Players.ConvertAll(s => s.ToString()),
|
||||||
collectionItem.MaximumRating
|
PlayerPerspective = collectionItem.PlayerPerspectives.ConvertAll(s => s.ToString()),
|
||||||
);
|
Theme = collectionItem.Themes.ConvertAll(s => s.ToString()),
|
||||||
|
GameRating = new Controllers.v1_1.GamesController.GameSearchModel.GameRatingItem{
|
||||||
|
MinimumRating = collectionItem.MinimumRating,
|
||||||
|
MaximumRating = collectionItem.MaximumRating
|
||||||
|
},
|
||||||
|
GameAgeRating = new Controllers.v1_1.GamesController.GameSearchModel.GameAgeRatingItem{
|
||||||
|
AgeGroupings = UserAgeGroupings,
|
||||||
|
IncludeUnrated = UserAgeGroupIncludeUnrated
|
||||||
|
}
|
||||||
|
};
|
||||||
|
games = Controllers.v1_1.GamesController.GetGames(searchModel, userid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectionContents.CollectionPlatformItem collectionPlatformItem = new CollectionContents.CollectionPlatformItem(platform);
|
CollectionContents.CollectionPlatformItem collectionPlatformItem = new CollectionContents.CollectionPlatformItem(platform);
|
||||||
@@ -274,7 +332,7 @@ namespace gaseous_server.Classes
|
|||||||
) && alwaysIncludeItem.PlatformId == platform.Id
|
) && alwaysIncludeItem.PlatformId == platform.Id
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Game AlwaysIncludeGame = Games.GetGame(alwaysIncludeItem.GameId, false, false, false);
|
MinimalGameItem AlwaysIncludeGame = new MinimalGameItem(Games.GetGame(alwaysIncludeItem.GameId, false, false, false));
|
||||||
CollectionContents.CollectionPlatformItem.CollectionGameItem gameItem = new CollectionContents.CollectionPlatformItem.CollectionGameItem(AlwaysIncludeGame);
|
CollectionContents.CollectionPlatformItem.CollectionGameItem gameItem = new CollectionContents.CollectionPlatformItem.CollectionGameItem(AlwaysIncludeGame);
|
||||||
gameItem.InclusionStatus = new CollectionItem.AlwaysIncludeItem();
|
gameItem.InclusionStatus = new CollectionItem.AlwaysIncludeItem();
|
||||||
gameItem.InclusionStatus.PlatformId = alwaysIncludeItem.PlatformId;
|
gameItem.InclusionStatus.PlatformId = alwaysIncludeItem.PlatformId;
|
||||||
@@ -286,7 +344,7 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Game game in games) {
|
foreach (MinimalGameItem game in games.Games) {
|
||||||
bool gameAlreadyInList = false;
|
bool gameAlreadyInList = false;
|
||||||
foreach (CollectionContents.CollectionPlatformItem.CollectionGameItem existingGame in collectionPlatformItem.Games)
|
foreach (CollectionContents.CollectionPlatformItem.CollectionGameItem existingGame in collectionPlatformItem.Games)
|
||||||
{
|
{
|
||||||
@@ -341,6 +399,17 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle age grouping
|
||||||
|
AgeGroups.AgeRestrictionGroupings CurrentAgeGroup = AgeGroups.GetAgeGroupFromAgeRatings(game.AgeRatings);
|
||||||
|
if (CurrentAgeGroup > AgeGrouping)
|
||||||
|
{
|
||||||
|
AgeGrouping = CurrentAgeGroup;
|
||||||
|
}
|
||||||
|
if (CurrentAgeGroup == AgeGroups.AgeRestrictionGroupings.Unclassified)
|
||||||
|
{
|
||||||
|
ContainsUnclassifiedAgeGroup = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
collectionPlatformItem.Games.Sort((x, y) => x.Name.CompareTo(y.Name));
|
collectionPlatformItem.Games.Sort((x, y) => x.Name.CompareTo(y.Name));
|
||||||
@@ -369,29 +438,39 @@ namespace gaseous_server.Classes
|
|||||||
|
|
||||||
collectionPlatformItems.Sort((x, y) => x.Name.CompareTo(y.Name));
|
collectionPlatformItems.Sort((x, y) => x.Name.CompareTo(y.Name));
|
||||||
|
|
||||||
CollectionContents collectionContents = new CollectionContents();
|
CollectionContents collectionContents = new CollectionContents
|
||||||
collectionContents.Collection = collectionPlatformItems;
|
{
|
||||||
|
Collection = collectionPlatformItems,
|
||||||
|
AgeGroup = AgeGrouping,
|
||||||
|
ContainsUnclassifiedAgeGroup = ContainsUnclassifiedAgeGroup
|
||||||
|
};
|
||||||
|
|
||||||
return collectionContents;
|
return collectionContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CompileCollections(long CollectionId)
|
public static void CompileCollections(long CollectionId, string userid)
|
||||||
{
|
{
|
||||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
|
|
||||||
CollectionItem collectionItem = GetCollection(CollectionId);
|
CollectionItem collectionItem = GetCollection(CollectionId, userid);
|
||||||
if (collectionItem.BuildStatus == CollectionItem.CollectionBuildStatus.WaitingForBuild)
|
if (collectionItem.BuildStatus == CollectionItem.CollectionBuildStatus.WaitingForBuild)
|
||||||
{
|
{
|
||||||
Logging.Log(Logging.LogType.Information, "Collections", "Beginning build of collection: " + collectionItem.Name);
|
Logging.Log(Logging.LogType.Information, "Collections", "Beginning build of collection: " + collectionItem.Name);
|
||||||
|
|
||||||
// set starting
|
CollectionContents collectionContents = GetCollectionContent(collectionItem, userid);
|
||||||
string sql = "UPDATE RomCollections SET BuiltStatus=@bs WHERE Id=@id";
|
|
||||||
Dictionary<string, object> dbDict = new Dictionary<string, object>();
|
|
||||||
dbDict.Add("id", collectionItem.Id);
|
|
||||||
dbDict.Add("bs", CollectionItem.CollectionBuildStatus.Building);
|
|
||||||
db.ExecuteCMD(sql, dbDict);
|
|
||||||
|
|
||||||
List<CollectionContents.CollectionPlatformItem> collectionPlatformItems = GetCollectionContent(collectionItem).Collection;
|
// set starting
|
||||||
|
string sql = "UPDATE RomCollections SET BuiltStatus=@bs, AgeGroup=@ag, AgeGroupUnclassified=@agu WHERE Id=@id";
|
||||||
|
Dictionary<string, object> dbDict = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "id", collectionItem.Id },
|
||||||
|
{ "bs", CollectionItem.CollectionBuildStatus.Building },
|
||||||
|
{ "ag", collectionContents.AgeGroup },
|
||||||
|
{ "agu", collectionContents.ContainsUnclassifiedAgeGroup }
|
||||||
|
};
|
||||||
|
db.ExecuteCMD(sql, dbDict);
|
||||||
|
|
||||||
|
List<CollectionContents.CollectionPlatformItem> collectionPlatformItems = collectionContents.Collection;
|
||||||
string ZipFilePath = Path.Combine(Config.LibraryConfiguration.LibraryCollectionsDirectory, collectionItem.Id + collectionItem.ArchiveExtension);
|
string ZipFilePath = Path.Combine(Config.LibraryConfiguration.LibraryCollectionsDirectory, collectionItem.Id + collectionItem.ArchiveExtension);
|
||||||
string ZipFileTempPath = Path.Combine(Config.LibraryConfiguration.LibraryTempDirectory, collectionItem.Id.ToString());
|
string ZipFileTempPath = Path.Combine(Config.LibraryConfiguration.LibraryTempDirectory, collectionItem.Id.ToString());
|
||||||
|
|
||||||
@@ -758,6 +837,9 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AgeGroups.AgeRestrictionGroupings AgeGroup { get; set; }
|
||||||
|
public bool ContainsUnclassifiedAgeGroup { get; set; }
|
||||||
|
|
||||||
public class CollectionPlatformItem {
|
public class CollectionPlatformItem {
|
||||||
public CollectionPlatformItem(IGDB.Models.Platform platform) {
|
public CollectionPlatformItem(IGDB.Models.Platform platform) {
|
||||||
string[] PropertyWhitelist = new string[] { "Id", "Name", "Slug" };
|
string[] PropertyWhitelist = new string[] { "Id", "Name", "Slug" };
|
||||||
@@ -808,48 +890,43 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CollectionGameItem {
|
public class CollectionGameItem : MinimalGameItem
|
||||||
public CollectionGameItem(IGDB.Models.Game game) {
|
{
|
||||||
string[] PropertyWhitelist = new string[] { "Id", "Name", "Slug", "Cover" };
|
public CollectionGameItem(MinimalGameItem gameObject)
|
||||||
PropertyInfo[] srcProperties = typeof(IGDB.Models.Game).GetProperties();
|
{
|
||||||
PropertyInfo[] dstProperties = typeof(CollectionPlatformItem.CollectionGameItem).GetProperties();
|
this.Id = gameObject.Id;
|
||||||
foreach (PropertyInfo srcProperty in srcProperties) {
|
this.Name = gameObject.Name;
|
||||||
if (PropertyWhitelist.Contains<string>(srcProperty.Name))
|
this.Slug = gameObject.Slug;
|
||||||
|
this.TotalRating = gameObject.TotalRating;
|
||||||
|
this.TotalRatingCount = gameObject.TotalRatingCount;
|
||||||
|
this.Cover = gameObject.Cover;
|
||||||
|
this.Artworks = gameObject.Artworks;
|
||||||
|
this.FirstReleaseDate = gameObject.FirstReleaseDate;
|
||||||
|
this.AgeRatings = gameObject.AgeRatings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IGDB.Models.Cover? CoverItem
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Cover != null)
|
||||||
{
|
{
|
||||||
foreach (PropertyInfo dstProperty in dstProperties)
|
IGDB.Models.Cover cover = Covers.GetCover(Cover.Id, Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory, "Games", Slug), false);
|
||||||
{
|
|
||||||
if (srcProperty.Name == dstProperty.Name)
|
return cover;
|
||||||
{
|
}
|
||||||
if (srcProperty.GetValue(game) != null) {
|
else
|
||||||
string compareName = srcProperty.PropertyType.Name.ToLower().Split("`")[0];
|
{
|
||||||
switch(compareName) {
|
return null;
|
||||||
case "identityorvalue":
|
|
||||||
string newObjectValue = Newtonsoft.Json.JsonConvert.SerializeObject(srcProperty.GetValue(game));
|
|
||||||
Dictionary<string, object> newDict = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(newObjectValue);
|
|
||||||
dstProperty.SetValue(this, newDict["Id"]);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dstProperty.SetValue(this, srcProperty.GetValue(game));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long Id { get; set; }
|
public AgeGroups.AgeRestrictionGroupings AgeGrouping
|
||||||
public string Name { get; set; }
|
{
|
||||||
public string Slug { get; set; }
|
|
||||||
public long Cover { get; set;}
|
|
||||||
public IGDB.Models.Cover CoverItem
|
|
||||||
{
|
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
IGDB.Models.Cover cover = Covers.GetCover(Cover, Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory, "Games", Slug), false);
|
return AgeGroups.GetAgeGroupFromAgeRatings(this.AgeRatings);
|
||||||
|
|
||||||
return cover;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -72,32 +72,7 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
// compile the ratings values into the ratings groups
|
// compile the ratings values into the ratings groups
|
||||||
AgeRestrictionGroupings highestAgeGroup = AgeRestrictionGroupings.Unclassified;
|
AgeRestrictionGroupings highestAgeGroup = GetAgeGroupFromAgeRatings(ageRatings);
|
||||||
foreach (AgeRating ageRating in ageRatings)
|
|
||||||
{
|
|
||||||
foreach (KeyValuePair<AgeRestrictionGroupings, AgeGroupItem> ageGroupItem in AgeGroupingsFlat)
|
|
||||||
{
|
|
||||||
|
|
||||||
PropertyInfo[] groupProps = typeof(AgeGroupItem).GetProperties();
|
|
||||||
foreach (PropertyInfo property in groupProps)
|
|
||||||
{
|
|
||||||
if (RatingsBoards.Contains(property.Name))
|
|
||||||
{
|
|
||||||
List<AgeRatingTitle> ratingBoard = (List<AgeRatingTitle>)property.GetValue(ageGroupItem.Value);
|
|
||||||
foreach (AgeRatingTitle ratingTitle in ratingBoard)
|
|
||||||
{
|
|
||||||
if (ageRating.Rating == ratingTitle)
|
|
||||||
{
|
|
||||||
if (highestAgeGroup < ageGroupItem.Key)
|
|
||||||
{
|
|
||||||
highestAgeGroup = ageGroupItem.Key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the compiled ratings group
|
// return the compiled ratings group
|
||||||
AgeGroup ageGroup = new AgeGroup();
|
AgeGroup ageGroup = new AgeGroup();
|
||||||
@@ -138,6 +113,39 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AgeRestrictionGroupings GetAgeGroupFromAgeRatings(List<AgeRating> ageRatings)
|
||||||
|
{
|
||||||
|
// compile the ratings values into the ratings groups
|
||||||
|
AgeRestrictionGroupings highestAgeGroup = AgeRestrictionGroupings.Unclassified;
|
||||||
|
foreach (AgeRating ageRating in ageRatings)
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<AgeRestrictionGroupings, AgeGroupItem> ageGroupItem in AgeGroupingsFlat)
|
||||||
|
{
|
||||||
|
|
||||||
|
PropertyInfo[] groupProps = typeof(AgeGroupItem).GetProperties();
|
||||||
|
foreach (PropertyInfo property in groupProps)
|
||||||
|
{
|
||||||
|
if (RatingsBoards.Contains(property.Name))
|
||||||
|
{
|
||||||
|
List<AgeRatingTitle> ratingBoard = (List<AgeRatingTitle>)property.GetValue(ageGroupItem.Value);
|
||||||
|
foreach (AgeRatingTitle ratingTitle in ratingBoard)
|
||||||
|
{
|
||||||
|
if (ageRating.Rating == ratingTitle)
|
||||||
|
{
|
||||||
|
if (highestAgeGroup < ageGroupItem.Key)
|
||||||
|
{
|
||||||
|
highestAgeGroup = ageGroupItem.Key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return highestAgeGroup;
|
||||||
|
}
|
||||||
|
|
||||||
public class AgeGroup
|
public class AgeGroup
|
||||||
{
|
{
|
||||||
public long? Id { get; set; }
|
public long? Id { get; set; }
|
||||||
|
@@ -538,6 +538,7 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
{
|
{
|
||||||
this.Id = gameObject.Id;
|
this.Id = gameObject.Id;
|
||||||
this.Name = gameObject.Name;
|
this.Name = gameObject.Name;
|
||||||
|
this.Slug = gameObject.Slug;
|
||||||
this.TotalRating = gameObject.TotalRating;
|
this.TotalRating = gameObject.TotalRating;
|
||||||
this.TotalRatingCount = gameObject.TotalRatingCount;
|
this.TotalRatingCount = gameObject.TotalRatingCount;
|
||||||
this.Cover = gameObject.Cover;
|
this.Cover = gameObject.Cover;
|
||||||
@@ -561,6 +562,7 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
|
|
||||||
public long? Id { get; set; }
|
public long? Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
public string Slug { get; set; }
|
||||||
public double? TotalRating { get; set; }
|
public double? TotalRating { get; set; }
|
||||||
public int? TotalRatingCount { get; set; }
|
public int? TotalRatingCount { get; set; }
|
||||||
public bool HasSavedGame { get; set; } = false;
|
public bool HasSavedGame { get; set; } = false;
|
||||||
|
@@ -3,8 +3,10 @@ using System.Collections.Generic;
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Authentication;
|
||||||
using gaseous_server.Classes;
|
using gaseous_server.Classes;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace gaseous_server.Controllers
|
namespace gaseous_server.Controllers
|
||||||
@@ -16,6 +18,17 @@ namespace gaseous_server.Controllers
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
public class CollectionsController : Controller
|
public class CollectionsController : Controller
|
||||||
{
|
{
|
||||||
|
private readonly UserManager<ApplicationUser> _userManager;
|
||||||
|
private readonly SignInManager<ApplicationUser> _signInManager;
|
||||||
|
|
||||||
|
public CollectionsController(
|
||||||
|
UserManager<ApplicationUser> userManager,
|
||||||
|
SignInManager<ApplicationUser> signInManager)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all ROM collections
|
/// Gets all ROM collections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -24,9 +37,16 @@ namespace gaseous_server.Controllers
|
|||||||
[MapToApiVersion("1.1")]
|
[MapToApiVersion("1.1")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
public List<Classes.Collections.CollectionItem> GetCollections()
|
public async Task<ActionResult> GetCollectionsAsync()
|
||||||
{
|
{
|
||||||
return Classes.Collections.GetCollections();
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
return Ok(Classes.Collections.GetCollections(user.Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -41,18 +61,27 @@ namespace gaseous_server.Controllers
|
|||||||
[Route("{CollectionId}")]
|
[Route("{CollectionId}")]
|
||||||
[ProducesResponseType(typeof(Classes.Collections.CollectionItem), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(Classes.Collections.CollectionItem), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public ActionResult GetCollection(long CollectionId, bool Build = false)
|
public async Task<ActionResult> GetCollection(long CollectionId, bool Build = false)
|
||||||
{
|
{
|
||||||
try
|
var user = await _userManager.GetUserAsync(User);
|
||||||
{
|
|
||||||
if (Build == true)
|
|
||||||
{
|
|
||||||
Classes.Collections.StartCollectionItemBuild(CollectionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Classes.Collections.GetCollection(CollectionId));
|
if (user != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Build == true)
|
||||||
|
{
|
||||||
|
Classes.Collections.StartCollectionItemBuild(CollectionId, user.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(Classes.Collections.GetCollection(CollectionId, user.Id));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
else
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
@@ -69,14 +98,23 @@ namespace gaseous_server.Controllers
|
|||||||
[Route("{CollectionId}/Roms")]
|
[Route("{CollectionId}/Roms")]
|
||||||
[ProducesResponseType(typeof(List<Classes.Collections.CollectionContents.CollectionPlatformItem>), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(List<Classes.Collections.CollectionContents.CollectionPlatformItem>), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public ActionResult GetCollectionRoms(long CollectionId)
|
public async Task<ActionResult> GetCollectionRoms(long CollectionId)
|
||||||
{
|
{
|
||||||
try
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
{
|
{
|
||||||
Classes.Collections.CollectionItem collectionItem = Classes.Collections.GetCollection(CollectionId);
|
try
|
||||||
return Ok(Classes.Collections.GetCollectionContent(collectionItem));
|
{
|
||||||
|
Classes.Collections.CollectionItem collectionItem = Classes.Collections.GetCollection(CollectionId, user.Id);
|
||||||
|
return Ok(Classes.Collections.GetCollectionContent(collectionItem, user.Id));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
else
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
@@ -94,15 +132,24 @@ namespace gaseous_server.Controllers
|
|||||||
[Authorize(Roles = "Admin,Gamer")]
|
[Authorize(Roles = "Admin,Gamer")]
|
||||||
[ProducesResponseType(typeof(List<Classes.Collections.CollectionContents.CollectionPlatformItem>), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(List<Classes.Collections.CollectionContents.CollectionPlatformItem>), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public ActionResult GetCollectionRomsPreview(Classes.Collections.CollectionItem Item)
|
public async Task<ActionResult> GetCollectionRomsPreview(Classes.Collections.CollectionItem Item)
|
||||||
{
|
{
|
||||||
try
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
{
|
{
|
||||||
return Ok(Classes.Collections.GetCollectionContent(Item));
|
try
|
||||||
|
{
|
||||||
|
return Ok(Classes.Collections.GetCollectionContent(Item, user.Id));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return NotFound(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
return NotFound(ex);
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,25 +164,34 @@ namespace gaseous_server.Controllers
|
|||||||
[Route("{CollectionId}/Roms/Zip")]
|
[Route("{CollectionId}/Roms/Zip")]
|
||||||
[ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public ActionResult GetCollectionRomsZip(long CollectionId)
|
public async Task<ActionResult> GetCollectionRomsZip(long CollectionId)
|
||||||
{
|
{
|
||||||
try
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
{
|
{
|
||||||
Classes.Collections.CollectionItem collectionItem = Classes.Collections.GetCollection(CollectionId);
|
try
|
||||||
|
|
||||||
string ZipFilePath = Path.Combine(Config.LibraryConfiguration.LibraryCollectionsDirectory, CollectionId + ".zip");
|
|
||||||
|
|
||||||
if (System.IO.File.Exists(ZipFilePath))
|
|
||||||
{
|
{
|
||||||
var stream = new FileStream(ZipFilePath, FileMode.Open);
|
Classes.Collections.CollectionItem collectionItem = Classes.Collections.GetCollection(CollectionId, user.Id);
|
||||||
return File(stream, "application/zip", collectionItem.Name + ".zip");
|
|
||||||
|
string ZipFilePath = Path.Combine(Config.LibraryConfiguration.LibraryCollectionsDirectory, CollectionId + ".zip");
|
||||||
|
|
||||||
|
if (System.IO.File.Exists(ZipFilePath))
|
||||||
|
{
|
||||||
|
var stream = new FileStream(ZipFilePath, FileMode.Open);
|
||||||
|
return File(stream, "application/zip", collectionItem.Name + ".zip");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
else
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
@@ -152,15 +208,24 @@ namespace gaseous_server.Controllers
|
|||||||
[Authorize(Roles = "Admin,Gamer")]
|
[Authorize(Roles = "Admin,Gamer")]
|
||||||
[ProducesResponseType(typeof(Classes.Collections.CollectionItem), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(Classes.Collections.CollectionItem), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
public ActionResult NewCollection(Classes.Collections.CollectionItem Item)
|
public async Task<ActionResult> NewCollectionAsync(Classes.Collections.CollectionItem Item)
|
||||||
{
|
{
|
||||||
try
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
{
|
{
|
||||||
return Ok(Classes.Collections.NewCollection(Item));
|
try
|
||||||
|
{
|
||||||
|
return Ok(Classes.Collections.NewCollection(Item, user.Id));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
return BadRequest(ex);
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,13 +242,22 @@ namespace gaseous_server.Controllers
|
|||||||
[Authorize(Roles = "Admin,Gamer")]
|
[Authorize(Roles = "Admin,Gamer")]
|
||||||
[ProducesResponseType(typeof(Classes.Collections.CollectionItem), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(Classes.Collections.CollectionItem), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public ActionResult EditCollection(long CollectionId, Classes.Collections.CollectionItem Item)
|
public async Task<ActionResult> EditCollection(long CollectionId, Classes.Collections.CollectionItem Item)
|
||||||
{
|
{
|
||||||
try
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
{
|
{
|
||||||
return Ok(Classes.Collections.EditCollection(CollectionId, Item, true));
|
try
|
||||||
|
{
|
||||||
|
return Ok(Classes.Collections.EditCollection(CollectionId, Item, user.Id, true));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
else
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
@@ -202,27 +276,36 @@ namespace gaseous_server.Controllers
|
|||||||
[Route("{CollectionId}/AlwaysInclude")]
|
[Route("{CollectionId}/AlwaysInclude")]
|
||||||
[ProducesResponseType(typeof(Classes.Collections.CollectionItem), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(Classes.Collections.CollectionItem), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public ActionResult EditCollectionAlwaysInclude(long CollectionId, [FromQuery]bool Rebuild, [FromBody]Collections.CollectionItem.AlwaysIncludeItem Inclusion)
|
public async Task<ActionResult> EditCollectionAlwaysInclude(long CollectionId, [FromQuery]bool Rebuild, [FromBody]Collections.CollectionItem.AlwaysIncludeItem Inclusion)
|
||||||
{
|
{
|
||||||
try
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
{
|
{
|
||||||
Collections.CollectionItem collectionItem = Classes.Collections.GetCollection(CollectionId);
|
try
|
||||||
bool ItemFound = false;
|
|
||||||
foreach (Collections.CollectionItem.AlwaysIncludeItem includeItem in collectionItem.AlwaysInclude)
|
|
||||||
{
|
{
|
||||||
if (includeItem.PlatformId == Inclusion.PlatformId && includeItem.GameId == Inclusion.GameId)
|
Collections.CollectionItem collectionItem = Classes.Collections.GetCollection(CollectionId, user.Id);
|
||||||
|
bool ItemFound = false;
|
||||||
|
foreach (Collections.CollectionItem.AlwaysIncludeItem includeItem in collectionItem.AlwaysInclude)
|
||||||
{
|
{
|
||||||
ItemFound = true;
|
if (includeItem.PlatformId == Inclusion.PlatformId && includeItem.GameId == Inclusion.GameId)
|
||||||
|
{
|
||||||
|
ItemFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ItemFound == false)
|
||||||
|
{
|
||||||
|
collectionItem.AlwaysInclude.Add(Inclusion);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (ItemFound == false)
|
|
||||||
{
|
|
||||||
collectionItem.AlwaysInclude.Add(Inclusion);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Classes.Collections.EditCollection(CollectionId, collectionItem, Rebuild));
|
return Ok(Classes.Collections.EditCollection(CollectionId, collectionItem, user.Id, Rebuild));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
else
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
@@ -239,14 +322,23 @@ namespace gaseous_server.Controllers
|
|||||||
[Route("{CollectionId}")]
|
[Route("{CollectionId}")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public ActionResult DeleteCollection(long CollectionId)
|
public async Task<ActionResult> DeleteCollection(long CollectionId)
|
||||||
{
|
{
|
||||||
try
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
{
|
{
|
||||||
Classes.Collections.DeleteCollection(CollectionId);
|
try
|
||||||
return Ok();
|
{
|
||||||
|
Classes.Collections.DeleteCollection(CollectionId, user.Id);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
else
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
@@ -474,6 +474,7 @@ SELECT DISTINCT
|
|||||||
Game.Id,
|
Game.Id,
|
||||||
Game.`Name`,
|
Game.`Name`,
|
||||||
Game.NameThe,
|
Game.NameThe,
|
||||||
|
Game.Slug,
|
||||||
Game.PlatformId,
|
Game.PlatformId,
|
||||||
Game.TotalRating,
|
Game.TotalRating,
|
||||||
Game.TotalRatingCount,
|
Game.TotalRatingCount,
|
||||||
@@ -543,9 +544,12 @@ FROM
|
|||||||
int pageOffset = pageSize * (pageNumber - 1);
|
int pageOffset = pageSize * (pageNumber - 1);
|
||||||
for (int i = pageOffset; i < dbResponse.Rows.Count; i++)
|
for (int i = pageOffset; i < dbResponse.Rows.Count; i++)
|
||||||
{
|
{
|
||||||
if (i >= (pageOffset + pageSize))
|
if (pageNumber != 0 && pageSize != 0)
|
||||||
{
|
{
|
||||||
break;
|
if (i >= (pageOffset + pageSize))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Game retGame = Storage.BuildCacheObject<Game>(new Game() , dbResponse.Rows[i]);
|
Game retGame = Storage.BuildCacheObject<Game>(new Game() , dbResponse.Rows[i]);
|
||||||
|
@@ -334,7 +334,8 @@ namespace gaseous_server
|
|||||||
|
|
||||||
case QueueItemType.CollectionCompiler:
|
case QueueItemType.CollectionCompiler:
|
||||||
Logging.Log(Logging.LogType.Debug, "Timered Event", "Starting Collection Compiler");
|
Logging.Log(Logging.LogType.Debug, "Timered Event", "Starting Collection Compiler");
|
||||||
Classes.Collections.CompileCollections((long)Options);
|
Dictionary<string, object> collectionOptions = (Dictionary<string, object>)Options;
|
||||||
|
Classes.Collections.CompileCollections((long)collectionOptions["Id"], (string)collectionOptions["UserId"]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QueueItemType.MediaGroupCompiler:
|
case QueueItemType.MediaGroupCompiler:
|
||||||
|
@@ -3,4 +3,4 @@ ADD COLUMN `ValueType` INT NULL DEFAULT 0 AFTER `Setting`,
|
|||||||
ADD COLUMN `ValueDate` DATETIME NULL DEFAULT NULL AFTER `Value`;
|
ADD COLUMN `ValueDate` DATETIME NULL DEFAULT NULL AFTER `Value`;
|
||||||
|
|
||||||
ALTER TABLE `GameState`
|
ALTER TABLE `GameState`
|
||||||
ADD COLUMN `Zipped` BOOLEAN NOT NULL DEFAULT 0;
|
ADD COLUMN `Zipped` BOOLEAN NOT NULL DEFAULT 0;
|
||||||
|
4
gaseous-server/Support/Database/MySQL/gaseous-1017.sql
Normal file
4
gaseous-server/Support/Database/MySQL/gaseous-1017.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
ALTER TABLE `RomCollections`
|
||||||
|
ADD COLUMN `OwnedBy` VARCHAR(45) NULL,
|
||||||
|
ADD COLUMN `AgeGroup` INT NULL,
|
||||||
|
ADD COLUMN `AgeGroupUnclassified` BOOLEAN NULL;
|
@@ -61,6 +61,7 @@
|
|||||||
<None Remove="Support\Database\MySQL\gaseous-1014.sql" />
|
<None Remove="Support\Database\MySQL\gaseous-1014.sql" />
|
||||||
<None Remove="Support\Database\MySQL\gaseous-1015.sql" />
|
<None Remove="Support\Database\MySQL\gaseous-1015.sql" />
|
||||||
<None Remove="Support\Database\MySQL\gaseous-1016.sql" />
|
<None Remove="Support\Database\MySQL\gaseous-1016.sql" />
|
||||||
|
<None Remove="Support\Database\MySQL\gaseous-1017.sql" />
|
||||||
<None Remove="Classes\Metadata\" />
|
<None Remove="Classes\Metadata\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -99,5 +100,6 @@
|
|||||||
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1014.sql" />
|
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1014.sql" />
|
||||||
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1015.sql" />
|
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1015.sql" />
|
||||||
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1016.sql" />
|
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1016.sql" />
|
||||||
|
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1017.sql" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@@ -59,7 +59,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Directory Layout</th>
|
<th>Directory Layout</th>
|
||||||
<td>
|
<td>
|
||||||
<select id="collection_directorylayout" style="width: 100%;" onchange="DisplayDirectoryLabel();">
|
<select id="collection_directorylayout" style="width: 100%;" data-minimum-results-for-search="Infinity" onchange="DisplayDirectoryLabel();">
|
||||||
<option id="collection_directorylayout_gaseous" selected="selected" value="Gaseous">Standard</option>
|
<option id="collection_directorylayout_gaseous" selected="selected" value="Gaseous">Standard</option>
|
||||||
<option id="collection_directorylayout_retropie" value="RetroPie">RetroPie</option>
|
<option id="collection_directorylayout_retropie" value="RetroPie">RetroPie</option>
|
||||||
</select>
|
</select>
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
Include BIOS files (if available)
|
Include BIOS files (if available)
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<select id="collection_includebios" style="width: 100%;">
|
<select id="collection_includebios" style="width: 100%;" data-minimum-results-for-search="Infinity">
|
||||||
<option id="collection_includebios_yes" selected="selected" value="true">Yes</option>
|
<option id="collection_includebios_yes" selected="selected" value="true">Yes</option>
|
||||||
<option id="collection_includebios_no" value="false">No</option>
|
<option id="collection_includebios_no" value="false">No</option>
|
||||||
</select>
|
</select>
|
||||||
@@ -589,11 +589,11 @@
|
|||||||
gameCoverCell.className = 'collections_preview_gamecovercell';
|
gameCoverCell.className = 'collections_preview_gamecovercell';
|
||||||
|
|
||||||
var gameImage = document.createElement('img');
|
var gameImage = document.createElement('img');
|
||||||
gameImage.className = 'game_tile_image game_tile_image_small';
|
gameImage.className = 'game_tile_image game_tile_image_small lazy';
|
||||||
|
gameImage.src = '/images/unknowngame.png';
|
||||||
if (gameItem.cover) {
|
if (gameItem.cover) {
|
||||||
gameImage.src = '/api/v1.1/Games/' + gameItem.id + '/cover/image/cover_small/' + gameItem.coverItem.imageId + '.jpg';
|
gameImage.setAttribute('data-src', '/api/v1.1/Games/' + gameItem.id + '/cover/image/cover_small/' + gameItem.coverItem.imageId + '.jpg');
|
||||||
} else {
|
} else {
|
||||||
gameImage.src = '/images/unknowngame.png';
|
|
||||||
gameImage.className = 'game_tile_image game_tile_image_small unknown';
|
gameImage.className = 'game_tile_image game_tile_image_small unknown';
|
||||||
}
|
}
|
||||||
gameCoverCell.appendChild(gameImage);
|
gameCoverCell.appendChild(gameImage);
|
||||||
@@ -626,6 +626,13 @@
|
|||||||
var collectionSize = document.getElementById('collectionedit_previewbox_size');
|
var collectionSize = document.getElementById('collectionedit_previewbox_size');
|
||||||
collectionSize.innerHTML = "Estimated uncompressed collection size: " + formatBytes(data.collectionProjectedSizeBytes);
|
collectionSize.innerHTML = "Estimated uncompressed collection size: " + formatBytes(data.collectionProjectedSizeBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#collectionedit_previewbox .lazy').Lazy({
|
||||||
|
scrollDirection: 'vertical',
|
||||||
|
effect: 'fadeIn',
|
||||||
|
visibleOnly: true,
|
||||||
|
appendScroll: $('#collectionedit_previewbox')
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function DisplayFormattedBytes(inputElement, labelElement) {
|
function DisplayFormattedBytes(inputElement, labelElement) {
|
||||||
|
Reference in New Issue
Block a user