Skip to content

Commit

Permalink
Merge pull request #1 from Macro-Deck-App/feature/github-file-provider
Browse files Browse the repository at this point in the history
Replace local data storage with GitHub
  • Loading branch information
manuelmayer-dev authored Jun 5, 2023
2 parents efa3584 + 10c3f24 commit 9218d37
Show file tree
Hide file tree
Showing 53 changed files with 705 additions and 1,211 deletions.
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<PackageVersion Include="AutoMapper.EF6" Version="2.1.1" />
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageVersion Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.1.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="7.0.5" />
<PackageVersion Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
Expand Down
147 changes: 42 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,126 +1,63 @@
# MacroDeck.UpdateService API v2
# Macro Deck Update Service API V2 Version Controller Documentation

This API provides endpoints to check for software updates, fetch version details, and download specific versions for different platforms.
The `ApiV2VersionController` in the Macro Deck Update Service provides methods for managing and interacting with Macro Deck versions. This controller is part of the API V2 and includes methods for checking for updates, retrieving the latest version, getting information about a specific version, and getting the file size of a specific version for a specific platform.

## **Endpoint: Check for Updates**
## Endpoints

`GET /v2/check/{installedVersion}/{platform}`
### GET /v2versions/check/{installedVersion}/{platform}

Checks if there is a newer version available than the installed one.
This endpoint checks for newer versions of Macro Deck based on the currently installed version and the platform.

### Parameters
- **Parameters**:
- `apiVersion`: The API version.
- `installedVersion`: A string representation of the installed version.
- `platform`: A `PlatformIdentifier` enum representing the Macro Deck's platform.
- `previewVersions` (optional, query): A boolean indicating whether to include preview versions in the check.
- **Returns**: An object representing the `ApiV2CheckResult`.

- `installedVersion`: The current installed version of the software.
- `platform`: The platform identifier where the software is running (See PlatformIdentifier enum values).
### GET /v2/versions/latest/{platform}

### Query Parameters
This endpoint returns the latest version of Macro Deck for a specific platform.

- `previewVersions`: Boolean value that indicates if preview versions should be considered. Defaults to `false`.
- **Parameters**:
- `apiVersion`: The API version.
- `platform`: A `PlatformIdentifier` enum representing the Macro Deck's platform.
- `previewVersions` (optional, query): A boolean indicating whether to include preview versions in the response.
- **Returns**: An object representing the `ApiV2VersionInfo`.

### Responses
### GET /v2/versions/{version}

Returns an `ApiV2CheckResult` object with properties:
This endpoint returns information about a specific version of Macro Deck.

- `NewerVersionAvailable`: Boolean indicating if a newer version is available.
- `Version`: String representing the newer version, if available.
- **Parameters**:
- `apiVersion`: The API version.
- `version`: A string representation of the version.
- **Returns**: An object representing the `ApiV2VersionInfo`.

---
### GET /v2/versions/{version}/fileSize/{platform}

## **Endpoint: Get Latest Version**
This endpoint returns the file size of a specific version of Macro Deck for a specific platform.

`GET /v2/latest/{platform}`
- **Parameters**:
- `apiVersion`: The API version.
- `version`: A string representation of the version.
- `platform`: A `PlatformIdentifier` enum representing the Macro Deck's platform.
- **Returns**: The file size as a double.

Fetches the latest software version details for the specified platform.
## Data Types

### Parameters
### `ApiV2VersionInfo`

- `platform`: The platform identifier (See PlatformIdentifier enum values).
The `ApiV2VersionInfo` class provides information about a Macro Deck version. This includes the version number and a dictionary of platform identifiers each mapped to their respective download link.

### Query Parameters
- **Properties**:
- `Version`: A string representation of the Macro Deck version.
- `Platforms`: A dictionary mapping `PlatformIdentifier` enum values to their respective download links for the specified version.

- `previewVersions`: Boolean value that indicates if preview versions should be considered. Defaults to `false`.
### `ApiV2CheckResult`

### Responses
The `ApiV2CheckResult` class provides the result of a version check for Macro Deck. It includes a boolean indicating if a newer version is available and an `ApiV2VersionInfo` object providing details about the available version, if applicable.

Returns an `ApiV2VersionInfo` object with properties:

- `Version`: String representing the version number.
- `VersionState`: State of the version.
- `Downloads`: Long representing the download count.
- `SupportedPlatforms`: Array of supported platforms.

---

## **Endpoint: Get Version**

`GET /v2/{version}`

Fetches the specific software version details.

### Parameters

- `version`: The version of the software to retrieve details for.

### Responses

Returns an `ApiV2VersionInfo` object similar to the Get Latest Version endpoint.

---

## **Endpoint: Download Latest Version**

`GET /v2/latest/download/{platform}`

Downloads the latest version for the specified platform.

### Parameters

- `platform`: The platform identifier for the download.

### Query Parameters

- `downloadReason`: Indicates the reason for download (See DownloadReason enum values). Defaults to `FirstDownload`.
- `previewVersions`: Boolean value that indicates if preview versions should be considered. Defaults to `false`.

### Responses

Returns a byte array representing the file contents of the version. A header "x-file-hash" with the file's hash is also set in the response.

---

## **Endpoint: Download Version**

`GET /v2/{version}/download/{platform}`

Downloads the specific version for the specified platform.

### Parameters

- `version`: The version of the software to download.
- `platform`: The platform identifier for the download.

### Query Parameters

- `downloadReason`: Indicates the reason for download (See DownloadReason enum values). Defaults to `FirstDownload`.

### Responses

Returns a byte array representing the file contents of the version. A header "x-file-hash" with the file's hash is also set in the response.

---

## Enums

### **PlatformIdentifier**

- `WinX64`: Windows 64-bit
- `MacX64`: Mac OS 64-bit
- `MacArm64`: Mac OS Arm 64-bit
- `LinuxX64`: Linux 64-bit
- `LinuxArm64`: Linux Arm 64-bit
- `LinuxArm32`: Linux Arm 32-bit

### **DownloadReason**

- `FirstDownload`: The version is being downloaded for the first time.
- `UpdateDownload`: The version is being downloaded as an update to a previous version.
- **Properties**:
- `NewerVersionAvailable`: A boolean indicating whether a newer version of Macro Deck is available.
- `Version`: An instance of `ApiV2VersionInfo` providing information about the newer version if one is available; null otherwise.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ public static partial class UpdateServiceConfiguration
public static string DatabaseConnectionString => GetString("database:connection_string");
public static string? DatabaseConnectionStringOverride { get; set; }
public static string AdminAuthenticationToken => GetString("authentication:admin_token");
public static string DataPath => GetString("paths:data_path");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace MacroDeck.UpdateService.Core.Constants;

public static class FileProviderBaseUrls
{
public const string GitHubFileBaseUrl = "https://github.com/macro-deck-app/macro-deck/releases/download";
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public override void Configure(EntityTypeBuilder<VersionEntity> builder)
builder.HasIndex(x => x.Version)
.IsUnique();

builder.HasIndex(x => x.VersionState);

builder.Property(x => x.Version)
.HasColumnName("version_string")
.IsRequired();
Expand All @@ -37,17 +35,13 @@ public override void Configure(EntityTypeBuilder<VersionEntity> builder)
.HasColumnName("version_patch")
.IsRequired();

builder.Property(x => x.PreviewNo)
.HasColumnName("version_preview_no");
builder.Property(x => x.PreReleaseNo)
.HasColumnName("version_pre_release_no");

builder.Property(x => x.IsPreviewVersion)
.HasColumnName("is_preview_version")
builder.Property(x => x.IsBetaVersion)
.HasColumnName("is_pre_release_version")
.HasDefaultValue(false);

builder.Property(x => x.VersionState)
.HasColumnName("version_state")
.IsRequired();

builder.HasMany(x => x.Files)
.WithOne(x => x.Version)
.HasForeignKey(x => x.VersionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public override void Configure(EntityTypeBuilder<VersionFileEntity> builder)
.HasColumnName("platform_identifier")
.IsRequired();

builder.Property(x => x.OriginalFileName)
.HasColumnName("file_name")
builder.Property(x => x.FileProvider)
.HasColumnName("file_provider")
.IsRequired();

builder.Property(x => x.SavedFileName)
.HasColumnName("saved_name")
builder.Property(x => x.FileName)
.HasColumnName("file_name")
.IsRequired();

builder.Property(x => x.FileHash)
Expand All @@ -41,10 +41,5 @@ public override void Configure(EntityTypeBuilder<VersionFileEntity> builder)
builder.Property(x => x.VersionId)
.HasColumnName("version_ref")
.IsRequired();

builder.HasMany(x => x.FileDownloads)
.WithOne(x => x.VersionFile)
.HasForeignKey(x => x.VersionFileId)
.OnDelete(DeleteBehavior.Cascade);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using MacroDeck.UpdateService.Core.Enums;

namespace MacroDeck.UpdateService.Core.DataAccess.Entities;

public class VersionEntity : BaseEntity
Expand All @@ -8,8 +6,7 @@ public class VersionEntity : BaseEntity
public int Major { get; set; }
public int Minor { get; set; }
public int Patch { get; set; }
public int? PreviewNo { get; set; }
public bool IsPreviewVersion { get; set; }
public VersionState VersionState { get; set; }
public int? PreReleaseNo { get; set; }
public bool IsBetaVersion { get; set; }
public ICollection<VersionFileEntity> Files { get; set; } = new List<VersionFileEntity>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ namespace MacroDeck.UpdateService.Core.DataAccess.Entities;

public class VersionFileEntity : BaseEntity
{
public FileProvider FileProvider { get; set; }
public PlatformIdentifier PlatformIdentifier { get; set; }
public string SavedFileName { get; set; } = string.Empty;
public string OriginalFileName { get; set; } = string.Empty;
public string FileName { get; set; } = string.Empty;
public string FileHash { get; set; } = string.Empty;
public long FileSize { get; set; }
public ICollection<FileDownloadEntity> FileDownloads { get; set; } = new List<FileDownloadEntity>();


public int VersionId { get; set; }
public VersionEntity? Version { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public ValueTask<InterceptionResult<int>> SavingChangesAsync(
versionEntity.Major = versionStruct.Major;
versionEntity.Minor = versionStruct.Minor;
versionEntity.Patch = versionStruct.Patch;
versionEntity.PreviewNo = versionStruct.PreviewNo;
versionEntity.IsPreviewVersion = versionStruct.IsPreviewVersion;
versionEntity.PreReleaseNo = versionStruct.BetaNo;
versionEntity.IsBetaVersion = versionStruct.IsBetaVersion;
}
}

Expand Down

This file was deleted.

Loading

0 comments on commit 9218d37

Please sign in to comment.