Skip to content

VersionController

The VersionController class in the ByteCobra Updater Server is responsible for handling various actions related to the versions of games or applications. This includes publishing new versions, deleting existing versions, retrieving all versions, and getting the latest published version. It's part of the server's controller layer and extends the Controller class from ASP.NET MVC.

Constructor

The constructor of VersionController accepts three parameters:

  • Storage storage: An instance of the Storage class, which handles the storage and retrieval of version information.
  • JsonSerializer jsonSerializer: An instance of JsonSerializer for serializing and deserializing JSON data.
  • WebAdminAuthenticator adminAuthenticator: An instance of WebAdminAuthenticator for authenticating admin requests.

Properties

  • protected Storage Storage: Reference to the Storage instance.
  • protected JsonSerializer JsonSerializer: Reference to the JsonSerializer instance.
  • protected WebAdminAuthenticator AdminAuthenticator: Reference to the WebAdminAuthenticator instance.

Methods

Publish

  • [HttpPost("Publish")]: Endpoint for publishing a specific version of a game or application.
  • public async Task Publish(string name, Platform platform, ushort major, ushort minor): Validates the request, authenticates the admin, and sets the specified version as the active version for download.

DeleteVersion

  • [HttpDelete("Delete")]: Endpoint for deleting a specific version.
  • public async Task DeleteVersion(string name, Platform platform, ushort major, ushort minor): Validates the request, authenticates the admin, and deletes the specified version. It also updates the active version if necessary.

GetAllVersions

  • [HttpPost("All")]: Endpoint for retrieving all versions of a specific game or application.
  • public async Task GetAllVersions(string name, Platform platform): Validates the request, authenticates the admin, and returns a list of all versions available.

Latest

  • [HttpGet("Latest")]: Endpoint for getting the latest published version of a game or application.
  • [RateLimit(Limit = 20, Seconds = 60)]: Rate limits requests to this endpoint.
  • [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(Version))]: Indicates a successful response will be of type Version.
  • public async Task Latest(string name, Platform platform): Validates the request and returns the latest published version.

Workflow for Each Method

  1. Authentication: Admin authentication is performed for all endpoints except Latest, which needs to be publicly available so that clients know if they are up to date or not.
  2. Validation: The name parameter is validated for correctness.
  3. Action-Specific Logic: Depending on the endpoint, appropriate actions are taken (e.g., publishing, deleting, retrieving versions).
  4. Response: A suitable HTTP response is returned based on the outcome (e.g., Ok, BadRequest, Unauthorized, NotFound).

Usage Example

VersionController can be used in the ByteCobra Updater Server to manage version-related operations for games or applications. It requires proper setup and integration with Storage, JsonSerializer, and WebAdminAuthenticator.

public class CustomVersionController : VersionController
{
    public CustomVersionController(Storage storage, JsonSerializer jsonSerializer, WebAdminAuthenticator adminAuthenticator)
        : base(storage, jsonSerializer, adminAuthenticator) { }

    // Optional: Override methods to provide custom behavior or additional functionality
}

This example demonstrates how CustomVersionController extends VersionController, utilizing dependency injection to provide necessary services. It allows for further customization or extension of version management functionalities.