Deprecate API v1 - API v1.1 is now default (#469)

This commit is contained in:
Michael Green
2024-12-19 14:37:21 +11:00
committed by GitHub
parent 98a09c32f8
commit 9922e61b44
17 changed files with 59 additions and 49 deletions

View File

@@ -15,7 +15,7 @@ namespace gaseous_server.Controllers
{ {
[ApiController] [ApiController]
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize] [Authorize]
public class AccountController : Controller public class AccountController : Controller

View File

@@ -10,7 +10,7 @@ namespace gaseous_server.Controllers
{ {
[ApiController] [ApiController]
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize(Roles = "Admin,Gamer,Player")] [Authorize(Roles = "Admin,Gamer,Player")]
public class BackgroundTasksController : Controller public class BackgroundTasksController : Controller

View File

@@ -12,7 +12,7 @@ namespace gaseous_server.Controllers
{ {
[ApiController] [ApiController]
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize] [Authorize]
public class BiosController : Controller public class BiosController : Controller

View File

@@ -14,7 +14,7 @@ namespace gaseous_server.Controllers
{ {
[ApiController] [ApiController]
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize] [Authorize]
public class CollectionsController : Controller public class CollectionsController : Controller
@@ -29,7 +29,7 @@ namespace gaseous_server.Controllers
_userManager = userManager; _userManager = userManager;
_signInManager = signInManager; _signInManager = signInManager;
} }
/// <summary> /// <summary>
/// Gets all ROM collections /// Gets all ROM collections
/// </summary> /// </summary>
@@ -145,7 +145,7 @@ namespace gaseous_server.Controllers
} }
catch (Exception ex) catch (Exception ex)
{ {
return NotFound(ex); return NotFound(ex);
} }
} }
else else
@@ -212,7 +212,7 @@ namespace gaseous_server.Controllers
public async Task<ActionResult> NewCollectionAsync(Classes.Collections.CollectionItem Item) public async Task<ActionResult> NewCollectionAsync(Classes.Collections.CollectionItem Item)
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
if (user != null) if (user != null)
{ {
try try
@@ -246,7 +246,7 @@ namespace gaseous_server.Controllers
public async Task<ActionResult> EditCollection(long CollectionId, Classes.Collections.CollectionItem Item) public async Task<ActionResult> EditCollection(long CollectionId, Classes.Collections.CollectionItem Item)
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
if (user != null) if (user != null)
{ {
try try
@@ -277,10 +277,10 @@ 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 async Task<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)
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
if (user != null) if (user != null)
{ {
try try
@@ -326,7 +326,7 @@ namespace gaseous_server.Controllers
public async Task<ActionResult> DeleteCollection(long CollectionId) public async Task<ActionResult> DeleteCollection(long CollectionId)
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
if (user != null) if (user != null)
{ {
try try

View File

@@ -15,7 +15,7 @@ using Asp.Versioning;
namespace gaseous_server.Controllers namespace gaseous_server.Controllers
{ {
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize] [Authorize]
[ApiController] [ApiController]
@@ -23,7 +23,7 @@ namespace gaseous_server.Controllers
{ {
private readonly UserManager<ApplicationUser> _userManager; private readonly UserManager<ApplicationUser> _userManager;
private readonly SignInManager<ApplicationUser> _signInManager; private readonly SignInManager<ApplicationUser> _signInManager;
public FilterController( public FilterController(
UserManager<ApplicationUser> userManager, UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager) SignInManager<ApplicationUser> signInManager)
@@ -40,7 +40,7 @@ namespace gaseous_server.Controllers
public async Task<IActionResult> FilterAsync() public async Task<IActionResult> FilterAsync()
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
return Ok(Filters.Filter(user.SecurityProfile.AgeRestrictionPolicy.MaximumAgeRestriction, user.SecurityProfile.AgeRestrictionPolicy.IncludeUnrated)); return Ok(Filters.Filter(user.SecurityProfile.AgeRestrictionPolicy.MaximumAgeRestriction, user.SecurityProfile.AgeRestrictionPolicy.IncludeUnrated));
} }
} }

View File

@@ -22,7 +22,7 @@ using Asp.Versioning;
namespace gaseous_server.Controllers namespace gaseous_server.Controllers
{ {
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize] [Authorize]
[ApiController] [ApiController]
@@ -30,7 +30,7 @@ namespace gaseous_server.Controllers
{ {
private readonly UserManager<ApplicationUser> _userManager; private readonly UserManager<ApplicationUser> _userManager;
private readonly SignInManager<ApplicationUser> _signInManager; private readonly SignInManager<ApplicationUser> _signInManager;
public GamesController( public GamesController(
UserManager<ApplicationUser> userManager, UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager SignInManager<ApplicationUser> signInManager
@@ -53,7 +53,7 @@ namespace gaseous_server.Controllers
int minrating = -1, int minrating = -1,
int maxrating = -1, int maxrating = -1,
bool sortdescending = false) bool sortdescending = false)
{ {
return Ok(GetGames(name, platform, genre, gamemode, playerperspective, theme, minrating, maxrating, "Adult", true, true, sortdescending)); return Ok(GetGames(name, platform, genre, gamemode, playerperspective, theme, minrating, maxrating, "Adult", true, true, sortdescending));
} }
@@ -473,14 +473,15 @@ namespace gaseous_server.Controllers
try try
{ {
IGDB.Models.Artwork artworkObject = Artworks.GetArtwork(ArtworkId, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), true); IGDB.Models.Artwork artworkObject = Artworks.GetArtwork(ArtworkId, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), true);
if (artworkObject != null) { if (artworkObject != null)
{
//string coverFilePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Artwork", size.ToString(), artworkObject.ImageId + ".jpg"); //string coverFilePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Artwork", size.ToString(), artworkObject.ImageId + ".jpg");
string basePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Artwork"); string basePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Artwork");
Communications comms = new Communications(); Communications comms = new Communications();
Task<string> ImgFetch = comms.GetSpecificImageFromServer(basePath, artworkObject.ImageId, size, new List<Communications.IGDBAPI_ImageSize>{ Communications.IGDBAPI_ImageSize.original }); Task<string> ImgFetch = comms.GetSpecificImageFromServer(basePath, artworkObject.ImageId, size, new List<Communications.IGDBAPI_ImageSize> { Communications.IGDBAPI_ImageSize.original });
string coverFilePath = ImgFetch.Result; string coverFilePath = ImgFetch.Result;
@@ -578,13 +579,14 @@ namespace gaseous_server.Controllers
{ {
IGDB.Models.Cover cover = Classes.Metadata.Covers.GetCover(gameObject.Cover.Id, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), false); IGDB.Models.Cover cover = Classes.Metadata.Covers.GetCover(gameObject.Cover.Id, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), false);
string basePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Covers"); string basePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Covers");
Communications comms = new Communications(); Communications comms = new Communications();
Task<string> ImgFetch = comms.GetSpecificImageFromServer(basePath, cover.ImageId, size, new List<Communications.IGDBAPI_ImageSize>{ Communications.IGDBAPI_ImageSize.cover_big, Communications.IGDBAPI_ImageSize.original }); Task<string> ImgFetch = comms.GetSpecificImageFromServer(basePath, cover.ImageId, size, new List<Communications.IGDBAPI_ImageSize> { Communications.IGDBAPI_ImageSize.cover_big, Communications.IGDBAPI_ImageSize.original });
string coverFilePath = ImgFetch.Result; string coverFilePath = ImgFetch.Result;
if (System.IO.File.Exists(coverFilePath)) { if (System.IO.File.Exists(coverFilePath))
{
string filename = cover.ImageId + ".jpg"; string filename = cover.ImageId + ".jpg";
string filepath = coverFilePath; string filepath = coverFilePath;
byte[] filedata = System.IO.File.ReadAllBytes(filepath); byte[] filedata = System.IO.File.ReadAllBytes(filepath);
@@ -627,7 +629,7 @@ namespace gaseous_server.Controllers
if (gameObject != null) if (gameObject != null)
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
if (user != null) if (user != null)
{ {
Favourites favourites = new Favourites(); Favourites favourites = new Favourites();
@@ -664,7 +666,7 @@ namespace gaseous_server.Controllers
if (gameObject != null) if (gameObject != null)
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
if (user != null) if (user != null)
{ {
Favourites favourites = new Favourites(); Favourites favourites = new Favourites();
@@ -796,7 +798,8 @@ namespace gaseous_server.Controllers
companyData.Add("company", company); companyData.Add("company", company);
return Ok(companyData); return Ok(companyData);
} else }
else
{ {
return NotFound(); return NotFound();
} }
@@ -895,7 +898,7 @@ namespace gaseous_server.Controllers
foreach (long icId in gameObject.ReleaseDates.Ids) foreach (long icId in gameObject.ReleaseDates.Ids)
{ {
ReleaseDate releaseDate = Classes.Metadata.ReleaseDates.GetReleaseDates(icId); ReleaseDate releaseDate = Classes.Metadata.ReleaseDates.GetReleaseDates(icId);
rdObjects.Add(releaseDate); rdObjects.Add(releaseDate);
} }
} }
@@ -923,7 +926,7 @@ namespace gaseous_server.Controllers
public async Task<ActionResult> GameRomAsync(long GameId, int pageNumber = 0, int pageSize = 0, long PlatformId = -1, string NameSearch = "") public async Task<ActionResult> GameRomAsync(long GameId, int pageNumber = 0, int pageSize = 0, long PlatformId = -1, string NameSearch = "")
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
try try
{ {
Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false);
@@ -1113,7 +1116,7 @@ namespace gaseous_server.Controllers
public async Task<ActionResult> GameRomGroupAsync(long GameId, long RomGroupId) public async Task<ActionResult> GameRomGroupAsync(long GameId, long RomGroupId)
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
try try
{ {
Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false);
@@ -1144,7 +1147,7 @@ namespace gaseous_server.Controllers
public async Task<ActionResult> GetGameRomGroupAsync(long GameId) public async Task<ActionResult> GetGameRomGroupAsync(long GameId)
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
try try
{ {
Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false);
@@ -1204,7 +1207,7 @@ namespace gaseous_server.Controllers
public async Task<ActionResult> GameRomGroupMembersAsync(long GameId, long RomGroupId, [FromBody] List<long> RomIds) public async Task<ActionResult> GameRomGroupMembersAsync(long GameId, long RomGroupId, [FromBody] List<long> RomIds)
{ {
var user = await _userManager.GetUserAsync(User); var user = await _userManager.GetUserAsync(User);
try try
{ {
Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false);
@@ -1386,9 +1389,10 @@ namespace gaseous_server.Controllers
public async Task<ActionResult> GameScreenshot(long GameId, long ScreenshotId) public async Task<ActionResult> GameScreenshot(long GameId, long ScreenshotId)
{ {
try try
{ {
IGDB.Models.Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); IGDB.Models.Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false);
if (gameObject != null) { if (gameObject != null)
{
IGDB.Models.Screenshot screenshotObject = Screenshots.GetScreenshot(ScreenshotId, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), false); IGDB.Models.Screenshot screenshotObject = Screenshots.GetScreenshot(ScreenshotId, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), false);
if (screenshotObject != null) if (screenshotObject != null)
{ {
@@ -1428,7 +1432,7 @@ namespace gaseous_server.Controllers
string basePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Screenshots"); string basePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Screenshots");
Communications comms = new Communications(); Communications comms = new Communications();
Task<string> ImgFetch = comms.GetSpecificImageFromServer(basePath, screenshotObject.ImageId, Size, new List<Communications.IGDBAPI_ImageSize>{ Communications.IGDBAPI_ImageSize.original }); Task<string> ImgFetch = comms.GetSpecificImageFromServer(basePath, screenshotObject.ImageId, Size, new List<Communications.IGDBAPI_ImageSize> { Communications.IGDBAPI_ImageSize.original });
string coverFilePath = ImgFetch.Result; string coverFilePath = ImgFetch.Result;

View File

@@ -11,7 +11,7 @@ namespace gaseous_server.Controllers
{ {
[ApiController] [ApiController]
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize(Roles = "Admin")] [Authorize(Roles = "Admin")]
public class LibraryController : Controller public class LibraryController : Controller

View File

@@ -11,7 +11,7 @@ namespace gaseous_server.Controllers
{ {
[ApiController] [ApiController]
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize(Roles = "Admin")] [Authorize(Roles = "Admin")]
public class LogsController : Controller public class LogsController : Controller

View File

@@ -19,7 +19,7 @@ using Asp.Versioning;
namespace gaseous_server.Controllers namespace gaseous_server.Controllers
{ {
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[ApiController] [ApiController]
[Authorize] [Authorize]

View File

@@ -18,7 +18,7 @@ using Asp.Versioning;
namespace gaseous_server.Controllers namespace gaseous_server.Controllers
{ {
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize] [Authorize]
[ApiController] [ApiController]

View File

@@ -19,7 +19,7 @@ using Asp.Versioning;
namespace gaseous_server.Controllers namespace gaseous_server.Controllers
{ {
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize] [Authorize]
[ApiController] [ApiController]

View File

@@ -18,7 +18,7 @@ namespace gaseous_server.Controllers
{ {
[ApiController] [ApiController]
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize] [Authorize]
public class SearchController : Controller public class SearchController : Controller

View File

@@ -17,7 +17,7 @@ namespace gaseous_server.Controllers
{ {
[ApiController] [ApiController]
[Route("api/v{version:apiVersion}/[controller]/[action]")] [Route("api/v{version:apiVersion}/[controller]/[action]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize] [Authorize]
public class SignaturesController : Controller public class SignaturesController : Controller

View File

@@ -19,7 +19,7 @@ namespace gaseous_server.Controllers
{ {
[ApiController] [ApiController]
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[Authorize] [Authorize]
public class SystemController : Controller public class SystemController : Controller

View File

@@ -11,7 +11,7 @@ using System.IO.Compression;
namespace gaseous_server.Controllers.v1_1 namespace gaseous_server.Controllers.v1_1
{ {
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[ApiController] [ApiController]
public class StateManagerController : ControllerBase public class StateManagerController : ControllerBase

View File

@@ -9,10 +9,10 @@ using Asp.Versioning;
namespace gaseous_server.Controllers.v1_1 namespace gaseous_server.Controllers.v1_1
{ {
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")] [ApiVersion("1.0", Deprecated = true)]
[ApiVersion("1.1")] [ApiVersion("1.1")]
[ApiController] [ApiController]
public class StatisticsController: ControllerBase public class StatisticsController : ControllerBase
{ {
private readonly UserManager<ApplicationUser> _userManager; private readonly UserManager<ApplicationUser> _userManager;
private readonly SignInManager<ApplicationUser> _signInManager; private readonly SignInManager<ApplicationUser> _signInManager;

View File

@@ -136,7 +136,7 @@ builder.Services.AddControllers(options =>
}); });
builder.Services.AddApiVersioning(config => builder.Services.AddApiVersioning(config =>
{ {
config.DefaultApiVersion = new ApiVersion(1, 0); config.DefaultApiVersion = new ApiVersion(1, 1);
config.AssumeDefaultVersionWhenUnspecified = true; config.AssumeDefaultVersionWhenUnspecified = true;
config.ReportApiVersions = true; config.ReportApiVersions = true;
config.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(), config.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(),
@@ -207,6 +207,9 @@ builder.Services.AddSwaggerGen(options =>
// using System.Reflection; // using System.Reflection;
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
// sort the endpoints
options.OrderActionsBy((apiDesc) => $"{apiDesc.RelativePath}_{apiDesc.HttpMethod}");
} }
); );
builder.Services.AddHostedService<TimedHostedService>(); builder.Services.AddHostedService<TimedHostedService>();
@@ -271,9 +274,12 @@ app.UseSwaggerUI(options =>
var descriptions = app.DescribeApiVersions(); var descriptions = app.DescribeApiVersions();
foreach (var description in descriptions) foreach (var description in descriptions)
{ {
var url = $"/swagger/{description.GroupName}/swagger.json"; if (description.IsDeprecated == false)
var name = description.GroupName.ToUpperInvariant(); {
options.SwaggerEndpoint(url, name); var url = $"/swagger/{description.GroupName}/swagger.json";
var name = description.GroupName.ToUpperInvariant();
options.SwaggerEndpoint(url, name);
}
} }
} }
); );